users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 22 Apr 2009 18:26:40 +0200

I added the following unit test that emulates what you are doing and
ti works fine:

http://fisheye4.atlassian.com/browse/~raw,r=2283/jersey/trunk/jersey/
contribs/jersey-multipart/src/test/java/com/sun/jersey/multipart/impl/
MultipartMixedWithApacheClientTest.java

Paul.

On Apr 22, 2009, at 3:39 PM, Gehl, Pascal wrote:

> I don’t know if was clear enough.
>
> My problem is that for example my client adds a 900 000 bytes byte[]
> to the multipart object and my server side only receives 600 000
> bytes in the BodyPartentity.
>
> Between the 2 there is only jersey client API and jersey server API.
>
> Has anybody experienced (and hopefully found a solution to) this
> problem ?
>
> Pascal
> From: Gehl, Pascal
> Sent: Wednesday, April 22, 2009 9:05 AM
> To: users_at_jersey.dev.java.net
> Subject: [Jersey] problem with multipart API when receiving
> BodyPartEntity
>
> 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("multipart/mixed");
> jerseyBuilder.entity(multiPart, "multipart/mixed");
> ClientResponse clientResponse =
> jerseyBuilder.post(ClientResponse.class, multiPart);
>
>
> The server receives the Multipart object
>
> @POST
> @Consumes(""multipart/mixed"")
> 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 GEHL