users@jersey.java.net

problem with multipart API when receiving BodyPartEntity

From: Gehl, Pascal <Pascal.Gehl_at_nuance.com>
Date: Wed, 22 Apr 2009 09:04:44 -0400

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