Hi
On 31/05/17 17:25, nicolasduminil wrote:
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.
The part needs to contain Content-Type
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 ?
Have a look please at
https://github.com/apache/cxf/blob/master/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Attachment constructors are somewhat inconsistent, were done awhile
back, but basically, make sure you pass the headers to it, or
Content-Type directly, and that will do it...
if you can not use @Multipart then iterate of a list of Attachments you
can get from (I)MultipartBody.
Cheers, Sergey
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.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/