-
Notifications
You must be signed in to change notification settings - Fork 24
modified JaxpRequest and JaxpResponse's load method #7
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this is protected ? |
||
| } | ||
|
|
||
|
|
@@ -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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont need all this just do this for both request and respone in a singleton class and reuse as required.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do this, jaxbContext will be initialized at application boot time no matter user need to use load method or not. Put it into the load method essentially lazy load it to save some memory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's ok, it is a trade off better than having two places with synchronized block. You need it anyhow definitely.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel it's good, we use the JaxpResponse to load XACML response string to an Response object and we construct the ResponseType object by our own unmarshal code. So it make sense to use the class without using it's own load method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is your own unmarshal code ? it is being performed here inside the response/request class. I totally see scalability issue in this patch and not comfortable in giving thumbs up, What you need is single instance of context (which is a good thought) but in code you are doing it at two different places pretty much in a similar way just flipping class type. If you really need to parameterize class type, again create singleton class and initialize it with custom class type (request or response). But, don't patch or modify existing class with synchronized block. IMHO, we should avoid synchronization, whenever possible and have things thread local and immutable. |
||
| synchronized (JaxpRequest.class) { | ||
| if(context == null) { | ||
| context = JAXBContext.newInstance(ResponseType.class); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Unmarshaller unmarshaller = context.createUnmarshaller(); | ||
| JAXBElement<ResponseType> jaxbElementResponse = unmarshaller.unmarshal(nodeRoot, | ||
| ResponseType.class); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you are breaking DRY principle, again -1 for that. Thing, again to make it better, separate class is always a good option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come? The two
contextin JaxpRequest nad JaxpResponse are different.