Removed duplicate code
This commit is contained in:
@@ -31,7 +31,7 @@ public class XPathController implements RestController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xpath")
|
@ScopedControllerManifest(method = HandlerType.POST, path = "/xpath")
|
||||||
public void transform(Request request, Response response) {
|
public void acceptRequest(Request request, Response response) {
|
||||||
|
|
||||||
XMLRequestBody requestBody;
|
XMLRequestBody requestBody;
|
||||||
try {
|
try {
|
||||||
@@ -50,63 +50,39 @@ public class XPathController implements RestController {
|
|||||||
|
|
||||||
switch (requestBody.getProcessor()) {
|
switch (requestBody.getProcessor()) {
|
||||||
case "saxon":
|
case "saxon":
|
||||||
processWithSaxon(response, requestBody);
|
process(response, requestBody, saxon);
|
||||||
break;
|
break;
|
||||||
case "xalan":
|
case "xalan":
|
||||||
processWithXalan(response, requestBody);
|
process(response, requestBody, xalan);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
response.body("saxon, xalan");
|
response.body("saxon, xalan");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processWithXalan(Response response, XMLRequestBody requestBody) {
|
private void process(Response response, XMLRequestBody requestBody, XmlEngine engine) {
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
XMLResponseBody responseBody = null;
|
XMLResponseBody responseBody = null;
|
||||||
try {
|
try {
|
||||||
XPathQueryResult xPathQueryResult =
|
XPathQueryResult xPathQueryResult =
|
||||||
xalan.processXPath(requestBody.getData(), requestBody.getProcess(), "");
|
engine.processXPath(requestBody.getData(), requestBody.getProcess(), "");
|
||||||
|
|
||||||
response.status(200);
|
response.status(200);
|
||||||
long duration = System.currentTimeMillis() - timeStart;
|
long duration = System.currentTimeMillis() - timeStart;
|
||||||
responseBody = new XMLResponseBody(xPathQueryResult.getData().trim(),
|
responseBody = new XMLResponseBody(xPathQueryResult.getData().trim(),
|
||||||
"OK", xalan.getVersion(),duration);
|
"OK", engine.getVersion(),duration);
|
||||||
|
|
||||||
responseBody.setType(xPathQueryResult.getType());
|
responseBody.setType(xPathQueryResult.getType());
|
||||||
this.logger.info("Request (XPath, Xalan) processed in " + duration + " ms.");
|
this.logger.info("Request (XPath, " + engine.getVersion() + ") processed in " + duration + " ms.");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
responseBody = prepareErrorResponse(ex.getMessage(), xalan.getVersion());
|
responseBody = prepareErrorResponse(ex.getMessage(), engine.getVersion());
|
||||||
response.status(400);
|
response.status(400);
|
||||||
|
|
||||||
this.logger.error("Error on processing XPath using Xalan. " + ex);
|
this.logger.error("Error on processing XPath using " + engine.getVersion() + ". " + ex);
|
||||||
} finally {
|
} finally {
|
||||||
response.body(this.gson.toJson(responseBody));
|
response.body(this.gson.toJson(responseBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processWithSaxon(Response response, XMLRequestBody requestBody) {
|
|
||||||
XMLResponseBody responseBody = null;
|
|
||||||
long timeStart = System.currentTimeMillis();
|
|
||||||
try {
|
|
||||||
String result =
|
|
||||||
saxon.processXPath(requestBody.getData(), requestBody.getProcess(), requestBody.getVersion())
|
|
||||||
.getData().trim();
|
|
||||||
|
|
||||||
response.status(200);
|
|
||||||
|
|
||||||
long duration = System.currentTimeMillis() - timeStart;
|
|
||||||
String processor = "Saxon " + saxon.getVersion() + " over s9api";
|
|
||||||
responseBody = new XMLResponseBody(result, "OK", processor, duration);
|
|
||||||
|
|
||||||
this.logger.info("Request (XPath, Saxon) processed in " + duration + " ms.");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
responseBody = prepareErrorResponse(ex.getMessage(), saxon.getVersion());
|
|
||||||
response.status(400);
|
|
||||||
this.logger.error("Error on processing XPath using Saxon. " + ex);
|
|
||||||
} finally {
|
|
||||||
response.body(this.gson.toJson(responseBody));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class XQueryController implements RestController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xquery")
|
@ScopedControllerManifest(method = HandlerType.POST, path = "/xquery")
|
||||||
public void transform(Request request, Response response) {
|
public void acceptRequest(Request request, Response response) {
|
||||||
XMLRequestBody requestBody;
|
XMLRequestBody requestBody;
|
||||||
try {
|
try {
|
||||||
requestBody = this.gson.fromJson(request.body(), XMLRequestBody.class);
|
requestBody = this.gson.fromJson(request.body(), XMLRequestBody.class);
|
||||||
@@ -45,7 +45,7 @@ public class XQueryController implements RestController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (requestBody.getProcessor().equals("saxon"))
|
if (requestBody.getProcessor().equals("saxon"))
|
||||||
processWithSaxon(response, requestBody);
|
process(response, requestBody, saxon);
|
||||||
else
|
else
|
||||||
response.body("saxon");
|
response.body("saxon");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -58,23 +58,23 @@ public class XQueryController implements RestController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processWithSaxon(Response response, XMLRequestBody requestBody) {
|
private void process(Response response, XMLRequestBody requestBody, XmlEngine engine) {
|
||||||
XMLResponseBody responseBody = null;
|
XMLResponseBody responseBody = null;
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
String result = saxon.executeXQuery(requestBody.getData(), requestBody.getProcess(), requestBody.getVersion());
|
String result = engine.executeXQuery(requestBody.getData(), requestBody.getProcess(), requestBody.getVersion());
|
||||||
|
|
||||||
response.status(200);
|
response.status(200);
|
||||||
|
|
||||||
long duration = System.currentTimeMillis() - timeStart;
|
long duration = System.currentTimeMillis() - timeStart;
|
||||||
responseBody = new XMLResponseBody(result, "OK", saxon.getVersion(), duration);
|
responseBody = new XMLResponseBody(result, "OK", engine.getVersion(), duration);
|
||||||
|
|
||||||
this.logger.info("Request (XQuery, Saxon) processed in " + duration + " ms.");
|
this.logger.info("Request (XQuery, " + engine.getVersion() + " processed in " + duration + " ms.");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
response.status(400);
|
response.status(400);
|
||||||
responseBody = prepareErrorResponse(ex.getMessage(), saxon.getVersion());
|
responseBody = prepareErrorResponse(ex.getMessage(), engine.getVersion());
|
||||||
|
|
||||||
this.logger.error("Error on processing XQuery using Saxon. " + ex);
|
this.logger.error("Error on processing XQuery using " + engine.getVersion() + ". " + ex);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
response.body(this.gson.toJson(responseBody));
|
response.body(this.gson.toJson(responseBody));
|
||||||
|
|||||||
@@ -27,38 +27,41 @@ public class XsdController implements RestController {
|
|||||||
return new XMLResponseBody(message, "ERR", processor, -1);
|
return new XMLResponseBody(message, "ERR", processor, -1);
|
||||||
}
|
}
|
||||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xsd")
|
@ScopedControllerManifest(method = HandlerType.POST, path = "/xsd")
|
||||||
public Response transform(Request request, Response response) {
|
public void acceptRequest(Request request, Response response) {
|
||||||
|
|
||||||
XMLRequestBody requestBody;
|
XMLRequestBody requestBody = null;
|
||||||
try {
|
try {
|
||||||
requestBody = this.gson.fromJson(request.body(), XMLRequestBody.class);
|
requestBody = this.gson.fromJson(request.body(), XMLRequestBody.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
XMLResponseBody responseJson = prepareErrorResponse(e.getMessage(), "N/A");
|
XMLResponseBody responseBody = prepareErrorResponse(e.getMessage(), "N/A");
|
||||||
|
|
||||||
response.status(400);
|
response.status(400);
|
||||||
response.body(this.gson.toJson(responseJson));
|
response.body(this.gson.toJson(responseBody));
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
process(response, requestBody, xalan);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void process(Response response, XMLRequestBody requestBody, XmlEngine engine) {
|
||||||
XMLResponseBody responseBody;
|
XMLResponseBody responseBody;
|
||||||
try {
|
try {
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
String result = xalan.validate(requestBody.getData(), requestBody.getProcess()).trim();
|
String result = engine.validate(requestBody.getData(), requestBody.getProcess()).trim();
|
||||||
|
|
||||||
response.status(200);
|
response.status(200);
|
||||||
|
|
||||||
long duration = System.currentTimeMillis() - timeStart;
|
long duration = System.currentTimeMillis() - timeStart;
|
||||||
responseBody = new XMLResponseBody(result, "OK", xalan.getVersion(), duration);
|
responseBody = new XMLResponseBody(result, "OK", engine.getVersion(), duration);
|
||||||
|
|
||||||
this.logger.info("Request (XSD, Xalan) processed in " + duration + " ms.");
|
this.logger.info("Request (XSD, " + engine.getVersion() + ") processed in " + duration + " ms.");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
responseBody = prepareErrorResponse(ex.getMessage(), xalan.getVersion());
|
responseBody = prepareErrorResponse(ex.getMessage(), engine.getVersion());
|
||||||
response.status(400);
|
response.status(400);
|
||||||
|
|
||||||
this.logger.error("Error on validation against XSD using Xalan. " + ex);
|
this.logger.error("Error on validation against XSD using " + engine.getVersion() + ". " + ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.body(this.gson.toJson(responseBody));
|
response.body(this.gson.toJson(responseBody));
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class XsltController implements RestController {
|
|||||||
return new XMLResponseBody(message, "ERR", processor, -1);
|
return new XMLResponseBody(message, "ERR", processor, -1);
|
||||||
}
|
}
|
||||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xslt")
|
@ScopedControllerManifest(method = HandlerType.POST, path = "/xslt")
|
||||||
public void transform(Request request, Response response) {
|
public void acceptRequest(Request request, Response response) {
|
||||||
String body = request.body();
|
String body = request.body();
|
||||||
|
|
||||||
XMLRequestBody requestBody;
|
XMLRequestBody requestBody;
|
||||||
@@ -50,11 +50,11 @@ public class XsltController implements RestController {
|
|||||||
|
|
||||||
switch (requestBody.getProcessor()) {
|
switch (requestBody.getProcessor()) {
|
||||||
case "saxon":
|
case "saxon":
|
||||||
processWithSaxon(response, requestBody);
|
process(response, requestBody, saxon);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case "xalan":
|
case "xalan":
|
||||||
processWithXalan(response, requestBody);
|
process(response, requestBody, xalan);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -62,21 +62,21 @@ public class XsltController implements RestController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processWithXalan(Response response, XMLRequestBody requestBody) {
|
private void process(Response response, XMLRequestBody requestBody, XmlEngine engine) {
|
||||||
XMLResponseBody responseBody = null;
|
XMLResponseBody responseBody = null;
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
String result = xalan.processXSLT(requestBody.getData(), requestBody.getProcess());
|
String result = engine.processXSLT(requestBody.getData(), requestBody.getProcess());
|
||||||
response.status(200);
|
response.status(200);
|
||||||
|
|
||||||
long duration = System.currentTimeMillis() - timeStart;
|
long duration = System.currentTimeMillis() - timeStart;
|
||||||
responseBody = new XMLResponseBody(result, "OK", xalan.getVersion(), duration);
|
responseBody = new XMLResponseBody(result, "OK", engine.getVersion(), duration);
|
||||||
|
|
||||||
this.logger.info("Request (XSLT, Xalan) processed in " + duration + " ms.");
|
this.logger.info("Request (XSLT, " + engine.getVersion() + "processed in " + duration + " ms.");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
responseBody = prepareErrorResponse(ex.getMessage(), xalan.getVersion());
|
responseBody = prepareErrorResponse(ex.getMessage(), engine.getVersion());
|
||||||
response.status(400);
|
response.status(400);
|
||||||
this.logger.error("Error on processing XSLT using Xalan. " + ex);
|
this.logger.error("Error on processing XSLT using " + engine.getVersion() + ". " + ex);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
response.body(this.gson.toJson(responseBody));
|
response.body(this.gson.toJson(responseBody));
|
||||||
@@ -84,26 +84,4 @@ public class XsltController implements RestController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processWithSaxon(Response response, XMLRequestBody requestBody) {
|
|
||||||
XMLResponseBody responseBody = null;
|
|
||||||
long timeStart = System.currentTimeMillis();
|
|
||||||
try {
|
|
||||||
String result = saxon.processXSLT(requestBody.getData(), requestBody.getProcess());
|
|
||||||
response.status(200);
|
|
||||||
|
|
||||||
long duration = System.currentTimeMillis() - timeStart;
|
|
||||||
responseBody = new XMLResponseBody(result, "OK", saxon.getVersion(), duration);
|
|
||||||
this.logger.info("Request (XSLT, Saxon) processed in " + duration + " ms.");
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
responseBody = prepareErrorResponse(ex.getMessage(), saxon.getVersion());
|
|
||||||
response.status(400);
|
|
||||||
|
|
||||||
this.logger.error("Error on processing XSLT using Saxon. " + ex);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
response.body(this.gson.toJson(responseBody));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user