Added XMLRequestBody class and implemented it in XPath controller
This commit is contained in:
@@ -37,9 +37,9 @@ public class XPathController implements RestController {
|
|||||||
public void transform(Request request, Response response) {
|
public void transform(Request request, Response response) {
|
||||||
String body = request.body();
|
String body = request.body();
|
||||||
|
|
||||||
JsonObject requestJson;
|
XMLRequestBody requestBody;
|
||||||
try {
|
try {
|
||||||
requestJson = this.gson.fromJson(body, JsonObject.class);
|
requestBody = this.gson.fromJson(body, XMLRequestBody.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
JsonObject responseJson = prepareErrorResponse(e.getMessage(), "N/A");
|
JsonObject responseJson = prepareErrorResponse(e.getMessage(), "N/A");
|
||||||
response.status(400);
|
response.status(400);
|
||||||
@@ -47,33 +47,29 @@ public class XPathController implements RestController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String data = requestJson.get("data").getAsString();
|
if (requestBody.getProcessor() == null) {
|
||||||
String query = requestJson.get("process").getAsString();
|
|
||||||
String processor = requestJson.get("processor").getAsString();
|
|
||||||
String version = requestJson.get("version").getAsString();
|
|
||||||
|
|
||||||
if (processor == null) {
|
|
||||||
response.body("saxon, xalan");
|
response.body("saxon, xalan");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject responseJson = new JsonObject();
|
JsonObject responseJson = new JsonObject();
|
||||||
switch (processor) {
|
switch (requestBody.getProcessor()) {
|
||||||
case "saxon":
|
case "saxon":
|
||||||
processWithSaxon(response, data, query, version, responseJson);
|
processWithSaxon(response, requestBody, responseJson);
|
||||||
break;
|
break;
|
||||||
case "xalan":
|
case "xalan":
|
||||||
processWithXalan(response, data, query, responseJson);
|
processWithXalan(response, requestBody, responseJson);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
response.body("saxon, xalan");
|
response.body("saxon, xalan");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processWithXalan(Response response, String data, String query, JsonObject responseJson) {
|
private void processWithXalan(Response response, XMLRequestBody requestBody, JsonObject responseJson) {
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
XPathQueryResult xPathQueryResult = xalan.processXPath(data, query, "");
|
XPathQueryResult xPathQueryResult =
|
||||||
|
xalan.processXPath(requestBody.getData(), requestBody.getProcess(), "");
|
||||||
|
|
||||||
response.status(200);
|
response.status(200);
|
||||||
|
|
||||||
@@ -97,16 +93,18 @@ public class XPathController implements RestController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processWithSaxon(Response response, String data, String query, String version, JsonObject responseJson) {
|
private void processWithSaxon(Response response, XMLRequestBody requestBody, JsonObject responseJson) {
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
String result = saxon.processXPath(data, query, version).getData().trim();
|
String result =
|
||||||
|
saxon.processXPath(requestBody.getData(), requestBody.getProcess(), requestBody.getVersion())
|
||||||
|
.getData().trim();
|
||||||
|
|
||||||
response.status(200);
|
response.status(200);
|
||||||
|
|
||||||
responseJson.addProperty("result", result);
|
responseJson.addProperty("result", result);
|
||||||
responseJson.addProperty("status", "OK");
|
responseJson.addProperty("status", "OK");
|
||||||
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + version + " over s9api");
|
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + requestBody.getVersion() + " over s9api");
|
||||||
|
|
||||||
long duration = System.currentTimeMillis() - timeStart;
|
long duration = System.currentTimeMillis() - timeStart;
|
||||||
responseJson.addProperty("time", duration);
|
responseJson.addProperty("time", duration);
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.r11.tools.controller.internal;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class XMLRequestBody {
|
||||||
|
@SerializedName("data")
|
||||||
|
private String data;
|
||||||
|
@SerializedName("process")
|
||||||
|
private String process;
|
||||||
|
@SerializedName("processor")
|
||||||
|
private String processor;
|
||||||
|
@SerializedName("version")
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
public String getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProcess() {
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProcessor() {
|
||||||
|
return processor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user