users@jersey.java.net

[Jersey] Re: UnmarshalException with Client API

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Thu, 07 Mar 2013 16:02:47 +0000

Figured out ...

I need to create the request as:

client.target("http://"
                     + request.getServerName()
                     + ":"
                     + request.getServerPort()
                     + request.getContextPath()
                     + "/webresources/movie")
                     .path("{movie}")
                     .resolveTemplate("movie", id)
                     .request()
                     .get(Movie.class);

Two differences here ...

- Seems like I cannot specify the variable part of the URI in
target(...) and have to use the builder path(...) for that. Why ?
- I had to specify the type as Movie instead of Movie[]. My mistake, but
the error was quite meaningless IMHO :-)

Arun

On 3/7/13 3:35 PM, Arun Gupta wrote:
> I have a REST endpoint that can be accessed as:
>
> http://localhost:8080/movieplex7/webresources/movie/1
>
> with no exceptions in GlassFish 4, b78.
>
> However when this endpoint is accessed using Client API as:
>
> Client client = ClientBuilder.newClient();
> Movie[] movies = client.target("http://"
> + request.getServerName()
> + ":"
> + request.getServerPort()
> + request.getContextPath()
> + "/webresources/movie/{id}")
> .resolveTemplate("id", id)
> .request()
> .get(Movie[].class);
>
> then it throws an error:
>
> Caused by: javax.xml.bind.UnmarshalException
> - with linked exception:
> [com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 63;
> unexpected element (uri:"", local:"actors"). Expected elements are
> <{}movie>]
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:435)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:372)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:342)
> at
> org.glassfish.jersey.message.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:353)
> ... 49 more
>
> If no template is specified then the Client API behaves as expected as
> well.
>
> Any thoughts ?
>
> Arun
>

-- 
http://twitter.com/arungupta
http://blogs.oracle.com/arungupta