users@jersey.java.net

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

From: <andreas.oh_at_codeispoetry.se>
Date: Thu, 17 Jan 2013 10:41:44 +0100

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