users@jersey.java.net

Re: [Jersey] Post entity with Webresource

From: Naresh <Srinivas.Bhimisetty_at_Sun.COM>
Date: Fri, 11 Sep 2009 16:15:02 +0530

I'm assuming that you have annotated service.PermitConverter with JAXB
annotations.
If not, can you try that.

Note that, its a requirement to annotate the entity class with JAXB
annotations to produce XML/JSON response.

-Naresh

xworker wrote:
> backend resource:
>
> @POST
> @Consumes({"application/xml", "application/json"})
> public Response post(PermitConverter data) {
> PersistenceService persistenceSvc =
> PersistenceService.getInstance();
> try {
> persistenceSvc.beginTx();
> EntityManager em = persistenceSvc.getEntityManager();
> Permit entity = data.resolveEntity(em);
> createEntity(data.resolveEntity(em));
> persistenceSvc.commitTx();
> return
> Response.created(uriInfo.getAbsolutePath().resolve(entity.getPermitId() +
> "/")).build();
> } finally {
> persistenceSvc.close();
> }
> }
>
> Client: (JSF backingbean)
>
> PermitConverter p = new PermitConverter();
> p.setPermitName("test");
>
>
> wr =
> client.resource("http://localhost:8080/permit-backend/resources/permits");
> wr.type("application/xml").post(new
> GenericType<PermitConverter>(){}, p);
>
>
> The problem now is that there is no MessageBody writer. The arrayindex
> problem went away when I set the type("application/xml"). Feels like I
> missed a step somewhere with the messageBodyWriter...
>
> 31:04,861 ERROR [application]
> com.sun.jersey.api.client.ClientHandlerException:
> com.sun.jersey.api.client.ClientHandlerException: A message body wr
> r for Java type, class service.PermitConverter, and MIME media type,
> application/xml, was not found
> ax.faces.el.EvaluationException:
> com.sun.jersey.api.client.ClientHandlerException:
> com.sun.jersey.api.client.ClientHandlerException: A message body
> iter for Java type, class service.PermitConverter, and MIME media type,
> application/xml, was not found
>
>
>
>
>
>
> Naresh-11 wrote:
>
>> Hi,
>>
>> could you please send more details, like the full exception stack
>> trace?
>> A reproducible sample would be helpful too (if possible).
>>
>> -Naresh
>>
>>
>> xworker wrote:
>>
>>> Hi
>>>
>>> Tried that. Like this:
>>>
>>> PermitConverter p = new PermitConverter();
>>> p.setPermitName("test");
>>>
>>>
>>> wr =
>>> client.resource("http://localhost:8080/permit-backend/resources/permits");
>>> wr.post(new GenericType<PermitConverter>(){}, p);
>>>
>>> Got this exception:
>>> javax.faces.el.EvaluationException:
>>> com.sun.jersey.api.client.ClientHandlerException:
>>> java.lang.IndexOutOfBoundsException: Index: 0, Size:0
>>>
>>>
>>> Naresh-11 wrote:
>>>
>>>
>>>> Hi,
>>>>
>>>> xworker wrote:
>>>>
>>>>
>>>>> Hi
>>>>>
>>>>> Im trying to do a simple post with an entity from my backingbean to my
>>>>> REST
>>>>> ws service.
>>>>>
>>>>> Something like this:
>>>>>
>>>>> webresource.post(ClientResponse.class, myEntity);
>>>>>
>>>>> Whats the correct way of doing this?
>>>>>
>>>>>
>>>> you can definitely do it this way.
>>>>
>>>>
>>>>> All the examples I've seen just send
>>>>> strings and not entitys.
>>>>>
>>>>>
>>>>>
>>>> Please refer the JAXB sample's [1] MainTest class. Most of the test
>>>> methods of this test class, use post() method for actually POSTing
>>>> entities.
>>>>
>>>> [1]
>>>> http://download.java.net/maven/2/com/sun/jersey/samples/jaxb/1.1.3-ea-SNAPSHOT/jaxb-1.1.3-ea-SNAPSHOT-project.zip
>>>>
>>>> -Naresh
>>>>
>>>>
>>>>> /xw
>>>>>
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>>
>
>