users@jersey.java.net

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

From: Arul Dhesiaseelan <aruld_at_acm.org>
Date: Sat, 19 Jan 2013 21:05:06 -1000

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]
https://github.com/aruld/jersey-client-jboss-resource/blob/master/jersey-client/src/main/java/com/aruld/resources/JerseyClient.java

On Wed, Jan 16, 2013 at 11:41 PM, <andreas.oh_at_codeispoetry.se> wrote:

> Hi,
> I'm 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);
>
> I'm 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 '_at_XopWithMultipartRelated' annotation. When I call
> the service I get a "com.sun.jersey.api.client.**ClientHandlerException:
> java.net.**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<String, String> parameters = new HashMap<String, String>();
> 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, I've modified it slightly to fit
> as an example.
>
> Is there anything fundamentally wrong with my approach? I don't 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? I've come the conclusion that xop is something used
> mostly in soap web services, I'm not quite sure why it is used in this
> context.
>
> I'll try to set up a resteasy service loacally so that I can test and
> verify that xop annotation but I'll be glad for any advice.
>
> I'm currently using jersey 1.13 and is somewhat stuck with that version
> for this project.
>
> Regards
> Andreas
>
>