App now uses updated engines
This commit is contained in:
@@ -8,6 +8,9 @@ import com.r11.tools.controller.XPathController;
|
||||
import com.r11.tools.controller.XsdController;
|
||||
import com.r11.tools.controller.XsltController;
|
||||
import com.r11.tools.controller.internal.RestControllerRegistry;
|
||||
import com.r11.tools.xml.Saxon;
|
||||
import com.r11.tools.xml.Xalan;
|
||||
import com.r11.tools.xml.XmlEngine;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import spark.Spark;
|
||||
@@ -35,12 +38,15 @@ public class SparkApplication {
|
||||
Gson jsongson = new GsonBuilder()
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
XmlEngine saxon = new Saxon();
|
||||
XmlEngine xalan = new Xalan();
|
||||
|
||||
|
||||
RestControllerRegistry registry = new RestControllerRegistry();
|
||||
registry.registerController(new ProcessorInfoController(logger));
|
||||
registry.registerController(new XsdController(gson, logger));
|
||||
registry.registerController(new XPathController(gson, logger));
|
||||
registry.registerController(new XsltController(gson, logger));
|
||||
registry.registerController(new ProcessorInfoController(logger, saxon, xalan));
|
||||
registry.registerController(new XsdController(gson, logger, saxon, xalan));
|
||||
registry.registerController(new XPathController(gson, logger, saxon, xalan));
|
||||
registry.registerController(new XsltController(gson, logger, saxon, xalan));
|
||||
registry.registerController(new JsonController(gson, jsongson, logger));
|
||||
|
||||
registry.register();
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.r11.tools.controller.internal.HandlerType;
|
||||
import com.r11.tools.controller.internal.RestController;
|
||||
import com.r11.tools.controller.internal.ScopedControllerManifest;
|
||||
import com.r11.tools.xml.Saxon;
|
||||
import com.r11.tools.xml.XmlEngine;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
@@ -13,9 +14,13 @@ import spark.Response;
|
||||
public class ProcessorInfoController implements RestController {
|
||||
|
||||
private final Logger logger;
|
||||
private final XmlEngine saxon;
|
||||
private final XmlEngine xalan;
|
||||
|
||||
public ProcessorInfoController(Logger logger) {
|
||||
public ProcessorInfoController(Logger logger, XmlEngine saxon, XmlEngine xalan) {
|
||||
this.logger = logger;
|
||||
this.saxon = saxon;
|
||||
this.xalan = xalan;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,8 +29,8 @@ public class ProcessorInfoController implements RestController {
|
||||
@ScopedControllerManifest(method = HandlerType.GET, path = "/procinfo")
|
||||
public void processorInfo(Request request, Response response) {
|
||||
try {
|
||||
response.header("processor", "Saxon " + Saxon.getVersion() + " over s9api");
|
||||
response.body(Saxon.getVersion());
|
||||
response.header("processor", "Saxon " + saxon.getVersion() + " over s9api");
|
||||
response.body(saxon.getVersion());
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on retrieving engine version. " + ex);
|
||||
response.body(ex.getMessage());
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
|
||||
import com.r11.tools.controller.internal.*;
|
||||
import com.r11.tools.xml.Saxon;
|
||||
import com.r11.tools.xml.Xalan;
|
||||
import com.r11.tools.xml.XmlEngine;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
@@ -15,9 +16,14 @@ public class XPathController implements RestController {
|
||||
private final Gson gson;
|
||||
private final Logger logger;
|
||||
|
||||
public XPathController(Gson gson, Logger logger) {
|
||||
private final XmlEngine saxon;
|
||||
private final XmlEngine xalan;
|
||||
|
||||
public XPathController(Gson gson, Logger logger, XmlEngine saxon, XmlEngine xalan) {
|
||||
this.gson = gson;
|
||||
this.logger = logger;
|
||||
this.saxon = saxon;
|
||||
this.xalan = xalan;
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xpath")
|
||||
@@ -56,11 +62,11 @@ public class XPathController implements RestController {
|
||||
JsonObject responseJson = new JsonObject();
|
||||
switch (processor) {
|
||||
case "saxon":
|
||||
response.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||
response.header("processor", "Saxon " + saxon.getVersion() + " " + version + " over s9api");
|
||||
timeStart = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
tmp = Saxon.processXPath(data, query, version).getData().trim();
|
||||
tmp = saxon.processXPath(data, query, version).getData().trim();
|
||||
|
||||
response.status(200);
|
||||
|
||||
@@ -78,18 +84,18 @@ public class XPathController implements RestController {
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request (XPath, Saxon) processed in " + duration + " ms.");
|
||||
|
||||
responseJson.addProperty("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + version + " over s9api");
|
||||
responseJson.addProperty("time", duration);
|
||||
|
||||
response.body(this.gson.toJson(responseJson));
|
||||
return;
|
||||
|
||||
case "xalan":
|
||||
response.header("processor", Xalan.getVersion());
|
||||
response.header("processor", xalan.getVersion());
|
||||
timeStart = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
XPathQueryResult xPathQueryResult = Xalan.processXPath(data, query);
|
||||
XPathQueryResult xPathQueryResult = xalan.processXPath(data, query, "");
|
||||
|
||||
response.status(200);
|
||||
|
||||
@@ -108,7 +114,7 @@ public class XPathController implements RestController {
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request (XPath, Xalan) processed in " + duration + " ms.");
|
||||
|
||||
responseJson.addProperty("processor", Xalan.getVersion());
|
||||
responseJson.addProperty("processor", xalan.getVersion());
|
||||
responseJson.addProperty("time", duration);
|
||||
|
||||
response.body(this.gson.toJson(responseJson));
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.r11.tools.controller.internal.HandlerType;
|
||||
import com.r11.tools.controller.internal.RestController;
|
||||
import com.r11.tools.controller.internal.ScopedControllerManifest;
|
||||
import com.r11.tools.xml.Xalan;
|
||||
import com.r11.tools.xml.XmlEngine;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
@@ -17,9 +18,14 @@ public class XsdController implements RestController {
|
||||
private final Gson gson;
|
||||
private final Logger logger;
|
||||
|
||||
public XsdController(Gson gson, Logger logger) {
|
||||
private final XmlEngine saxon;
|
||||
private final XmlEngine xalan;
|
||||
|
||||
public XsdController(Gson gson, Logger logger, XmlEngine saxon, XmlEngine xalan) {
|
||||
this.gson = gson;
|
||||
this.logger = logger;
|
||||
this.saxon = saxon;
|
||||
this.xalan = xalan;
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xsd")
|
||||
@@ -44,14 +50,14 @@ public class XsdController implements RestController {
|
||||
String data = requestJson.get("data").getAsString();
|
||||
String xsd = requestJson.get("process").getAsString();
|
||||
|
||||
response.header("processor", Xalan.getVersion());
|
||||
response.header("processor", xalan.getVersion());
|
||||
|
||||
long timeStart = System.currentTimeMillis();
|
||||
String tmp;
|
||||
|
||||
JsonObject responseJson = new JsonObject();
|
||||
try {
|
||||
tmp = Xalan.validate(data, xsd).trim();
|
||||
tmp = xalan.validate(data, xsd).trim();
|
||||
|
||||
response.status(200);
|
||||
|
||||
@@ -69,7 +75,7 @@ public class XsdController implements RestController {
|
||||
long duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request (XSD, Xalan) processed in " + duration + " ms.");
|
||||
|
||||
responseJson.addProperty("processor", Xalan.getVersion());
|
||||
responseJson.addProperty("processor", xalan.getVersion());
|
||||
responseJson.addProperty("time", duration);
|
||||
|
||||
response.body(this.gson.toJson(responseJson));
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.r11.tools.controller.internal.RestController;
|
||||
import com.r11.tools.controller.internal.ScopedControllerManifest;
|
||||
import com.r11.tools.xml.Saxon;
|
||||
import com.r11.tools.xml.Xalan;
|
||||
import com.r11.tools.xml.XmlEngine;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
@@ -18,9 +19,14 @@ public class XsltController implements RestController {
|
||||
private final Gson gson;
|
||||
private final Logger logger;
|
||||
|
||||
public XsltController(Gson gson, Logger logger) {
|
||||
private final XmlEngine saxon;
|
||||
private final XmlEngine xalan;
|
||||
|
||||
public XsltController(Gson gson, Logger logger, XmlEngine saxon, XmlEngine xalan) {
|
||||
this.gson = gson;
|
||||
this.logger = logger;
|
||||
this.saxon = saxon;
|
||||
this.xalan = xalan;
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xslt")
|
||||
@@ -61,7 +67,7 @@ public class XsltController implements RestController {
|
||||
case "saxon":
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Saxon.processXSLT(data, query);
|
||||
tmp = saxon.processXSLT(data, query);
|
||||
|
||||
response.status(200);
|
||||
|
||||
@@ -79,7 +85,7 @@ public class XsltController implements RestController {
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request (XSLT, Saxon) processed in " + duration + " ms.");
|
||||
|
||||
responseJson.addProperty("processor", "Saxon " + Saxon.getVersion() + " " + version);
|
||||
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + version);
|
||||
responseJson.addProperty("time", duration);
|
||||
|
||||
response.body(this.gson.toJson(responseJson));
|
||||
@@ -88,7 +94,7 @@ public class XsltController implements RestController {
|
||||
case "xalan":
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Xalan.processXSLT(data, query);
|
||||
tmp = xalan.processXSLT(data, query);
|
||||
|
||||
response.status(200);
|
||||
|
||||
@@ -106,7 +112,7 @@ public class XsltController implements RestController {
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request (XSLT, Xalan) processed in " + duration + " ms.");
|
||||
|
||||
responseJson.addProperty("processor", Xalan.getVersion());
|
||||
responseJson.addProperty("processor", xalan.getVersion());
|
||||
responseJson.addProperty("time", duration);
|
||||
|
||||
response.body(this.gson.toJson(responseJson));
|
||||
|
||||
Reference in New Issue
Block a user