users@jersey.java.net

[Jersey] Re: UnmarshalException with Client API

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Fri, 8 Mar 2013 19:14:39 +0100

On Mar 7, 2013, at 5:02 PM, Arun Gupta <Arun.p.Gupta_at_oracle.COM> wrote:

> 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 ?

That does not sound probable. Are you sure that what you are saying conforms to the observed behavior? Do you have a reproducible test case?

> - I had to specify the type as Movie instead of Movie[]. My mistake, but the error was quite meaningless IMHO :-)

Please file a RFE. I'm not sure how much we can do here, but at least we can try... :)

Marek

>
> 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
>