Hi

MultipartBody represents the complete multipart body request, so you can either use only MultipartBody and extract the individual parts from it or use a non MultipartBody to refer to the individual parts.

If you need to support the variable number of parts then using MultipartBody is the simplest option. If you have a real multipart/form-data request where one part, say named 'files' contains the embedded parts, then you can do something like

myEndPoint(@Multipart(value="context") String firstPart, @Multipart(value="files") List<MyType> files)

In general using a List to capture the parts with the same id will also work even if you do not have the embedded parts inside a single part

Cheers, Sergey
On 28/05/17 10:28, nicolasduminil wrote:
Hello,

I have a JAX-RS service which one of endpoints consumes a multipart containg
a list of attachments. The first attachment is a JSON object, the next ones
are input streams. Here is the signature:

   @POST
   @Consumes({MediaType.MULTIPART_FORM_DATA, MediaType.APPLICATION_JSON,
"multipart/mixed" })
   @Path("createTransaction")
   public Response myEndPoint (@Multipart(value = "context", type =
MediaType.APPLICATION_JSON)MyContext ctx, MultipartBody mb) throws
QuickSignException

So, the idea is to have a first part of type "application/json", followed by
a certain number of parts having input streams to PDF files.

The client calling the end-point looks as follows:

     List<Attachment> attachments = new ArrayList<Attachment>();
     attachments.add(new Attachment("context", MediaType.APPLICATION_JSON,
new MyContext()));
     attachments.add((new Attachment ("contracts",
MediaType.MULTIPART_FORM_DATA, new FileInputStream (new File
("test.pdf")))));
     Response resp = client.target(new
URI("http://localhost:9082/qs/services/api/createTransaction";)).request().post(Entity.entity(new
MultipartBody(attachments), MediaType.MULTIPART_FORM_DATA_TYPE));
     assertEquals (200, resp.getStatus());

And the assertions fails as the service responds with HTTP 415.

So, my questions are:
   1. Is that the right way to accomplish what I need, aka passing a JSON
object and a variable number of input files in a multipart ?
   2. If this is the right way to do that, why do I get HTTP 415 and how to
correct that ?

Many thanks in advance,

Nicolas




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



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to