Hello,
Apologies if this is a double-post..
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 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.
Any ideas?
Thanks
Murali
PS: Details below
Exception
----------
javax.ws.rs.WebApplicationException:
org.jvnet.mimepull.MIMEParsingException: Missing start boundary
at
com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiP
artReaderClientSide.java:141)
at
com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiP
artReaderClientSide.java:77)
at
com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerReques
t.java:454)
at
com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchPro
vider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
at
com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectabl
eValues(InjectableValuesProvider.java:46)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethod
DispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodD
ispatchProvider.java:138)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethod
DispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDis
patchProvider.java:185)
at
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDisp
atcher.dispatch(ResourceJavaMethodDispatcher.java:70)
at
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRu
le.java:279)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHand
PathRule.java:136)
at
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceC
lassRule.java:86)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHand
PathRule.java:136)
at
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(Roo
tResourceClassesRule.java:74)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleReques
t(WebApplicationImpl.java:1357)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleReques
t(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(ServletCo
ntainer.java:497)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletCo
ntainer.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:
--------
@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());
}