You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Gabo Manuel <km...@solegysystems.com> on 2008/11/11 11:36:58 UTC

[JAX-RS] Receiving NullPointerException instead of namespace error/UnmarshalException

Hi All,

I encountered this by accident. Here is the scenario:

expected payload:
<Account xmlns="http://some.namespace/">
... more here

submitted payload:
<Account xmlns="http://accounts.some.namespace/">
... more details here

On the server side, I see the error as:

javax.xml.bind.UnmarshalException: unexpected element 
(uri:"http://accounts.some.namespace/", local:"Account"). Expected 
elements are <{http://some.namespace/}Account>
        at 
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:603)

However, on the client-side (using http commons client) I receive this 
as response content:
<ns1:XMLFault 
xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring 
xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.lang.NullPointerException</ns1:faultstring></ns1:XMLFault>

As additional info the Account is annotated as follows:

@XmlType(name="Account")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name="Account")
public class WSAccount {

with a class package-info.java annotated as follows:
@javax.xml.bind.annotation.XmlSchema(namespace = 
"http://subscriber.ws.solegy.com/",
                                     elementFormDefault = 
javax.xml.bind.annotation.XmlNsForm.QUALIFIED)

The service implementation is annotated as follows:

@ConsumeMime("*/xml")
@ProduceMime("*/xml")
public class RestAccountService {
    @POST
    @Path("/")
    public int update(
            @Context HttpHeaders header,
            WSAccount account
            ) {
        return 1;
    }
}

The content is the same as captured by tcpmon, so that clears out the 
client api. I am however, unable to trace where the NPE happens. Is 
there something I should set to avoid the NPE?

Gabo

Re: [JAX-RS] Receiving NullPointerException instead of namespace error/UnmarshalException

Posted by Sergey Beryozkin <se...@progress.com>.
Hi Gabo
I'm sorry but I'm not sure what's happening so I can't help at the moment. It's likely coming from a JAXRS code but is it comming 
from a Sun JAXB impl code used by CXF JAXB provider or from CXF JAXRS itself it's not clear. I'm a bit busy at the moment so I don't 
have time to write a test. If you could try to debug it and see where the source is then it'd be cool.

Cheers, Sergey

> Hi All,
>
> I encountered this by accident. Here is the scenario:
>
> expected payload:
> <Account xmlns="http://some.namespace/">
> ... more here
>
> submitted payload:
> <Account xmlns="http://accounts.some.namespace/">
> ... more details here
>
> On the server side, I see the error as:
>
> javax.xml.bind.UnmarshalException: unexpected element (uri:"http://accounts.some.namespace/", local:"Account"). Expected elements 
> are <{http://some.namespace/}Account>
>        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:603)
>
> However, on the client-side (using http commons client) I receive this as response content:
> <ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring 
> xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.lang.NullPointerException</ns1:faultstring></ns1:XMLFault>
>
> As additional info the Account is annotated as follows:
>
> @XmlType(name="Account")
> @XmlAccessorType(XmlAccessType.PROPERTY)
> @XmlRootElement(name="Account")
> public class WSAccount {
>
> with a class package-info.java annotated as follows:
> @javax.xml.bind.annotation.XmlSchema(namespace = "http://subscriber.ws.solegy.com/",
>                                     elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
>
> The service implementation is annotated as follows:
>
> @ConsumeMime("*/xml")
> @ProduceMime("*/xml")
> public class RestAccountService {
>    @POST
>    @Path("/")
>    public int update(
>            @Context HttpHeaders header,
>            WSAccount account
>            ) {
>        return 1;
>    }
> }
>
> The content is the same as captured by tcpmon, so that clears out the client api. I am however, unable to trace where the NPE 
> happens. Is there something I should set to avoid the NPE?
>
> Gabo