users@glassfish.java.net

Re: [jersey] problem with multipart API when receiving BodyPartEntity

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 22 Apr 2009 10:00:31 +0200

Hi Pascal,

What version of Jersey are you using? 1.0.2?

There was a bug in 1.0.2, that is fixed in 1.0.3, where the boundary
string in the media type was not created to demarcate body parts, and
this may be causing the issue. (Specifically the problem was related
to committing the request headers when the first byte of the request
entity is written).

It is possible to work around this for 1.0.2 (as the GlassFish
Mobility Platform folks did by explicitly adding the media type with a
boundary parameter), and such a workaround will also work for 1.0.3.

Hope this helps,
Paul.

On Apr 21, 2009, at 10:12 PM, glassfish_at_javadesktop.org wrote:

> Hi,
>
> In my application I send 2 bodyparts ( the first is XML and the
> second is an audio file (small):
>
> MultiPart multiPart = new MultiPart().bodyPart(
> new BodyPart(jaxbSchedulerTranscriptionRequest,
> MediaType.APPLICATION_XML_TYPE)).bodyPart(
> new BodyPart(audioByteArray,
> MediaType.APPLICATION_OCTET_STREAM_TYPE));
>
> Builder jerseyBuilder =
> webResource.accept(MediaType.MULTIPART_FORM_DATA);
> jerseyBuilder.entity(multiPart, MediaType.MULTIPART_FORM_DATA);
> ClientResponse clientResponse =
> jerseyBuilder.post(ClientResponse.class, multiPart);
>
> the server receives the Multipart object
>
> @POST
> @Consumes("multipart/form-data")
> public Response receive(MultiPart multiPart) throws Exception {
> Object generatedXMLRequest =
> multiPart
> .getBodyParts().get(0).getEntityAs(getGeneratedXMLObjectClass());
>
> BodyPartEntity bodyPartEntity = (BodyPartEntity)
> multiPart.getBodyParts().get(1).getEntity();
> InputStream audioStream = bodyPartEntity.getInputStream();
> byte[] audioArray = IOUtils.toByteArray(audioStream);
>
> My problem is that the number of bytes sent as audio (2nd bodypart)
> is not equal to the number of bytes received.
>
> Do I miss something ?
>
> Thanks
>
> Pascal
> [Message sent by forum member 'paskos' (paskos)]
>
> http://forums.java.net/jive/thread.jspa?messageID=343131
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>