How can one get the full HTTP REST request body for a POST
request using Jersey?
In our case the data will be XML. Size would vary from 1K to 1MB.
The docs seem to indicate you should use MessageBodyReader
but I can't see any examples.
How can one get the full HTTP REST request body for a POST
request using Jersey?
In our case the data will be XML. Size would vary from 1K to 1MB.
The docs seem to indicate you should use MessageBodyReader
but I can't see any examples.
You could use the @Consumes annotation to get the full body:
Note: Don't forget the "Content-Type: application/xml" header by the request.
Try this using this single code:
The url for try rest services ends .... /serviceX/doSomething
Turns out you don't have to do much at all.
See below - the parameter
x
will contain the full HTTP body (which is XML in our case).It does seem you would have to use a
MessageBodyReader
here. Here's an example, using jdom:Add this class to the list of resources your jersey deployment will process (usually configured via web.xml, I think). You can then use this reader in one of your regular resource classes like this:
I haven't verified that this works exactly as typed, but that's the gist of it. More reading here:
Since you're transferring data in xml, you could also (un)marshal directly from/to pojos.
There's an example (and more info) in the jersey user guide, which I copy here:
POJO with JAXB annotations:
Resource:
The xml that gets produced/consumed: