Hi Sergey,

In my case, I can't use @Multipart as they refernce extension classes that
aren't authorized to be used with WebSphere (they are imported as
"was_internal" meaning that only WAS but not applications may use them).
Accordingly, I have to use com.ibm.websphere.jaxrs20.multipart.IMulipartBody
and, for some reason,  the call attachment.getObject(MyType.class) on the
service side returns null.

So, finally I came to that:

Client:
      List<Attachment> attachments = new ArrayList<Attachment>();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectMapper().writeValue(baos, new MyObject());
    attachments.add(new Attachment("context", new
ByteArrayInputStream(baos.toByteArray()), new ContentDisposition("form-data;
name=\"create-transaction-context\"")));
    for (File file : files)
    {
      FileInputStream stream = new FileInputStream(file);
      attachments.add(new Attachment(file.getName(), stream, new
ContentDisposition("form-data; name=\"contracts\"; filename=\"" +
file.getName() + "\"")));
    }
    assertEquals(200,
        client.target(new
URI("http://localhost:9081/qs/services/api/createTransaction";)).request().post(Entity.entity(new
MultipartBody(attachments), MediaType.MULTIPART_FORM_DATA)).getStatus());

Here the object type MyObject is marshalled in a JSON string and passed as a
ByteArrayInputStream. On the server side the string is unmarshelled into
Java object. 

This works but I hoped that the marshalling/unmarshalling stuff would happen
automatically, behinde the scene, but I didn't find any way to make it
happen. Is that the right way to do things in this case ?

Kind regards,

Nicolas



--
View this message in context: 
http://cxf.547215.n5.nabble.com/HTTP-415-raised-by-JAX-RS-service-consuming-multipart-tp5780784p5780874.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to