Merge pull request 'bema/func/xalan_error_handling' (#24) from bema/func/xalan_error_handling into dev

Reviewed-on: R11/release11-tools-web#24
This commit is contained in:
2023-02-10 11:58:19 +01:00

View File

@@ -1,5 +1,6 @@
package com.r11.tools.xslt;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.r11.tools.xslt.processors.Saxon;
@@ -65,8 +66,15 @@ public class SparkInitializer {
Map<String, String> responseMap = new HashMap<>();
try {
requestMap = mapper.readValue(body, Map.class);
} catch (JsonMappingException ex) {
ex.printStackTrace();
} catch (JsonMappingException | JsonParseException ex) {
LOG.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");
@@ -103,8 +111,15 @@ public class SparkInitializer {
Map<String, String> responseMap = new HashMap<>();
try {
requestMap = mapper.readValue(body, Map.class);
} catch (JsonMappingException ex) {
LOG.error("JSON mapping error. " + ex);
} catch (JsonMappingException | JsonParseException ex) {
LOG.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");
@@ -158,7 +173,6 @@ public class SparkInitializer {
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;
@@ -174,17 +188,24 @@ public class SparkInitializer {
private static final Route xsltHandler = (Request req, Response resp) -> {
String body = req.body();
ObjectMapper mapper = new ObjectMapper();
Map<String, String> jsonMap = new HashMap<>();
Map<String, String> requestMap = new HashMap<>();
Map<String, String> responseMap = new HashMap<>();
try {
jsonMap = mapper.readValue(body, Map.class);
} catch (JsonMappingException ex) {
LOG.error("JSON mapping error. " + ex);
requestMap = mapper.readValue(body, Map.class);
} catch (JsonMappingException | JsonParseException ex) {
LOG.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 = jsonMap.get("data");
String query = jsonMap.get("process");
String processor = jsonMap.get("processor");
String version = jsonMap.get("version");
String data = requestMap.get("data");
String query = requestMap.get("process");
String processor = requestMap.get("processor");
String version = requestMap.get("version");
if (processor == null) {
return "saxon, xalan";