Skip to main content

How to add missing namespace information?

2 replies [Last post]
tahicks
Offline
Joined: 2009-04-03

In response to the invocation of a web service I'm getting a return that has the namespace missing from the "payload" of the SOAP message. This detail throws the JAXB unmarshaller off when it tries to convert the XML to a JAXB bound class.

To illustrate (The OverlayFileList tag is the one that is incorrect):

Should be: (The element needing fixing is OverlayFileList, which is missing namespace information)



I have a class that implements the SOAPHandler interface wherein I have tried many things to attempt to modify the message prior to unmarshalling so that JAXB does the right thing, but none of my attempts have been successful. The things I've tried are rather numerous so I'm reluctant to post them, but will if additional details are desired.

As a quick aside, I've even tried (successfully) modifying a copy of the SOAPMessage to include the missing namespace and tried to get JAXB to unmarshall the body, but approach this fails as well.

Any help would be most appreciated.
-Troy

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ratoo
Offline
Joined: 2007-08-27

You can do it using a filter:

[code]
public class TemplateFilter extends XMLFilterImpl
{
public TemplateFilter(XMLReader reader)
{
super(reader);
}

@Override
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
{
}
[/code]

Here in a startElement() method you can add/change your namespace.

Then you can use this filter with a JAXBSource like:

[code]
XMLReader reader = jaxbSource.getXMLReader();
TemplateFilter filter = new TemplateFilter(reader);
InputSource inputSource = jaxbSource.getInputSource();
SAXSource saxSource = new SAXSource(filter, inputSource);
[/code]

And use JAXB Unmarshaller with this saxSource object

Cheers,

D.

abc2009
Offline
Joined: 2009-09-22

The best easy way is to refer the guides on namespace or just search with goolge,yahoo, etc.

http://www.sharewareguides.com/ includes "software development", maybe you can find some guide books there.

Good luck.