users@jersey.java.net

[Jersey] Re: Multipart content interop issue between CXF and Jersey

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 10 Jan 2011 12:05:46 +0100

On Jan 7, 2011, at 3:25 PM, Murali Krishnan wrote:

> Hi Paul,
> Below is the exact bytes captured through tcpmon... I get the same
> error if the content-type is "multipart/form-data" as well...

If possible could you send as a binary attachment, say in a zip file.
Or even better send a maven project that reproduces the error.

I could not reproduce the error when i copied the entity body content
into a file and sent that as a multipart message.

However, i did find another bug in relation to Jersey's encoding of
parameters of media types:

   http://java.net/jira/browse/JERSEY-627

Paul.


> Thanks for your input.
> Murali
>
> ----- begin capture --------
> POST /jersey/attachJersey HTTP/1.1
> Content-Type: multipart/mixed; type="*/*";
> boundary="uuid:d3f4a82e-9719-4c49-967e-d08d0ac94a92";
> start="<root>"; start-info="*/*"
> Accept: application/xml
> 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:d3f4a82e-9719-4c49-967e-d08d0ac94a92
> Content-Type: */*
> Content-Transfer-Encoding: binary
> Content-ID: <root>
>
> Root msg
> --uuid:d3f4a82e-9719-4c49-967e-d08d0ac94a92
> Content-Type: text/plain
> Content-Transfer-Encoding: binary
> Content-ID: <file1>
>
> This content is from test.txt
> --uuid:d3f4a82e-9719-4c49-967e-d08d0ac94a92--
> ----- end capture --------
>
>
> From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
> To: Murali Krishnan <cme_mk_at_yahoo.com>
> Cc: users_at_jersey.java.net
> Sent: Fri, January 7, 2011 3:45:45 AM
> Subject: Re: [Jersey] Multipart content interop issue between CXF
> and Jersey
>
> Hi Murali,
>
> I think this may be a bug in the mimpull API or the CXF client is
> sending malformed content. My hunch is that mimepull is not ignoring
> any characters before the first boundary.
>
> Would it be possible to send the exact bytes captured by tcpmon.
> Then we can use that data for a test case.
>
> Paul.
>
> On Jan 6, 2011, at 3:14 PM, Murali Krishnan wrote:
>
> > 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());
> > }
> >
> >
>
>
>