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