Search code examples
javaspringservletsmime

Spring web service - How do i extract the request?


I have a web service that is processed on the Spring end as follows:

    @POST
    @Path("/processRequest")
    @Consumes("multipart/mixed")
    @ResponseStatus(HttpStatus.OK)
    public String processRequest(@Context ServletContext servletContext, MultipartInput input) {

        return addAccout(servletContext, input);
    }

The request will come in as a multipart/mixed request and will look something like this:

--productBoundary
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?>
<product>
     <name>ProductA</name>
</product>

--productBoundary
Content-Type: text/xml

ZGF0YRBAAABn5///////////////5///Z+fn///n////////5////////2f//2f//+f//+f////n/
///////52f//////2f//////2f/////5////////+f/////Z+f///////////////9n//9nZ/9n////5+f///9
<snip>
//+f//////2f/////////5//n//////////9n

--productBoundary--

The request will come in as a mutipart/mixed. I can use Resteasy's object shown in the processRequest's method parameters to extract each part of the multipart/mixed message. What i would like to do though is to get the message as it is unmodified with its headers and everything else. Is this possible?

I need to be able to store the request exactly as it came in. Using the MultipartInput structure means i have modified the request. Is there anyway i can get the request as it came in (with all its headers) without modifying it?


Solution

  • Docs here:

    3.1.18 @RequestPart Annotation On Controller Method Arguments

    This new annotation provides access to the content of a "multipart/form-data" request part. See Section 16.10.5, “Handling a file upload request from programmatic clients” and Section 16.10, “Spring's multipart (file upload) support”.