spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

ben_rr
This post was updated on .
I have this problem when use spring-ws component as a web service client. It happens when payload of web service response has namespace prefix in attribute value.

my route looks like,

from("direct:callWebService").marshall(jaxbDataFormat).to("spring-ws:someServer?soapAction=someAction").unmarshall(jaxbDataFormat)

I can see the web service has been called successfully from the server side and response returned as well.
But when the payload has namespace prefix in attribute value I have an unmarshall problem.

exception in log,

hangeId: ID-MELWKS-0433-64949-1337140734480-0-3). Exhausted after delivery attempt: 1 caught: java.lang.IllegalArgumentException: prefix n2 is not bound to a namespace
java.lang.IllegalArgumentException: prefix n2 is not bound to a namespace
        at com.sun.xml.bind.DatatypeConverterImpl._parseQName(DatatypeConverterImpl.java:385)
        at com.sun.xml.bind.v2.runtime.unmarshaller.LeafPropertyXsiLoader.selectLoader(LeafPropertyXsiLoader.java:86)
        at com.sun.xml.bind.v2.runtime.unmarshaller.LeafPropertyXsiLoader.startElement(LeafPropertyXsiLoader.java:69)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:481)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
        at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
        at org.apache.camel.converter.jaxb.JaxbDataFormat.unmarshal(JaxbDataFormat.java:152)



soap response,
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n2="http://www.ben_rr.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <n:loginResponse xmlns:n="http://www.ben_rr.com/">
         <n:Result xsi:type="n2:LoginResp">
            <header xsi:type="n2:APIResponseHeader">
               <errorCode xsi:type="n2:APIErrorEnum">OK</errorCode>
               <timestamp xsi:type="xsd:dateTime">2012-05-16T03:57:03.782Z</timestamp>
            </header>
            <errorCode xsi:type="n2:LoginErrorEnum">OK</errorCode>
            <minorErrorCode xsi:nil="1"/>
            <validUntil xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</validUntil>
         </n:Result>
      </n:loginResponse>
   </soap:Body>
</soap:Envelope>

Similar issue opened on spring-ws and xmlBeans
https://jira.springsource.org/browse/SWS-523
and
https://issues.apache.org/jira/browse/XMLBEANS-427

but I still dont have a solution for this.

Please help.
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

Richard Kettelerij
Hi,

Use the JAXB NamespacePrefixMapper to customize the prefux. See http://camel.apache.org/jaxb.html and the following post on the mailing list: http://camel.465427.n5.nabble.com/camel-jaxb-namespace-prefix-td5685354.html.

Btw, why are you referring to XMLBeans in the last part of your post when you're using JAXB?

Regards,
Richard
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

Richard Kettelerij
In reply to this post by ben_rr
Also can you post your package-info.java file? You need that when binding the namespace (prefix). Especially note the @XmlNs annotation.
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

ben_rr
In reply to this post by Richard Kettelerij
Hi Richard

Thanks for the quick reply. I copied the xmlBean url twice and now changed the URL to Spring web service ticket. The xmlBean ticket mentioned in the spring web service one so I paste it here.

Anyway, please correct me if I am wrong. I don't think adding prefix mapper will fix my problem. In my case I am only use camel spring-ws and jaxb as web service client. What returned from the server is out of my control. I only want the unmarshaller to pick up the namespace prefix from the soap Envelope.

example,
xmlns:n2="http://www.ben_rr.com" in the soap response

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n2="http://www.ben_rr.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <n:loginResponse xmlns:n="http://www.ben_rr.com/">
         <n:Result xsi:type="n2:LoginResp">
            <header xsi:type="n2:APIResponseHeader">
               <errorCode xsi:type="n2:APIErrorEnum">OK</errorCode>
               <timestamp xsi:type="xsd:dateTime">2012-05-16T03:57:03.782Z</timestamp>
            </header>
            <errorCode xsi:type="n2:LoginErrorEnum">OK</errorCode>
            <minorErrorCode xsi:nil="1"/>
            <validUntil xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</validUntil>
         </n:Result>
      </n:loginResponse>
   </soap:Body>
</soap:Envelope>
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

Christian Mueller
Administrator
In reply to this post by Richard Kettelerij
I removed the NamespacePrefixMapper because there is a standard way in JAXB
to customize the namespace:
http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/XmlSchema.html

Best,
Christian

On Wed, May 16, 2012 at 7:28 AM, Richard Kettelerij <
[hidden email]> wrote:

> Hi,
>
> Use the JAXB NamespacePrefixMapper to customize the prefux. See
> http://camel.apache.org/jaxb.html and the following post on the mailing
> list:
>
> http://camel.465427.n5.nabble.com/camel-jaxb-namespace-prefix-td5685354.html
> .
>
> Btw, why are you referring to XMLBeans in the last part of your post when
> you're using JAXB?
>
> Regards,
> Richard
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/spring-ws-component-unmarshall-Jaxb-problem-when-Payload-namespace-prefix-in-attribute-value-tp5710538p5710553.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

