Hi,
If you use FormParam for your multipart/form-data packets, you can envelope
them with @BeanParam:
public class MyBean {
@FormParam("myData")
private String data;
...
}
@Path("myresources")
public class MyResources {
@POST
@Path("{id}")
public void post(@BeanParam MyBean myBean) {...}
...
}
Regards,
Andrei.
> -----Original Message-----
> From: Paul Avijit [mailto:[email protected]]
> Sent: Dienstag, 29. April 2014 18:27
> To: [email protected]
> Subject: CXF + REST + multipart/form-data
>
> Hi,
>
> I have a CXF REST service. It consumes "multipart/form-data". A sample
> request received by the service is as follows:
>
>
> INFO: Inbound Message
> ----------------------------
> ID: 1
> Address: http://localhost:7001/services/MIMEServices/batchSubmitTransaction
> Encoding: ISO-8859-1
> Http-Method: POST
> Content-Type: multipart/form-data; boundary=----
> WebKitFormBoundaryvvDTLM9Nty3rROQA
> Headers:
> {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*
> /*;q=0.8], accept-encoding=[gzip,deflate,sdch], Accept-Language=[en-
> US,en;q=0.8], Cache-Control=[max-age=0], connection=[keep-alive], Content-
> Length=[462], content-type=[multipart/form-data; boundary=----
> WebKitFormBoundaryvvDTLM9Nty3rROQA], Host=[localhost:7001],
> Origin=[null], User-Agent=[Mozilla/5.0 (Windows NT 6.1; WOW64)
> AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131
> Safari/537.36]}
> Payload: ------WebKitFormBoundaryvvDTLM9Nty3rROQA
> Content-Disposition: form-data; name="Payload"; filename="test.txt"
> Content-Type: text/plain
>
> This is Test file for testing File Upload...
> ------WebKitFormBoundaryvvDTLM9Nty3rROQA
> Content-Disposition: form-data; name="PayloadType"
>
> MyPayloadType
> ------WebKitFormBoundaryvvDTLM9Nty3rROQA
> Content-Disposition: form-data; name="ProcessingMode"
>
> MyProcessingMode
> ------WebKitFormBoundaryvvDTLM9Nty3rROQA--
>
> --------------------------------------
>
>
> I have written a method in the service implementation class to handle the
> above request using the following options and both work:
>
> Option#1:
> @POST
> @Path("/batchSubmitTransaction")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> public void batchSubmitTransaction(MultipartBody request)
>
>
> Option#2:
> @POST
> @Path("/batchSubmitTransaction")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> public void batchSubmitTransaction(List<AttachmentDataSource> request)
>
>
> In CXF is there a way for data binding so that I can map the multipart/form-
> data request above to a POJO something like the following:
>
> @POST
> @Path("/batchSubmitTransaction")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> public void batchSubmitTransaction(EnvelopeBatchSubmission request)
>
> where EnvelopeBatchSubmission is:
>
> public class EnvelopeBatchSubmission
> {
> public DataHandler payload;
> public String payloadType;
> public String processingMode;
> }
>
>
> Resteasy has such an option
> (https://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html/Multipart.html#m
> ultipartform_annotation) but I could not find similar option in CXF
> documentation.
>
> Thanks in advance.
>
> Regards
> Paul