You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Julien Charon <Ju...@avitech.aero> on 2015/06/18 12:30:30 UTC

JAX-WS and staxsource binding namespace issue

 Hi,


I used wsdl2java to generate JAX-WS classes from a WSDL using staxsource data binding. When I parse the received XML with the XMLStreamReader from the StaxSource, the namespaces defined in the SOAP part of the message are not available, but I need those because I have to pass the XML to another service.

Examples:
This will work because the namespace is defined in the XML that will be passed to the WebMethod:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
   <soapenv:Header/>
   <soapenv:Body>
      <ns:GetCapabilities service="WFS" xmlns:ns="http://www.opengis.net/wfs/2.0">
      </ns:GetCapabilities>
   </soapenv:Body>
</soapenv:Envelope>

This will not work because the namespace is defined in the SOAP envelope:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opengis.net/wfs/2.0">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:GetCapabilities service="WFS">
      </ns:GetCapabilities>
   </soapenv:Body>
</soapenv:Envelope>

Is there a way to access the namespaces defined in the SOAP envelope without having to parse it myself?


Mit freundlichen Grüßen / With kind regards,
Julien Charon

Avitech GmbH
Engineering AxL
Tel.: +49 (0)7541/282-177
Fax: +49 (0)7541/282-199
e-mail: julien.charon@avitech.aero<ma...@avitech.aero>
________________________________________________
Avitech GmbH
Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany
Court Registration: Amtsgericht Ulm | HRB 728293
Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza
http://avitech.aero<http://avitech.aero/>

This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.


AW: JAX-WS and staxsource binding namespace issue

Posted by Julien Charon <Ju...@avitech.aero>.
I finally wrote an Interceptor that parses the SOAP envelope and extracts namespaces defined there. Then I add the namespaces that are defined in the envelope to the first element of the body content (of course only those, that are not already defined and omitting the SOAP envelope namespace). It's a little bit ugly to manipulate the incoming SOAP message, but it works.
So according to my example, if the client sends

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opengis.net/wfs/2.0">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:GetCapabilities service="WFS"> 
      </ns:GetCapabilities>
   </soapenv:Body>
</soapenv:Envelope>  

the interceptor changes it to

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opengis.net/wfs/2.0">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:GetCapabilities service="WFS" xmlns:ns="http://www.opengis.net/wfs/2.0"> 
      </ns:GetCapabilities>
   </soapenv:Body>
</soapenv:Envelope>  



Mit freundlichen Grüßen / With kind regards,
 
Julien Charon

Avitech GmbH
Engineering AxL
Tel.: +49 (0)7541/282-177
Fax: +49 (0)7541/282-199
e-mail: julien.charon@avitech.aero
________________________________________________
Avitech GmbH
Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany
Court Registration: Amtsgericht Ulm | HRB 728293
Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza
http://avitech.aero

This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.


-----Ursprüngliche Nachricht-----
Von: Daniel Kulp [mailto:dkulp@apache.org] 
Gesendet: Donnerstag, 18. Juni 2015 21:29
An: users@cxf.apache.org; Julien Charon
Betreff: Re: JAX-WS and staxsource binding namespace issue


The XMLStreamReader.getNamespaceContext() context should have a context that has all the namespaces declared.   Thus, if you need to map a prefix or similar, you should be able to use that.   However, you cannot "grab" the namespaces and copy them or anything.  :(

With 3.1.1, you can set the property "org.apache.cxf.binding.soap.addNamespaceContext" to true on the endpoint and then we'll record the various namespaces in a map and set them on the message with the "soap.body.ns.context" property.   


Dan



> On Jun 18, 2015, at 6:30 AM, Julien Charon <Ju...@avitech.aero> wrote:
> 
> Hi,
> 
> 
> I used wsdl2java to generate JAX-WS classes from a WSDL using staxsource data binding. When I parse the received XML with the XMLStreamReader from the StaxSource, the namespaces defined in the SOAP part of the message are not available, but I need those because I have to pass the XML to another service.
> 
> Examples:
> This will work because the namespace is defined in the XML that will be passed to the WebMethod:
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
>   <soapenv:Header/>
>   <soapenv:Body>
>      <ns:GetCapabilities service="WFS" xmlns:ns="http://www.opengis.net/wfs/2.0">
>      </ns:GetCapabilities>
>   </soapenv:Body>
> </soapenv:Envelope>
> 
> This will not work because the namespace is defined in the SOAP envelope:
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opengis.net/wfs/2.0">
>   <soapenv:Header/>
>   <soapenv:Body>
>      <ns:GetCapabilities service="WFS">
>      </ns:GetCapabilities>
>   </soapenv:Body>
> </soapenv:Envelope>
> 
> Is there a way to access the namespaces defined in the SOAP envelope without having to parse it myself?
> 
> 
> Mit freundlichen Grüßen / With kind regards, Julien Charon
> 
> Avitech GmbH
> Engineering AxL
> Tel.: +49 (0)7541/282-177
> Fax: +49 (0)7541/282-199
> e-mail: julien.charon@avitech.aero<ma...@avitech.aero>
> ________________________________________________
> Avitech GmbH
> Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany 
> Court Registration: Amtsgericht Ulm | HRB 728293 
> Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza 
> http://avitech.aero<http://avitech.aero/>
> 
> This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.
> 

--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog Talend Community Coder - http://coders.talend.com


Re: JAX-WS and staxsource binding namespace issue

Posted by Daniel Kulp <dk...@apache.org>.
The XMLStreamReader.getNamespaceContext() context should have a context that has all the namespaces declared.   Thus, if you need to map a prefix or similar, you should be able to use that.   However, you cannot “grab” the namespaces and copy them or anything.  :(

With 3.1.1, you can set the property “org.apache.cxf.binding.soap.addNamespaceContext" to true on the endpoint and then we’ll record the various namespaces in a map and set them on the message with the “soap.body.ns.context” property.   


Dan



> On Jun 18, 2015, at 6:30 AM, Julien Charon <Ju...@avitech.aero> wrote:
> 
> Hi,
> 
> 
> I used wsdl2java to generate JAX-WS classes from a WSDL using staxsource data binding. When I parse the received XML with the XMLStreamReader from the StaxSource, the namespaces defined in the SOAP part of the message are not available, but I need those because I have to pass the XML to another service.
> 
> Examples:
> This will work because the namespace is defined in the XML that will be passed to the WebMethod:
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
>   <soapenv:Header/>
>   <soapenv:Body>
>      <ns:GetCapabilities service="WFS" xmlns:ns="http://www.opengis.net/wfs/2.0">
>      </ns:GetCapabilities>
>   </soapenv:Body>
> </soapenv:Envelope>
> 
> This will not work because the namespace is defined in the SOAP envelope:
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opengis.net/wfs/2.0">
>   <soapenv:Header/>
>   <soapenv:Body>
>      <ns:GetCapabilities service="WFS">
>      </ns:GetCapabilities>
>   </soapenv:Body>
> </soapenv:Envelope>
> 
> Is there a way to access the namespaces defined in the SOAP envelope without having to parse it myself?
> 
> 
> Mit freundlichen Grüßen / With kind regards,
> Julien Charon
> 
> Avitech GmbH
> Engineering AxL
> Tel.: +49 (0)7541/282-177
> Fax: +49 (0)7541/282-199
> e-mail: julien.charon@avitech.aero<ma...@avitech.aero>
> ________________________________________________
> Avitech GmbH
> Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany
> Court Registration: Amtsgericht Ulm | HRB 728293
> Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza
> http://avitech.aero<http://avitech.aero/>
> 
> This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.
> 

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com