users@glassfish.java.net

[jersey] problem with multipart API when receiving BodyPartEntity

From: <glassfish_at_javadesktop.org>
Date: Tue, 21 Apr 2009 13:12:35 PDT

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