Unified intendations to 4 spaces in tools-services
This commit is contained in:
@@ -12,28 +12,28 @@ import spark.Spark;
|
||||
|
||||
public class SparkApplication {
|
||||
|
||||
public static void run() {
|
||||
// TODO: read port from config
|
||||
Spark.port(8081);
|
||||
public static void run() {
|
||||
// TODO: read port from config
|
||||
Spark.port(8081);
|
||||
|
||||
Spark.after((request, response) -> {
|
||||
response.header("Access-Control-Allow-Origin", "*");
|
||||
response.header("access-control-allow-headers", "*");
|
||||
response.header("access-control-expose-headers", "*");
|
||||
response.header("Access-Control-Allow-Methods", "POST");
|
||||
});
|
||||
Spark.after((request, response) -> {
|
||||
response.header("Access-Control-Allow-Origin", "*");
|
||||
response.header("access-control-allow-headers", "*");
|
||||
response.header("access-control-expose-headers", "*");
|
||||
response.header("Access-Control-Allow-Methods", "POST");
|
||||
});
|
||||
|
||||
Logger logger = LogManager.getLogger(SparkApplication.class);
|
||||
Logger logger = LogManager.getLogger(SparkApplication.class);
|
||||
|
||||
RestControllerRegistry registry = new RestControllerRegistry();
|
||||
registry.registerController(new ProcessorInfoController(logger));
|
||||
registry.registerController(new XsdController(logger));
|
||||
registry.registerController(new XPathController(logger));
|
||||
registry.registerController(new XsltController(logger));
|
||||
registry.registerController(new JsonController());
|
||||
RestControllerRegistry registry = new RestControllerRegistry();
|
||||
registry.registerController(new ProcessorInfoController(logger));
|
||||
registry.registerController(new XsdController(logger));
|
||||
registry.registerController(new XPathController(logger));
|
||||
registry.registerController(new XsltController(logger));
|
||||
registry.registerController(new JsonController());
|
||||
|
||||
registry.register();
|
||||
registry.register();
|
||||
|
||||
logger.info("Server is online at port: " + Spark.port());
|
||||
}
|
||||
logger.info("Server is online at port: " + Spark.port());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.r11.tools;
|
||||
|
||||
public class SparkInitializer {
|
||||
public static void main(String[] args) {
|
||||
SparkApplication.run();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SparkApplication.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,46 +13,46 @@ import spark.Response;
|
||||
@GlobalControllerManifest(path = "/json")
|
||||
public class JsonController implements RestController {
|
||||
|
||||
private final Gson prettyGson = new GsonBuilder()
|
||||
.disableHtmlEscaping()
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
private final Gson prettyGson = new GsonBuilder()
|
||||
.disableHtmlEscaping()
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
private final Gson gson = new GsonBuilder()
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
private final Gson gson = new GsonBuilder()
|
||||
.disableHtmlEscaping()
|
||||
.create();
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/formatting")
|
||||
public void formatting(Request request, Response response) {
|
||||
try {
|
||||
JsonObject jsonObject = this.gson.fromJson(request.body(), JsonObject.class);
|
||||
response.status(200);
|
||||
response.body(this.prettyGson.toJson(jsonObject));
|
||||
} catch (Exception e) {
|
||||
response.status(500);
|
||||
Throwable cause = e.getCause();
|
||||
if (cause == null) {
|
||||
response.body(e.getMessage());
|
||||
} else {
|
||||
response.body(cause.getMessage());
|
||||
}
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/formatting")
|
||||
public void formatting(Request request, Response response) {
|
||||
try {
|
||||
JsonObject jsonObject = this.gson.fromJson(request.body(), JsonObject.class);
|
||||
response.status(200);
|
||||
response.body(this.prettyGson.toJson(jsonObject));
|
||||
} catch (Exception e) {
|
||||
response.status(500);
|
||||
Throwable cause = e.getCause();
|
||||
if (cause == null) {
|
||||
response.body(e.getMessage());
|
||||
} else {
|
||||
response.body(cause.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/minimize")
|
||||
public void minimize(Request request, Response response) {
|
||||
try {
|
||||
JsonObject jsonObject = this.prettyGson.fromJson(request.body(), JsonObject.class);
|
||||
response.status(200);
|
||||
response.body(this.gson.toJson(jsonObject));
|
||||
} catch (Exception e) {
|
||||
response.status(500);
|
||||
Throwable cause = e.getCause();
|
||||
if (cause == null) {
|
||||
response.body(e.getMessage());
|
||||
} else {
|
||||
response.body(cause.getMessage());
|
||||
}
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/minimize")
|
||||
public void minimize(Request request, Response response) {
|
||||
try {
|
||||
JsonObject jsonObject = this.prettyGson.fromJson(request.body(), JsonObject.class);
|
||||
response.status(200);
|
||||
response.body(this.gson.toJson(jsonObject));
|
||||
} catch (Exception e) {
|
||||
response.status(500);
|
||||
Throwable cause = e.getCause();
|
||||
if (cause == null) {
|
||||
response.body(e.getMessage());
|
||||
} else {
|
||||
response.body(cause.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,23 +12,23 @@ import spark.Response;
|
||||
@GlobalControllerManifest
|
||||
public class ProcessorInfoController implements RestController {
|
||||
|
||||
private final Logger logger;
|
||||
private final Logger logger;
|
||||
|
||||
public ProcessorInfoController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler that returns processor version
|
||||
*/
|
||||
@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());
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on retrieving engine version. " + ex);
|
||||
response.body(ex.getMessage());
|
||||
public ProcessorInfoController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler that returns processor version
|
||||
*/
|
||||
@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());
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on retrieving engine version. " + ex);
|
||||
response.body(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,88 +17,88 @@ import spark.Response;
|
||||
@GlobalControllerManifest
|
||||
public class XPathController implements RestController {
|
||||
|
||||
private final Logger logger;
|
||||
private final Logger logger;
|
||||
|
||||
public XPathController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xpath")
|
||||
public void transform(Request request, Response response) throws JsonProcessingException {
|
||||
String body = request.body();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> requestMap = new HashMap<>();
|
||||
Map<String, String> responseMap = new HashMap<>();
|
||||
try {
|
||||
requestMap = mapper.readValue(body, Map.class);
|
||||
} catch (JsonProcessingException ex) {
|
||||
this.logger.error("Request JSON error. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("processor", "N/A");
|
||||
responseMap.put("status", "ERR");
|
||||
responseMap.put("time", "N/A");
|
||||
response.status(400);
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
public XPathController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
String data = requestMap.get("data");
|
||||
String query = requestMap.get("process");
|
||||
String processor = requestMap.get("processor");
|
||||
String version = requestMap.get("version");
|
||||
|
||||
|
||||
String tmp = "";
|
||||
long timeStart;
|
||||
long duration;
|
||||
|
||||
if (processor == null) {
|
||||
response.body("saxon, xalan");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (processor) {
|
||||
case "saxon":
|
||||
response.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||
timeStart = System.currentTimeMillis();
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xpath")
|
||||
public void transform(Request request, Response response) throws JsonProcessingException {
|
||||
String body = request.body();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> requestMap = new HashMap<>();
|
||||
Map<String, String> responseMap = new HashMap<>();
|
||||
try {
|
||||
tmp = Saxon.processXPath(data, query, version).trim();
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XPath using Saxon. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
requestMap = mapper.readValue(body, Map.class);
|
||||
} catch (JsonProcessingException ex) {
|
||||
this.logger.error("Request JSON error. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("processor", "N/A");
|
||||
responseMap.put("status", "ERR");
|
||||
responseMap.put("time", "N/A");
|
||||
response.status(400);
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
}
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request" + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||
responseMap.put("time", "" + duration);
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
|
||||
case "xalan":
|
||||
response.header("processor", Xalan.getVersion());
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Xalan.processXPath(data, query).trim();
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XPath using Xalan. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
String data = requestMap.get("data");
|
||||
String query = requestMap.get("process");
|
||||
String processor = requestMap.get("processor");
|
||||
String version = requestMap.get("version");
|
||||
|
||||
|
||||
String tmp = "";
|
||||
long timeStart;
|
||||
long duration;
|
||||
|
||||
if (processor == null) {
|
||||
response.body("saxon, xalan");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (processor) {
|
||||
case "saxon":
|
||||
response.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Saxon.processXPath(data, query, version).trim();
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XPath using Saxon. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
}
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request" + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||
responseMap.put("time", "" + duration);
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
|
||||
case "xalan":
|
||||
response.header("processor", Xalan.getVersion());
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Xalan.processXPath(data, query).trim();
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XPath using Xalan. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
}
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", Xalan.getVersion());
|
||||
responseMap.put("time", Long.toString(duration));
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
default:
|
||||
response.body("saxon, xalan");
|
||||
}
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", Xalan.getVersion());
|
||||
responseMap.put("time", Long.toString(duration));
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
default:
|
||||
response.body("saxon, xalan");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,55 +16,55 @@ import spark.Response;
|
||||
@GlobalControllerManifest
|
||||
public class XsdController implements RestController {
|
||||
|
||||
private final Logger logger;
|
||||
private final Logger logger;
|
||||
|
||||
public XsdController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xsd")
|
||||
public Response transform(Request req, Response resp) throws JsonProcessingException {
|
||||
String body = req.body();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> requestMap = new HashMap<>();
|
||||
Map<String, String> responseMap = new HashMap<>();
|
||||
|
||||
try {
|
||||
requestMap = mapper.readValue(body, Map.class);
|
||||
} catch (JsonProcessingException ex) {
|
||||
this.logger.error("Request JSON error. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("processor", "N/A");
|
||||
responseMap.put("status", "ERR");
|
||||
responseMap.put("time", "N/A");
|
||||
resp.status(400);
|
||||
resp.body(mapper.writeValueAsString(responseMap));
|
||||
return resp;
|
||||
public XsdController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
String data = requestMap.get("data");
|
||||
String xsd = requestMap.get("process");
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xsd")
|
||||
public Response transform(Request req, Response resp) throws JsonProcessingException {
|
||||
String body = req.body();
|
||||
|
||||
resp.header("processor", Xalan.getVersion());
|
||||
long timeStart = System.currentTimeMillis();
|
||||
String tmp;
|
||||
try {
|
||||
tmp = Xalan.validate(data, xsd).trim();
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on validation against XSD using Xalan. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
resp.status(400);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> requestMap = new HashMap<>();
|
||||
Map<String, String> responseMap = new HashMap<>();
|
||||
|
||||
try {
|
||||
requestMap = mapper.readValue(body, Map.class);
|
||||
} catch (JsonProcessingException ex) {
|
||||
this.logger.error("Request JSON error. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("processor", "N/A");
|
||||
responseMap.put("status", "ERR");
|
||||
responseMap.put("time", "N/A");
|
||||
resp.status(400);
|
||||
resp.body(mapper.writeValueAsString(responseMap));
|
||||
return resp;
|
||||
}
|
||||
|
||||
String data = requestMap.get("data");
|
||||
String xsd = requestMap.get("process");
|
||||
|
||||
resp.header("processor", Xalan.getVersion());
|
||||
long timeStart = System.currentTimeMillis();
|
||||
String tmp;
|
||||
try {
|
||||
tmp = Xalan.validate(data, xsd).trim();
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on validation against XSD using Xalan. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
resp.status(400);
|
||||
}
|
||||
|
||||
long duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", Xalan.getVersion());
|
||||
responseMap.put("time", "" + duration);
|
||||
resp.body(mapper.writeValueAsString(responseMap));
|
||||
return resp;
|
||||
}
|
||||
|
||||
long duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", Xalan.getVersion());
|
||||
responseMap.put("time", "" + duration);
|
||||
resp.body(mapper.writeValueAsString(responseMap));
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,87 +19,87 @@ import spark.Response;
|
||||
@GlobalControllerManifest
|
||||
public class XsltController implements RestController {
|
||||
|
||||
private final Logger logger;
|
||||
private final Logger logger;
|
||||
|
||||
public XsltController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xslt")
|
||||
public void transform(Request request, Response response) throws JsonProcessingException {
|
||||
String body = request.body();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> requestMap = new HashMap<>();
|
||||
Map<String, String> responseMap = new HashMap<>();
|
||||
try {
|
||||
requestMap = mapper.readValue(body, Map.class);
|
||||
} catch (JsonMappingException | JsonParseException ex) {
|
||||
this.logger.error("Request JSON error. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("processor", "N/A");
|
||||
responseMap.put("status", "ERR");
|
||||
responseMap.put("time", "N/A");
|
||||
response.status(400);
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
public XsltController(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
String data = requestMap.get("data");
|
||||
String query = requestMap.get("process");
|
||||
String processor = requestMap.get("processor");
|
||||
String version = requestMap.get("version");
|
||||
|
||||
if (processor == null) {
|
||||
response.body("saxon, xalan");
|
||||
return;
|
||||
}
|
||||
|
||||
String tmp;
|
||||
long timeStart;
|
||||
long duration;
|
||||
switch (processor) {
|
||||
case "saxon":
|
||||
timeStart = System.currentTimeMillis();
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/xslt")
|
||||
public void transform(Request request, Response response) throws JsonProcessingException {
|
||||
String body = request.body();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> requestMap = new HashMap<>();
|
||||
Map<String, String> responseMap = new HashMap<>();
|
||||
try {
|
||||
tmp = Saxon.processXSLT(data, query);
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XSLT using Saxon. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
requestMap = mapper.readValue(body, Map.class);
|
||||
} catch (JsonMappingException | JsonParseException ex) {
|
||||
this.logger.error("Request JSON error. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("processor", "N/A");
|
||||
responseMap.put("status", "ERR");
|
||||
responseMap.put("time", "N/A");
|
||||
response.status(400);
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
}
|
||||
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version);
|
||||
responseMap.put("time", Long.toString(duration));
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
String data = requestMap.get("data");
|
||||
String query = requestMap.get("process");
|
||||
String processor = requestMap.get("processor");
|
||||
String version = requestMap.get("version");
|
||||
|
||||
case "xalan":
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Xalan.processXSLT(data, query);
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XSLT using Xalan. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
if (processor == null) {
|
||||
response.body("saxon, xalan");
|
||||
return;
|
||||
}
|
||||
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", Xalan.getVersion());
|
||||
responseMap.put("time", Long.toString(duration));
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
String tmp;
|
||||
long timeStart;
|
||||
long duration;
|
||||
switch (processor) {
|
||||
case "saxon":
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Saxon.processXSLT(data, query);
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XSLT using Saxon. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
}
|
||||
|
||||
default:
|
||||
response.body("saxon, xalan");
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version);
|
||||
responseMap.put("time", Long.toString(duration));
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
|
||||
case "xalan":
|
||||
timeStart = System.currentTimeMillis();
|
||||
try {
|
||||
tmp = Xalan.processXSLT(data, query);
|
||||
responseMap.put("result", tmp);
|
||||
responseMap.put("status", "OK");
|
||||
} catch (Exception ex) {
|
||||
this.logger.error("Error on processing XSLT using Xalan. " + ex);
|
||||
responseMap.put("result", ex.getMessage());
|
||||
responseMap.put("status", "ERR");
|
||||
response.status(400);
|
||||
}
|
||||
|
||||
duration = System.currentTimeMillis() - timeStart;
|
||||
this.logger.info("Request: " + body + " processed in " + duration + " ms.");
|
||||
responseMap.put("processor", Xalan.getVersion());
|
||||
responseMap.put("time", Long.toString(duration));
|
||||
response.body(mapper.writeValueAsString(responseMap));
|
||||
return;
|
||||
|
||||
default:
|
||||
response.body("saxon, xalan");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ import java.lang.annotation.Target;
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface GlobalControllerManifest {
|
||||
|
||||
String path() default "";
|
||||
String path() default "";
|
||||
}
|
||||
@@ -2,6 +2,6 @@ package com.r11.tools.controller.internal;
|
||||
|
||||
public enum HandlerType {
|
||||
|
||||
GET, POST, PUT, DELETE
|
||||
GET, POST, PUT, DELETE
|
||||
|
||||
}
|
||||
|
||||
@@ -8,52 +8,52 @@ import spark.Spark;
|
||||
|
||||
public class RestControllerRegistry {
|
||||
|
||||
private final Set<RestController> registeredControllers;
|
||||
private final Set<RestController> registeredControllers;
|
||||
|
||||
public RestControllerRegistry() {
|
||||
this.registeredControllers = new HashSet<>();
|
||||
}
|
||||
|
||||
public void registerController(RestController restController) {
|
||||
this.registeredControllers.add(restController);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
this.registeredControllers.forEach(controller -> {
|
||||
if (controller.getClass().isAnnotationPresent(GlobalControllerManifest.class)) {
|
||||
for (Method method : controller.getClass().getMethods()) {
|
||||
this.registerAssignableHandlers(controller.getClass(), controller, method);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerAssignableHandlers(Class<? extends RestController> parent, RestController parentValue, Method method) {
|
||||
if (
|
||||
(parent.isAnnotationPresent(GlobalControllerManifest.class)) &&
|
||||
(method.isAnnotationPresent(ScopedControllerManifest.class))
|
||||
) {
|
||||
HandlerType handlerType = method.getAnnotation(ScopedControllerManifest.class).method();
|
||||
|
||||
String path = PathBuilder.resolvePathOf(
|
||||
parent.getAnnotation(GlobalControllerManifest.class).path(),
|
||||
method.getAnnotation(ScopedControllerManifest.class).path()
|
||||
);
|
||||
|
||||
switch (handlerType) {
|
||||
case GET:
|
||||
Spark.get(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
case PUT:
|
||||
Spark.put(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
case POST:
|
||||
Spark.post(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
case DELETE:
|
||||
Spark.delete(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
}
|
||||
public RestControllerRegistry() {
|
||||
this.registeredControllers = new HashSet<>();
|
||||
}
|
||||
|
||||
public void registerController(RestController restController) {
|
||||
this.registeredControllers.add(restController);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
this.registeredControllers.forEach(controller -> {
|
||||
if (controller.getClass().isAnnotationPresent(GlobalControllerManifest.class)) {
|
||||
for (Method method : controller.getClass().getMethods()) {
|
||||
this.registerAssignableHandlers(controller.getClass(), controller, method);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerAssignableHandlers(Class<? extends RestController> parent, RestController parentValue, Method method) {
|
||||
if (
|
||||
(parent.isAnnotationPresent(GlobalControllerManifest.class)) &&
|
||||
(method.isAnnotationPresent(ScopedControllerManifest.class))
|
||||
) {
|
||||
HandlerType handlerType = method.getAnnotation(ScopedControllerManifest.class).method();
|
||||
|
||||
String path = PathBuilder.resolvePathOf(
|
||||
parent.getAnnotation(GlobalControllerManifest.class).path(),
|
||||
method.getAnnotation(ScopedControllerManifest.class).path()
|
||||
);
|
||||
|
||||
switch (handlerType) {
|
||||
case GET:
|
||||
Spark.get(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
case PUT:
|
||||
Spark.put(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
case POST:
|
||||
Spark.post(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
case DELETE:
|
||||
Spark.delete(path, (request, response) -> method.invoke(parentValue, request, response));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ScopedControllerManifest {
|
||||
|
||||
HandlerType method();
|
||||
HandlerType method();
|
||||
|
||||
String path();
|
||||
String path();
|
||||
}
|
||||
Reference in New Issue
Block a user