Hello,
I'm encountering the following exception in Jersey when sending a HTTP POST
request with multipart/mixed content using the CXF client api.
The same request succeeds when handled through CXF itself on the server side
(i.e. the method annotated with @POST with cxf MultipartBody is called
and the attachments can be accessed).
I'm not sure if this is an error on the receiving side (Jersey) or how the cxf
client is sending the request. I thought I would
check here since cxf<->cxf scenario is working and cxf<->jersey is failing.
More details below. Any ideas?
Thanks
Murali
Exception
----------
javax.ws.rs.WebApplicationException: org.jvnet.mimepull.MIMEParsingException:
Missing start boundary
at
com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:141)
at
com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:77)
at
com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:454)
at
com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
at
com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:138)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
at
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
at
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
at
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1357)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1289)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
Client Request (captured thro' tcpmon)
---------
POST /jersey/attachJersey HTTP/1.1
Content-Type: multipart/mixed; type="*/*";
boundary="uuid:e24ae09c-03d3-4cfb-a276-957cf9ce3209"; start="<root>";
start-info="*/*"
Accept: multipart/mixed
User-Agent: Apache CXF 2.3.1
Cache-Control: no-cache
Pragma: no-cache
Host: 127.0.0.1:9999
Connection: keep-alive
Content-Length: 338
--uuid:e24ae09c-03d3-4cfb-a276-957cf9ce3209
Content-Type: */*
Content-Transfer-Encoding: binary
Content-ID: <root>Root
msg--uuid:e24ae09c-03d3-4cfb-a276-957cf9ce3209Content-Type:
text/plainContent-Transfer-Encoding: binaryContent-ID:
<file1>This content is from
test.txt--uuid:e24ae09c-03d3-4cfb-a276-957cf9ce3209--
Server resource handling code: (not invoked; fails within jersey)
--------
@POST
@Consumes("multipart/mixed")
@Path("/attachJersey")
public Response addAttachmentsUsingJersey(MultiPart multiPart) {
List<BodyPart> bodyParts = multiPart.getBodyParts();
for (BodyPart bodyPart : bodyParts) {
Object entity = bodyPart.getEntity();
System.out.println("Got part with entity: " + entity);
}
return Response.ok("Processed attachments using Jersey").build();
}
Client code sending the request:
--------
@Test
public void testCxfWebClientMultiPart() throws Exception {
WebClient client =
WebClient.create("
http://localhost:9999/jersey/attachJersey");
client.type("multipart/mixed").accept("multipart/mixed");
List<org.apache.cxf.jaxrs.ext.multipart.Attachment> atts =
new LinkedList<org.apache.cxf.jaxrs.ext.multipart.Attachment>();
atts.add(new org.apache.cxf.jaxrs.ext.multipart.Attachment("root",
"*/*", "Root msg"));
DataHandler dh = new DataHandler(new URL("file:///D:\\temp\\test.txt"));
atts.add(new org.apache.cxf.jaxrs.ext.multipart.Attachment("file1", dh,
null));
Response response = client.post(atts);
System.out.println("Response status = " + response.getStatus());
}