Babak Vahdat
Hi Christian,

Shouldn't the changes on the Wiki be removed as well?

http://camel.apache.org/jaxb.html#JAXB-UsingacustomNamespacePrefixMapper

Babak
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

ben_rr
In reply to this post by Christian Mueller
Thanks Christian.

I have checked the JAXB namespace prefix mapping, but in my case I am only the web service client and all jaxb mappings are generated from server wsdl file by wsdl2java. And my problem is not marshalling but unmarshall response from web service server. It is more like a spring-ws camel component problem to me.

From my debugging, around code

org.apache.camel.component.spring.ws.SpringWebserviceProducer.java  line 59
body = endpoint.getConfiguration().getWebServiceTemplate().sendSourceAndReceive(sourcePayload, callback, SOURCE_EXTRACTOR);

When the web service response is

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n2="http://www.ben_rr.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <n:loginResponse xmlns:n="http://www.ben_rr.com/">
         <n:Result xsi:type="n2:LoginResp">
            <header xsi:type="n2:APIResponseHeader">
               <errorCode xsi:type="n2:APIErrorEnum">OK</errorCode>
               <timestamp xsi:type="xsd:dateTime">2012-05-16T03:57:03.782Z</timestamp>
            </header>
            <errorCode xsi:type="n2:LoginErrorEnum">OK</errorCode>
            <minorErrorCode xsi:nil="1"/>
            <validUntil xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</validUntil>
         </n:Result>
      </n:loginResponse>
   </soap:Body>
</soap:Envelope>

The body returned as a DomSource object with only the soap body which starts with node <n:loginResponse>.
The prefix mapping xmlns:n2="http://www.ben_rr.com" on soap envelope is just simply gone then in my camel route an exception "prefix n2 is not bound to a namespace" throw out from  org.apache.camel.converter.jaxb.JaxbDataFormat.unmarshal

Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

ben_rr
In reply to this post by ben_rr
I end up with not using spring-ws or cxf camel component but use JaxWsProxyFactoryBean  from cxf frontend-jaxws to build service bean then make web service call in a camel processor so no need of camel marshal or unmarshal then problem solved which makes me feel more likely it should be spring-ws camel component or jaxb dataformat issue.

Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

Christian Mueller
Administrator
In reply to this post by Babak Vahdat
Thanks for the reminder Babak. Done.

Best,
Christian

On Wed, May 16, 2012 at 9:27 AM, Babak Vahdat
<[hidden email]>wrote:

> Hi Christian,
>
> Shouldn't the changes on the Wiki be removed as well?
>
> http://camel.apache.org/jaxb.html#JAXB-UsingacustomNamespacePrefixMapper
>
> Babak
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/spring-ws-component-unmarshall-Jaxb-problem-when-Payload-namespace-prefix-in-attribute-value-tp5710538p5710599.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

Christian Mueller
Administrator
Ben, is it possible to provide an unit test which show this issue? Than
it's much more easier for us to track down this issue...

Best,
Christian

On Thu, May 17, 2012 at 6:03 PM, Christian Müller <
[hidden email]> wrote:

> Thanks for the reminder Babak. Done.
>
> Best,
> Christian
>
>
> On Wed, May 16, 2012 at 9:27 AM, Babak Vahdat <[hidden email]
> > wrote:
>
>> Hi Christian,
>>
>> Shouldn't the changes on the Wiki be removed as well?
>>
>> http://camel.apache.org/jaxb.html#JAXB-UsingacustomNamespacePrefixMapper
>>
>> Babak
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/spring-ws-component-unmarshall-Jaxb-problem-when-Payload-namespace-prefix-in-attribute-value-tp5710538p5710599.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

ben_rr
Hi Christian

It is a bit hard to create a unit test because to recreate the problem involves a running web service server to return some expected response. Let me see if I can build a small project for this.
Reply | Threaded
Open this post in threaded view
|

Re: spring-ws component unmarshall Jaxb problem when Payload namespace prefix in attribute value

Christian Mueller
Administrator
Please have a look into the unit tests for the camel-spring-ws component
where we do this already.

Best,
Christian

Sent from a mobile device
Am 18.05.2012 01:45 schrieb "ben_rr" <[hidden email]>:

> Hi Christian
>
> It is a bit hard to create a unit test because to recreate the problem
> involves a running web service server to return some expected response. Let
> me see if I can build a small project for this.
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/spring-ws-component-unmarshall-Jaxb-problem-when-Payload-namespace-prefix-in-attribute-value-tp5710538p5711684.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>