I have a jax-rs REST service, using JEE 7 (deployed in glassfish), which has a method to process HTTP POST on the resource:
@POST
@Path(value="{dId}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response sendStatus(@Context HttpServletRequest request)
I try to extract the multipart data as:
Collection<Part> parts = request.getParts();
if(parts==null || parts.isEmpty()){
lg.warn("Empty/non-existent parts in request body!");
return sendBadRequestError(sp);
}
I then try to simulate a client multipart POST request, using RestClient(from wiztools.org), with atleast 2 parts of different content-types ( boundary delimiter is automatically set by the RESTClient tool).
I verify in wireshark that its a proper request that is sent from the RESTClient( no malformed packet etc).
However, all the request seems to hit the block containing the Empty/non-existent parts in request body message, indicating there were no parts found in the request.
I searched around in Stackoverflow many times before posting, and all the examples/solutions relate to use-case where one is uploading a file/image, which is not the case am dealing with.
My rest service just consumes a multipart request, which can consist of one part with JSON data, another part with simple string or other JSON data.
Is there something am missing - please help?.Is there someother technique to parse the multipart data that hits a REST service?
Please advice.
Thanks. J