bema/func/log4j_logging #6
@@ -14,6 +14,7 @@
 | 
				
			|||||||
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
					    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
				
			||||||
    <jackson.version>2.14.1</jackson.version>
 | 
					    <jackson.version>2.14.1</jackson.version>
 | 
				
			||||||
    <slf4j.version>2.0.6</slf4j.version>
 | 
					    <slf4j.version>2.0.6</slf4j.version>
 | 
				
			||||||
 | 
					    <log4j.version>2.19.0</log4j.version>
 | 
				
			||||||
  </properties>
 | 
					  </properties>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <build>
 | 
					  <build>
 | 
				
			||||||
@@ -133,8 +134,15 @@
 | 
				
			|||||||
    <dependency>
 | 
					    <dependency>
 | 
				
			||||||
      <groupId>org.apache.logging.log4j</groupId>
 | 
					      <groupId>org.apache.logging.log4j</groupId>
 | 
				
			||||||
      <artifactId>log4j-core</artifactId>
 | 
					      <artifactId>log4j-core</artifactId>
 | 
				
			||||||
      <version>2.19.0</version>
 | 
					      <version>${log4j.version}</version>
 | 
				
			||||||
    </dependency>
 | 
					    </dependency>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <dependency>
 | 
				
			||||||
 | 
					      <groupId>org.apache.logging.log4j</groupId>
 | 
				
			||||||
 | 
					      <artifactId>log4j-api</artifactId>
 | 
				
			||||||
 | 
					      <version>${log4j.version}</version>
 | 
				
			||||||
 | 
					    </dependency>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  </dependencies>
 | 
					  </dependencies>
 | 
				
			||||||
</project>
 | 
					</project>
 | 
				
			||||||
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.JsonMappingException;
 | 
				
			|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
 | 
					import com.fasterxml.jackson.databind.ObjectMapper;
 | 
				
			||||||
import com.r11.tools.xslt.processors.Saxon;
 | 
					import com.r11.tools.xslt.processors.Saxon;
 | 
				
			||||||
import com.r11.tools.xslt.processors.Xalan;
 | 
					import com.r11.tools.xslt.processors.Xalan;
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.LogManager;
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.Logger;
 | 
				
			||||||
import spark.*;
 | 
					import spark.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
