From 6d3b9e15ab25dbbbc30476dc556409f34dc75149 Mon Sep 17 00:00:00 2001 From: Duan Shiqiang Date: Thu, 20 Oct 2016 17:32:24 +0800 Subject: [PATCH 1/2] modified JaxpRequest and JaxpResponse's load method --- .../openaz/xacml/std/jaxp/JaxpRequest.java | 29 ++++++++++--------- .../openaz/xacml/std/jaxp/JaxpResponse.java | 29 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java index a010c9c..769ebea 100644 --- a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java +++ b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java @@ -51,7 +51,6 @@ import org.apache.openaz.xacml.std.dom.DOMUtil; import org.w3c.dom.Document; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** @@ -60,6 +59,16 @@ */ public class JaxpRequest extends StdMutableRequest { private static Log logger = LogFactory.getLog(JaxpRequest.class); + + private static JAXBContext context = null; + + private static void init() throws JAXBException { + synchronized (JaxpRequest.class) { + if(context == null) { + context = JAXBContext.newInstance(RequestType.class); + } + } + } public JaxpRequest() { } @@ -114,19 +123,13 @@ public static JaxpRequest load(File fileXmlRequest) throws ParserConfigurationEx logger.error("No Document returned parsing \"" + fileXmlRequest.getAbsolutePath() + "\""); return null; } - - NodeList nodeListRoot = document.getChildNodes(); - if (nodeListRoot == null || nodeListRoot.getLength() == 0) { - logger.warn("No child elements of the XML document"); - return null; + + Node nodeRoot = document.getDocumentElement(); + + if(context == null) { + init(); } - Node nodeRoot = nodeListRoot.item(0); - if (nodeRoot == null || nodeRoot.getNodeType() != Node.ELEMENT_NODE) { - logger.warn("Root of the document is not an ELEMENT"); - return null; - } - - JAXBContext context = JAXBContext.newInstance(RequestType.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement jaxbElementRequest = unmarshaller.unmarshal(nodeRoot, RequestType.class); diff --git a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java index 651b425..7ba597c 100644 --- a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java +++ b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java @@ -50,7 +50,6 @@ import org.apache.openaz.xacml.std.dom.DOMUtil; import org.w3c.dom.Document; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** @@ -59,7 +58,17 @@ */ public class JaxpResponse extends StdMutableResponse { private static Log logger = LogFactory.getLog(JaxpResponse.class); - + + private static JAXBContext context = null; + + private static void init() throws JAXBException { + synchronized (JaxpRequest.class) { + if(context == null) { + context = JAXBContext.newInstance(ResponseType.class); + } + } + } + protected JaxpResponse() { } @@ -102,18 +111,12 @@ public static JaxpResponse load(File fileXmlResponse) throws ParserConfiguration return null; } - NodeList nodeListRoot = document.getChildNodes(); - if (nodeListRoot == null || nodeListRoot.getLength() == 0) { - logger.warn("No child elements of the XML document"); - return null; - } - Node nodeRoot = nodeListRoot.item(0); - if (nodeRoot == null || nodeRoot.getNodeType() != Node.ELEMENT_NODE) { - logger.warn("Root of the document is not an ELEMENT"); - return null; - } + Node nodeRoot = document.getDocumentElement(); - JAXBContext context = JAXBContext.newInstance(ResponseType.class); + if(context == null) { + init(); + } + Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement jaxbElementResponse = unmarshaller.unmarshal(nodeRoot, ResponseType.class); From 78b81d31ac0c6bfbcb128b35ed3d846f513f19b4 Mon Sep 17 00:00:00 2001 From: Duan Shiqiang Date: Fri, 21 Oct 2016 11:43:34 +0800 Subject: [PATCH 2/2] removed init method to create the jaxb context object --- .../openaz/xacml/std/jaxp/JaxpRequest.java | 18 +++++++----------- .../openaz/xacml/std/jaxp/JaxpResponse.java | 14 +++++--------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java index 769ebea..931d04d 100644 --- a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java +++ b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpRequest.java @@ -60,16 +60,8 @@ public class JaxpRequest extends StdMutableRequest { private static Log logger = LogFactory.getLog(JaxpRequest.class); - private static JAXBContext context = null; - - private static void init() throws JAXBException { - synchronized (JaxpRequest.class) { - if(context == null) { - context = JAXBContext.newInstance(RequestType.class); - } - } - } - + private static JAXBContext context = null; + public JaxpRequest() { } @@ -127,7 +119,11 @@ public static JaxpRequest load(File fileXmlRequest) throws ParserConfigurationEx Node nodeRoot = document.getDocumentElement(); if(context == null) { - init(); + synchronized (JaxpRequest.class) { + if(context == null) { + context = JAXBContext.newInstance(RequestType.class); + } + } } Unmarshaller unmarshaller = context.createUnmarshaller(); diff --git a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java index 7ba597c..86dd621 100644 --- a/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java +++ b/openaz-xacml/src/main/java/org/apache/openaz/xacml/std/jaxp/JaxpResponse.java @@ -61,14 +61,6 @@ public class JaxpResponse extends StdMutableResponse { private static JAXBContext context = null; - private static void init() throws JAXBException { - synchronized (JaxpRequest.class) { - if(context == null) { - context = JAXBContext.newInstance(ResponseType.class); - } - } - } - protected JaxpResponse() { } @@ -114,7 +106,11 @@ public static JaxpResponse load(File fileXmlResponse) throws ParserConfiguration Node nodeRoot = document.getDocumentElement(); if(context == null) { - init(); + synchronized (JaxpRequest.class) { + if(context == null) { + context = JAXBContext.newInstance(ResponseType.class); + } + } } Unmarshaller unmarshaller = context.createUnmarshaller();