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..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 @@ -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,7 +59,9 @@ */ public class JaxpRequest extends StdMutableRequest { private static Log logger = LogFactory.getLog(JaxpRequest.class); - + + private static JAXBContext context = null; + public JaxpRequest() { } @@ -114,19 +115,17 @@ 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 = 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(); + + if(context == null) { + synchronized (JaxpRequest.class) { + if(context == null) { + context = JAXBContext.newInstance(RequestType.class); + } + } } - - 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..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 @@ -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,9 @@ */ public class JaxpResponse extends StdMutableResponse { private static Log logger = LogFactory.getLog(JaxpResponse.class); - + + private static JAXBContext context = null; + protected JaxpResponse() { } @@ -102,18 +103,16 @@ 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) { + synchronized (JaxpRequest.class) { + if(context == null) { + context = JAXBContext.newInstance(ResponseType.class); + } + } + } + Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement jaxbElementResponse = unmarshaller.unmarshal(nodeRoot, ResponseType.class);