@@ -14,6 +16,9 @@ import java.util.Map;
 | 
				
			|||||||
 * @author Wojciech Czop
 | 
					 * @author Wojciech Czop
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class SparkInitializer {
 | 
					public class SparkInitializer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final Logger LOG = LogManager.getLogger(SparkInitializer.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Initializes spark framework
 | 
					     * Initializes spark framework
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@@ -32,7 +37,8 @@ public class SparkInitializer {
 | 
				
			|||||||
        Spark.post("/xpathpost", xpathHandler);
 | 
					        Spark.post("/xpathpost", xpathHandler);
 | 
				
			||||||
        Spark.post("/xsdpost", xsdHandler);
 | 
					        Spark.post("/xsdpost", xsdHandler);
 | 
				
			||||||
        Spark.get("/procinfo", procinfoHandler);
 | 
					        Spark.get("/procinfo", procinfoHandler);
 | 
				
			||||||
        System.out.println("Server is online");
 | 
					
 | 
				
			||||||
 | 
					        LOG.info("Server is online at port: " + Spark.port());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -53,7 +59,7 @@ 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();
 | 
				
			||||||
        System.out.println("Request: " + 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<>();
 | 
				
			||||||
@@ -76,12 +82,13 @@ 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) {
 | 
				
			||||||
            System.out.println("Exception: "+ex.getMessage());
 | 
					            LOG.error("Exception: "+ ex.getMessage());
 | 
				
			||||||
            responseMap.put("result", ex.getMessage());
 | 
					            responseMap.put("result", ex.getMessage());
 | 
				
			||||||
            responseMap.put("status", "ERR");
 | 
					            responseMap.put("status", "ERR");
 | 
				
			||||||
            resp.status(400);
 | 
					            resp.status(400);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        long duration = System.currentTimeMillis() - timeStart;
 | 
					        long duration = System.currentTimeMillis() - timeStart;
 | 
				
			||||||
 | 
					        LOG.info("Request: " + body + " processed in " + duration + " ms.");
 | 
				
			||||||
        responseMap.put("processor", Xalan.getVersion());
 | 
					        responseMap.put("processor", Xalan.getVersion());
 | 
				
			||||||
        responseMap.put("time", "" + duration);
 | 
					        responseMap.put("time", "" + duration);
 | 
				
			||||||
        resp.body(mapper.writeValueAsString(responseMap));
 | 
					        resp.body(mapper.writeValueAsString(responseMap));
 | 
				
			||||||
@@ -92,16 +99,16 @@ public class SparkInitializer {
 | 
				
			|||||||
     * Handler that returns output of xpath query and processor data
 | 
					     * Handler that returns output of xpath query and processor data
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static Route xpathHandler = (Request req, Response resp) -> {
 | 
					    private static Route xpathHandler = (Request req, Response resp) -> {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        String body = req.body();
 | 
					        String body = req.body();
 | 
				
			||||||
        System.out.println("Request: " + 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) {
 | 
				
			||||||
            ex.printStackTrace();
 | 
					            LOG.error("Exception: "+ ex.getMessage());
 | 
				
			||||||
 | 
					            //ex.printStackTrace();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String data = requestMap.get("data");
 | 
					        String data = requestMap.get("data");
 | 
				
			||||||
@@ -109,6 +116,7 @@ public class SparkInitializer {
 | 
				
			|||||||
        String processor = requestMap.get("processor");
 | 
					        String processor = requestMap.get("processor");
 | 
				
			||||||
        String version = requestMap.get("version");
 | 
					        String version = requestMap.get("version");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String tmp = "";
 | 
					        String tmp = "";
 | 
				
			||||||
        long timeStart;
 | 
					        long timeStart;
 | 
				
			||||||
        long duration;
 | 
					        long duration;
 | 
				
			||||||
@@ -120,19 +128,21 @@ public class SparkInitializer {
 | 
				
			|||||||
            switch (processor) {
 | 
					            switch (processor) {
 | 
				
			||||||
                case "saxon":
 | 
					                case "saxon":
 | 
				
			||||||
                    resp.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
 | 
					                    resp.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
 | 
				
			||||||
                    System.out.print("Processing start...");
 | 
					                    //LOG.info("Processing start...");
 | 
				
			||||||
                    timeStart = System.currentTimeMillis();
 | 
					                    timeStart = System.currentTimeMillis();
 | 
				
			||||||
                    try {
 | 
					                    try {
 | 
				
			||||||
                        tmp = Saxon.processXPath(data, query, version).trim();
 | 
					                        tmp = Saxon.processXPath(data, query, version).trim();
 | 
				
			||||||
                        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());
 | 
				
			||||||
                        responseMap.put("result", ex.getMessage());
 | 
					                        responseMap.put("result", ex.getMessage());
 | 
				
			||||||
                        responseMap.put("status", "ERR");
 | 
					                        responseMap.put("status", "ERR");
 | 
				
			||||||
                        resp.status(400);
 | 
					                        resp.status(400);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    duration = System.currentTimeMillis() - timeStart;
 | 
					                    duration = System.currentTimeMillis() - timeStart;
 | 
				
			||||||
                    System.out.println("end(" + duration + ")");
 | 
					                    //System.out.println("end(" + duration + ")");
 | 
				
			||||||
 | 
					                    LOG.info("Request" + body + " processed in " + duration + " ms.");
 | 
				
			||||||
                    responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
 | 
					                    responseMap.put("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
 | 
				
			||||||
                    responseMap.put("time", "" + duration);
 | 
					                    responseMap.put("time", "" + duration);
 | 
				
			||||||
                    resp.body(mapper.writeValueAsString(responseMap));
 | 
					                    resp.body(mapper.writeValueAsString(responseMap));
 | 
				
			||||||
@@ -146,6 +156,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());
 | 
				
			||||||
                        responseMap.put("result", ex.getMessage());
 | 
					                        responseMap.put("result", ex.getMessage());
 | 
				
			||||||
                        responseMap.put("status", "ERR");
 | 
					                        responseMap.put("status", "ERR");
 | 
				
			||||||
                        resp.status(400);
 | 
					                        resp.status(400);
 | 
				
			||||||
@@ -177,9 +188,11 @@ 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);
 | 
				
			||||||
            System.out.println(jsonMap);
 | 
					            LOG.info(jsonMap);
 | 
				
			||||||
 | 
					            //System.out.println(jsonMap);
 | 
				
			||||||
        } catch (JsonMappingException ex) {
 | 
					        } catch (JsonMappingException ex) {
 | 
				
			||||||
            ex.printStackTrace();
 | 
					            LOG.error("Exception: "+ ex.getMessage());
 | 
				
			||||||
 | 
					            //ex.printStackTrace();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        String data = jsonMap.get("data");
 | 
					        String data = jsonMap.get("data");
 | 
				
			||||||
        String query = jsonMap.get("process");
 | 
					        String query = jsonMap.get("process");
 | 
				
			||||||
@@ -201,6 +214,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());
 | 
				
			||||||
                        responseMap.put("result", ex.getMessage());
 | 
					                        responseMap.put("result", ex.getMessage());
 | 
				
			||||||
                        responseMap.put("status", "ERR");
 | 
					                        responseMap.put("status", "ERR");
 | 
				
			||||||
                        resp.status(400);
 | 
					                        resp.status(400);
 | 
				
			||||||
@@ -220,6 +234,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());
 | 
				
			||||||
                        responseMap.put("result", ex.getMessage());
 | 
					                        responseMap.put("result", ex.getMessage());
 | 
				
			||||||
                        responseMap.put("status", "ERR");
 | 
					                        responseMap.put("status", "ERR");
 | 
				
			||||||
                        resp.status(400);
 | 
					                        resp.status(400);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,8 @@ import net.sf.saxon.om.NamespaceBinding;
 | 
				
			|||||||
import net.sf.saxon.om.NamespaceMap;
 | 
					import net.sf.saxon.om.NamespaceMap;
 | 
				
			||||||
import net.sf.saxon.s9api.XPathCompiler;
 | 
					import net.sf.saxon.s9api.XPathCompiler;
 | 
				
			||||||
import net.sf.saxon.s9api.XdmNode;
 | 
					import net.sf.saxon.s9api.XdmNode;
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.LogManager;
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -13,6 +15,7 @@ import java.util.Iterator;
 | 
				
			|||||||
 * @author Wojciech Czop
 | 
					 * @author Wojciech Czop
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class NewNamespaceResolver {
 | 
					public class NewNamespaceResolver {
 | 
				
			||||||
 | 
					    private static final Logger LOG = LogManager.getLogger("NewNamespaceResolver");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private NamespaceMap namespaceMap;
 | 
					    private NamespaceMap namespaceMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -63,10 +66,7 @@ public class NewNamespaceResolver {
 | 
				
			|||||||
                XdmNode rNode = it.next();
 | 
					                XdmNode rNode = it.next();
 | 
				
			||||||
//                TODO: remove
 | 
					//                TODO: remove
 | 
				
			||||||
                if(rNode.getUnderlyingNode().getPrefix().isEmpty() && !rNode.getParent().getUnderlyingNode().getPrefix().isEmpty()){
 | 
					                if(rNode.getUnderlyingNode().getPrefix().isEmpty() && !rNode.getParent().getUnderlyingNode().getPrefix().isEmpty()){
 | 
				
			||||||
 | 
					                    LOG.warn("Missing prefix. Parent has " + rNode.getParent().getUnderlyingNode().getPrefix() + ", but child has none");
 | 
				
			||||||
                    System.out.println("prefix missing, parent has "+rNode.getParent().getUnderlyingNode().getPrefix() + ", but child has none");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    System.out.println();
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
//                end
 | 
					//                end
 | 
				
			||||||
                extractNamespace(rNode);
 | 
					                extractNamespace(rNode);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,9 @@
 | 
				
			|||||||
package com.r11.tools.xslt.processors;
 | 
					package com.r11.tools.xslt.processors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.sf.saxon.s9api.*;
 | 
					import net.sf.saxon.s9api.*;
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.LogManager;
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.xml.transform.stream.StreamSource;
 | 
					import javax.xml.transform.stream.StreamSource;
 | 
				
			||||||
import java.io.StringReader;
 | 
					import java.io.StringReader;
 | 
				
			||||||
import java.io.StringWriter;
 | 
					import java.io.StringWriter;
 | 
				
			||||||
@@ -11,6 +14,8 @@ import java.io.StringWriter;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
public class Saxon {
 | 
					public class Saxon {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final Logger LOG = LogManager.getLogger("Saxon");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Transforms string containing xml document via xslt
 | 
					     * Transforms string containing xml document via xslt
 | 
				
			||||||
     * @param data xml to be transformed
 | 
					     * @param data xml to be transformed
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,7 @@
 | 
				
			|||||||
package com.r11.tools.xslt.processors;
 | 
					package com.r11.tools.xslt.processors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.LogManager;
 | 
				
			||||||
 | 
					import org.apache.logging.log4j.Logger;
 | 
				
			||||||
import org.w3c.dom.Document;
 | 
					import org.w3c.dom.Document;
 | 
				
			||||||
import org.xml.sax.InputSource;
 | 
					import org.xml.sax.InputSource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -25,6 +27,9 @@ import java.io.StringWriter;
 | 
				
			|||||||
 * @author Wojciech Czop
 | 
					 * @author Wojciech Czop
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class Xalan {
 | 
					public class Xalan {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final Logger LOG = LogManager.getLogger("Xalan");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Transforms string containing xml document via xslt
 | 
					     * Transforms string containing xml document via xslt
 | 
				
			||||||
     * @param data xml to be transformed
 | 
					     * @param data xml to be transformed
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								Backend/xslt-rest/src/main/resources/log4j2.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								Backend/xslt-rest/src/main/resources/log4j2.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<Configuration status="WARN">
 | 
				
			||||||
 | 
						<Appenders>
 | 
				
			||||||
 | 
							<Console name="Console" target="SYSTEM_OUT">
 | 
				
			||||||
 | 
								<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level - %msg%n"/>
 | 
				
			||||||
 | 
							</Console>
 | 
				
			||||||
 | 
							<File name="File" fileName="/tmp/log4j2.log" append="true">
 | 
				
			||||||
 | 
								<PatternLayout>
 | 
				
			||||||
 | 
									<Pattern>%d{HH:mm:ss.SSS} [%t] %-5level - %msg%n</Pattern>
 | 
				
			||||||
 | 
								</PatternLayout>
 | 
				
			||||||
 | 
							</File>
 | 
				
			||||||
 | 
						</Appenders>
 | 
				
			||||||
 | 
						<Loggers>
 | 
				
			||||||
 | 
							<Logger name="com.r11.tools.xslt.SparkInitializer" level="info" additivity="true">
 | 
				
			||||||
 | 
								<AppenderRef ref="Console"/>
 | 
				
			||||||
 | 
							</Logger>
 | 
				
			||||||
 | 
							<Root level="info">
 | 
				
			||||||
 | 
								<AppenderRef ref="File"/>
 | 
				
			||||||
 | 
							</Root>
 | 
				
			||||||
 | 
						</Loggers>
 | 
				
			||||||
 | 
					</Configuration>
 | 
				
			||||||
		Reference in New Issue
	
	Block a user