users@jersey.java.net

[Jersey] Re: Calling a JBoss resteasy multipart service using the Jersey rest client

From: <andreas.oh_at_codeispoetry.se>
Date: Mon, 21 Jan 2013 09:21:39 +0100

Hi Arul,
Thanks for the reply.
I managed to work around my problem after I found that my local
resteasy test service was working with my original client code.

Somehow creating a new WebResource (which I did in my testcode) and
using that to call the resteasy service completed without problems.
Because the quite expensive construction of the WebResource I had used
the same WebResource to call different rest endpoints with other media
types before this one. This has worked fine up until this call. I
believe (by reading the user guide) this is the recommended strategy for
using the WebResource.

Thanks for your help.
Andreas

On Sat, 19 Jan 2013 21:05:06 -1000, Arul Dhesiaseelan wrote:
> Hi Andreas,
>
> It should work fine as per your approach. I put together a sample app
> in github that works with this scenario [1], you may want to check
> out
> the JerseyClient [2].
>
> What exception you are getting?
>
> -Arul
>
> [1] https://github.com/aruld/jersey-client-jboss-resource [2]
> [2]
>
> https://github.com/aruld/jersey-client-jboss-resource/blob/master/jersey-client/src/main/java/com/aruld/resources/JerseyClient.java
> [3]
>
> On Wed, Jan 16, 2013 at 11:41 PM, wrote:
>
>> Hi,
>> Im currently writing a rest client using Jersey client API and
>> having trouble consuming a rest endpoint written using jboss
>> resteasy framwork. The service is defined something like this:
>>
>> @POST
>> @Consumes(MultipartConstants.MULTIPART_RELATED)
>> @Produces(MediaType.APPLICATION_XML)
>> @Path("user/{user_id}")
>> UserInfoBean addItemFromUri(@XopWithMultipartRelated ItemBeanUri
>> item, @PathParam("user_id") String userId);
>>
>> Im at the moment using jersey-multipart, though I can not find any
>> explicit support for media type multipart/related, but I think my
>> main problem really is the @XopWithMultipartRelated annotation. When
>> I call the service I get a
>> "com.sun.jersey.api.client.ClientHandlerException: java.net
>> [1].SocketTimeoutException: Read timed out". The "time out" appears
>> instantly, which leads me to believe this is not the root cause of
>> the problem. If I omit the boundry header, the service returns with
>> a 500 and a message saying it can not find a bondry token.
>>
>> My approach so far is:
>> //Creating the mediatype with boundry string
>> Map parameters = new HashMap();
>> parameters.put("boundary", "--part_boundry");
>> MediaType mediaType = new MediaType("multipart", "related",
>> parameters);
>>
>> //Building the multipart from respective body parts
>> MultiPart multiPart = new MultiPart(mediaType);
>> BodyPart bp = new BodyPart(itemBean,
>> MediaType.APPLICATION_XML_TYPE);
>> multiPart.bodyPart(bp);
>>
>> //Make the request to the resource
>> UriBuilder uriBuilder =
>> service.getUriBuilder().path("user").path(userId);
>> ClientResponse response = service.uri(uriBuilder.build())
>>         .type(mediaType).post(ClientResponse.class, multiPart);
>> //Throws exception!
>> checkStatusOk(response);
>>
>> I apologize for any errors in the code, Ive modified it slightly to
>> fit as an example.
>>
>> Is there anything fundamentally wrong with my approach? I dont have
>> the ability to modify the jboss service, it is what it is for
>> whatever reason. Has anyone any experience with the jersey client
>> and xop and can point me in the right direction? Ive come the
>> conclusion that xop is something used mostly in soap web services,
>> Im not quite sure why it is used in this context.
>>
>> Ill try to set up a resteasy service loacally so that I can test
>> and verify that xop annotation but Ill be glad for any advice.
>>
>> Im currently using jersey 1.13 and is somewhat stuck with that
>> version for this project.
>>
>> Regards
>> Andreas
>
>
>
> Links:
> ------
> [1] http://java.net
> [2] https://github.com/aruld/jersey-client-jboss-resource
> [3]
>
> https://github.com/aruld/jersey-client-jboss-resource/blob/master/jersey-client/src/main/java/com/aruld/resources/JerseyClient.java
> [4] mailto:andreas.oh_at_codeispoetry.se