Xstream seems like not supporting namespace . Is there a solution without changing core code ? just by passing attribute

StackOverflow https://stackoverflow.com/questions/18051408

Question

I am writing a nexus oss plugin . My server gives a rest request to this nexus oss app for which the nexus oss sends a response. But as I suggested in Empty uri in rest response , it throws an error as suggested there.Thanks to @Blaise Doughan . So the answerer @Blaise Doughan suggested to make package name that goes with the response to match package name that is there in the server . So I did that .So this solved a potential problem that would come in future (package name problem). But still it throws the same error .

So to debug I took some other app (that uses "apache cxf") for which the server doesn't throw such errors .I found that the xml response was

<ns2:com.collabnet.teamforge.ia.GetConfigurationParametersResponse
 xmlns:ns2="http://www.collab.net/teamforge/integratedapp"/>

But In case of my app(which make server throw an error) the response is

<com.collabnet.teamforge.ia.GetConfigurationParametersResponse/>

So only potential difference I found among these responses is the namespace "http://www.collab.net/teamforge/integratedapp" . In the linked answer @Blaise Doughan suggested that the response seems be from xstream . Then I later confirmed that the nexus oss internally uses xstream.

So here comes the problem .In xstream website I found this Note :

Why does XStream not have any namespace support?

Not every XML parser supports namespaces and not every XML parser that supports namespaces can be configured within XStream to use those. Basically namespaces must be supported individually for the different XML parsers and the only support for namespaces that has currently been implemented in XStream is for the StAX paser. Therefore use and configure the StaxDriver of XStream to use namespaces.

This gives me a sense that xstream doesn't support namespaces , so it doesn't send namespace in the response . So my server want's uri set with namespace "http://www.collab.net/teamforge/integratedapp" . But nexus oss which uses xstream will not send namespace in response .

Question 1: I don't believe a plugin will be given so much power to configure drivers(StaxDriver) as suggested in the note . This is based on my code walkthrough of nexus oss .So is there any other way to do this from plugin itself ?

Question 2: If there is no solution for question 1 , does this suggest that I will have to tweak nexus oss code ? to make default namespace as suggested in http://blog.bdoughan.com/2010/10/how-does-jaxb-compare-to-xstream.html under the heading "Applying Namespaces" . Is this the final solution ? Because make changes in the core nexus oss is not advisable as it becomes a problem while nexus oss upgrade .

Question 3: Even if balise's way of invoking staxDriver is suggested as a solution ,the problem is that my nexus oss internally uses XppDriver

nexus restlet plugin

nexus client core xstream

So as the app internally uses only XppDriver , is it possibile for me to apply what blaise has said in his blog ?. Because Blaise uses StaxDriver in that blog to set name space(and he adds that only StaxDriver allows this namespace setting and also the official xstream note mentioned above under "Why does XStream not have any namespace support?" topic confirms that ).

Please help.

Thanks

Was it helpful?

Solution

You could fake out XStream by adding a field called xmlns to hold the namespace

@XStreamAsAttribute
private String xmlns = "http://www.collab.net/teamforge/integratedapp";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top