This may be more of a JAXB question, but I'm using CXF to send the serialized
XML and I'm trying to use AbstractPhaseInterceptor<SoapMessage> to fix this
issue so I though I'd ask here. Basically, I'm working with a server I have
no control over and the data it expects to be sent is almost identical to
the response except that it must have a blank namespace. Now, I'm not using
CXF to generate anything except the SOAP service and port classes from the
given WSDLs. The WSDLs have <xsd:any /> tags for their messages, so the data
that gets sent is really up to me and not the schema. I've created several
annotated Java classes and I'm marshalling/unmarshalling them with JAXB, but
because of the tiny, tiny difference between the XML, I can't use the same
annotated Java classes for both replies and requests. I figured it would be
easiest if I just annotated my classes to have no namespaces and find some
way of stripping the server responses of their namespaces; in essence, I
need an XML message sent from the server via SOAP, which looks something
like this:

        <ServerResponse xmlns="http://some.namespace.com/";>
               <Entries>
                     <Entry id="test1" firstName="Test1" lastName="User" >
                           <Address />
                     </Entry>
                     <Entry id="test2" firstName="Test2" lastName="User" >
                           <Address />
                     </Entry>
               </Entries>
        </ServerResponse>

transformed into this for unmarshalling:

        <ServerResponse xmlns="">
               <Entries>
                     <Entry id="test1" firstName="Test1" lastName="User" >
                           <Address />
                     </Entry>
                     <Entry id="test2" firstName="Test2" lastName="User" >
                           <Address />
                     </Entry>
               </Entries>
        </ServerResponse>
                
I've been trying to use the AbstractPhaseInterceptor<SoapMessage> method of
getting to the XML content of the message sent FROM the server, but changing
the "xmlns" attribute to be blank seems to have no effect. After my
interceptor blanks the namespace attribute, I still get a JAXB exception
like this:

Unmarshalling Error : unexpected element (uri:"http://some.namespace.com/";,
local:"Entries").
Expected elements are <{}Entries>

Here's the handleMessage() method in my interceptor, and as you can see from
the debug code, I know it's being hit:

        public void handleMessage(SoapMessage message) {
                SOAPMessage sm = message.getContent(SOAPMessage.class);
                try {
                        if (sm != null) {
                                System.out.println("*********************");
                                SOAPBody sb = sm.getSOAPBody();
                                NodeList nlist = sb.getChildNodes();
                                for (int i = 0; i < nlist.getLength(); i++) {
                                        Node tag = nlist.item(i);
                                        if (tag.getLocalName() != null) {
                                                
System.out.println(tag.getLocalName());
                                                NamedNodeMap nmap = 
tag.getAttributes();
                                                
if(nmap.getNamedItem("xmlns")!=null){
                                                        
System.out.println("found namespace attr");
                                                        Node ns = 
nmap.getNamedItem("xmlns");
                                                        ns.setNodeValue("");
                                                        nmap.setNamedItem(ns);
                                                }
                                        }
                                }
                                message.setContent(SOAPMessage.class, sm);
                                System.out.println("*********************");
                        }
                        
                } catch (SOAPException e) {
                        throw new Fault(e);
                }
        }

It isn't shown, but I had code in there to make sure that all of the objects
are live references and that the attribute was actually being changed in the
SOAPMessage object. This all leads me to believe that at the point the
SOAPMessage is available, the namespace is already set somewhere else and I
can't get to it. Is there some way to completely remove the namespace off
the <ServerResponse> element and force that change into all of its children
with CXF interceptors (or some other method)?
-- 
View this message in context: 
http://cxf.547215.n5.nabble.com/Removing-namespaces-tp3380211p3380211.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to