bema/func/log4j_logging #6
@@ -49,6 +49,7 @@ public class SparkInitializer {
|
|||||||
resp.header("processor", "Saxon " + Saxon.getVersion() + " over s9api");
|
resp.header("processor", "Saxon " + Saxon.getVersion() + " over s9api");
|
||||||
return Saxon.getVersion();
|
return Saxon.getVersion();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
LOG.error("Error on retrieving engine version. " + ex);
|
||||||
return ex.getMessage();
|
return ex.getMessage();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -59,7 +60,6 @@ public class SparkInitializer {
|
|||||||
*/
|
*/
|
||||||
private static Route xsdHandler = (Request req, Response resp) -> {
|
private static Route xsdHandler = (Request req, Response resp) -> {
|
||||||
String body = req.body();
|
String body = req.body();
|
||||||
LOG.info("Request: " + body);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
Map<String, String> requestMap = null;
|
Map<String, String> requestMap = null;
|
||||||
Map<String, String> responseMap = new HashMap<>();
|
Map<String, String> responseMap = new HashMap<>();
|
||||||
@@ -82,7 +82,7 @@ public class SparkInitializer {
|
|||||||
responseMap.put("result", tmp);
|
responseMap.put("result", tmp);
|
||||||
responseMap.put("status", "OK");
|
responseMap.put("status", "OK");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Exception: "+ ex.getMessage());
|
LOG.error("Error on validation against XSD using Xalan. " + ex);
|
||||||
responseMap.put("result", ex.getMessage());
|
responseMap.put("result", ex.getMessage());
|
||||||
responseMap.put("status", "ERR");
|
responseMap.put("status", "ERR");
|
||||||
resp.status(400);
|
resp.status(400);
|
||||||
@@ -100,15 +100,13 @@ public class SparkInitializer {
|
|||||||
*/
|
*/
|
||||||
private static Route xpathHandler = (Request req, Response resp) -> {
|
private static Route xpathHandler = (Request req, Response resp) -> {
|
||||||
String body = req.body();
|
String body = req.body();
|
||||||
LOG.info("Request: " + body);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
Map<String, String> requestMap = null;
|
Map<String, String> requestMap = null;
|
||||||
Map<String, String> responseMap = new HashMap<>();
|
Map<String, String> responseMap = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
requestMap = mapper.readValue(body, Map.class);
|
requestMap = mapper.readValue(body, Map.class);
|
||||||
} catch (JsonMappingException ex) {
|
} catch (JsonMappingException ex) {
|
||||||
LOG.error("Exception: "+ ex.getMessage());
|
LOG.error("JSON mapping error. " + ex);
|
||||||
//ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String data = requestMap.get("data");
|
String data = requestMap.get("data");
|
||||||
@@ -124,57 +122,51 @@ public class SparkInitializer {
|
|||||||
if (processor == null) {
|
if (processor == null) {
|
||||||
return "saxon, xalan";
|
return "saxon, xalan";
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
switch (processor) {
|
|
||||||
case "saxon":
|
|
||||||
resp.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
|
||||||
//LOG.info("Processing start...");
|
|
||||||
timeStart = System.currentTimeMillis();
|
|
||||||
try {
|
|
||||||
tmp = Saxon.processXPath(data, query, version).trim();
|
|
||||||
responseMap.put("result", tmp);
|
|
||||||
responseMap.put("status", "OK");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.error("Exception: "+ ex.getMessage());
|
|
||||||
responseMap.put("result", ex.getMessage());
|
|
||||||
responseMap.put("status", "ERR");
|
|
||||||
resp.status(400);
|
|
||||||
}
|
|
||||||
duration = System.currentTimeMillis() - timeStart;
|
|
||||||
//System.out.println("end(" + duration + ")");
|
|
||||||
LOG.info("Request" + body + " processed in " + duration + " ms.");
|
|
||||||
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
|
||||||
responseMap.put("time", "" + duration);
|
|
||||||
resp.body(mapper.writeValueAsString(responseMap));
|
|
||||||
return resp;
|
|
||||||
|
|
||||||
case "xalan":
|
switch (processor) {
|
||||||
resp.header("processor", Xalan.getVersion());
|
case "saxon":
|
||||||
timeStart = System.currentTimeMillis();
|
resp.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||||
try {
|
timeStart = System.currentTimeMillis();
|
||||||
tmp = Xalan.processXPath(data, query).trim();
|
try {
|
||||||
responseMap.put("result", tmp);
|
tmp = Saxon.processXPath(data, query, version).trim();
|
||||||
responseMap.put("status", "OK");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.error("Exception: "+ ex.getMessage());
|
|
||||||
responseMap.put("result", ex.getMessage());
|
|
||||||
responseMap.put("status", "ERR");
|
|
||||||
resp.status(400);
|
|
||||||
}
|
|
||||||
duration = System.currentTimeMillis() - timeStart;
|
|
||||||
responseMap.put("processor", Xalan.getVersion());
|
|
||||||
responseMap.put("result", tmp);
|
responseMap.put("result", tmp);
|
||||||
responseMap.put("time", Long.toString(duration));
|
responseMap.put("status", "OK");
|
||||||
resp.body(mapper.writeValueAsString(responseMap));
|
} catch (Exception ex) {
|
||||||
return resp;
|
LOG.error("Error on processing XPath using Saxon. " + ex);
|
||||||
|
responseMap.put("result", ex.getMessage());
|
||||||
|
responseMap.put("status", "ERR");
|
||||||
|
resp.status(400);
|
||||||
|
}
|
||||||
|
duration = System.currentTimeMillis() - timeStart;
|
||||||
|
LOG.info("Request" + body + " processed in " + duration + " ms.");
|
||||||
|
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
|
||||||
|
responseMap.put("time", "" + duration);
|
||||||
|
resp.body(mapper.writeValueAsString(responseMap));
|
||||||
|
return resp;
|
||||||
|
|
||||||
default:
|
case "xalan":
|
||||||
return "saxon, xalan";
|
resp.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) {
|
||||||
|
LOG.error("Error on processing XPath using Xalan. " + ex);
|
||||||
|
responseMap.put("result", ex.getMessage());
|
||||||
|
responseMap.put("status", "ERR");
|
||||||
|
resp.status(400);
|
||||||
|
}
|
||||||
|
duration = System.currentTimeMillis() - timeStart;
|
||||||
|
LOG.info("Request: " + body + " processed in " + duration + " ms.");
|
||||||
|
responseMap.put("processor", Xalan.getVersion());
|
||||||
|
responseMap.put("result", tmp);
|
||||||
|
responseMap.put("time", Long.toString(duration));
|
||||||
|
resp.body(mapper.writeValueAsString(responseMap));
|
||||||
|
return resp;
|
||||||
|
|
||||||
} catch (Exception ex) {
|
default:
|
||||||
ex.printStackTrace();
|
return "saxon, xalan";
|
||||||
return ex.getMessage();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,11 +180,8 @@ public class SparkInitializer {
|
|||||||
Map<String, String> responseMap = new HashMap<>();
|
Map<String, String> responseMap = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
jsonMap = mapper.readValue(body, Map.class);
|
jsonMap = mapper.readValue(body, Map.class);
|
||||||
LOG.info(jsonMap);
|
|
||||||
//System.out.println(jsonMap);
|
|
||||||
} catch (JsonMappingException ex) {
|
} catch (JsonMappingException ex) {
|
||||||
LOG.error("Exception: "+ ex.getMessage());
|
LOG.error("JSON mapping error. " + ex);
|
||||||
//ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
String data = jsonMap.get("data");
|
String data = jsonMap.get("data");
|
||||||
String query = jsonMap.get("process");
|
String query = jsonMap.get("process");
|
||||||
@@ -202,54 +191,51 @@ public class SparkInitializer {
|
|||||||
if (processor == null) {
|
if (processor == null) {
|
||||||
return "saxon, xalan";
|
return "saxon, xalan";
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
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) {
|
|
||||||
LOG.error("Exception: "+ ex.getMessage());
|
|
||||||
responseMap.put("result", ex.getMessage());
|
|
||||||
responseMap.put("status", "ERR");
|
|
||||||
resp.status(400);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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) {
|
||||||
|
LOG.error("Error on processing XSLT using Saxon. " + ex);
|
||||||
|
responseMap.put("result", ex.getMessage());
|
||||||
|
responseMap.put("status", "ERR");
|
||||||
|
resp.status(400);
|
||||||
|
}
|
||||||
|
duration = System.currentTimeMillis() - timeStart;
|
||||||
|
LOG.info("Request: " + body + " processed in " + duration + " ms.");
|
||||||
|
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version);
|
||||||
|
responseMap.put("time", Long.toString(duration));
|
||||||
|
resp.body(mapper.writeValueAsString(responseMap));
|
||||||
|
return resp;
|
||||||
|
|
||||||
duration = System.currentTimeMillis() - timeStart;
|
case "xalan":
|
||||||
responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version);
|
timeStart = System.currentTimeMillis();
|
||||||
responseMap.put("time", Long.toString(duration));
|
try {
|
||||||
resp.body(mapper.writeValueAsString(responseMap));
|
tmp = Xalan.processXSLT(data, query);
|
||||||
return resp;
|
responseMap.put("result", tmp);
|
||||||
|
responseMap.put("status", "OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error("Error on processing XSLT using Xalan. " + ex);
|
||||||
|
responseMap.put("result", ex.getMessage());
|
||||||
|
responseMap.put("status", "ERR");
|
||||||
|
resp.status(400);
|
||||||
|
}
|
||||||
|
duration = System.currentTimeMillis() - timeStart;
|
||||||
|
LOG.info("Request: " + body + " processed in " + duration + " ms.");
|
||||||
|
responseMap.put("processor", Xalan.getVersion());
|
||||||
|
responseMap.put("time", Long.toString(duration));
|
||||||
|
resp.body(mapper.writeValueAsString(responseMap));
|
||||||
|
return resp;
|
||||||
|
|
||||||
case "xalan":
|
default:
|
||||||
timeStart = System.currentTimeMillis();
|
return "saxon, xalan";
|
||||||
try {
|
|
||||||
tmp = Xalan.processXSLT(data, query);
|
|
||||||
responseMap.put("result", tmp);
|
|
||||||
responseMap.put("status", "OK");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.error("Exception: "+ ex.getMessage());
|
|
||||||
responseMap.put("result", ex.getMessage());
|
|
||||||
responseMap.put("status", "ERR");
|
|
||||||
resp.status(400);
|
|
||||||
}
|
|
||||||
duration = System.currentTimeMillis() - timeStart;
|
|
||||||
responseMap.put("processor", Xalan.getVersion());
|
|
||||||
responseMap.put("time", Long.toString(duration));
|
|
||||||
resp.body(mapper.writeValueAsString(responseMap));
|
|
||||||
return resp;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return "saxon, xalan";
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return ex.getMessage();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user