Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get full REST request body using Jersey?

Tags:

java

rest

jersey

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.

like image 820
Marcus Leon Avatar asked Nov 12 '09 20:11

Marcus Leon


People also ask

What is Jersey in REST API?

Jersey is Sun's production quality reference implementation for JSR 311: JAX-RS: The Java API for RESTful Web Services. Jersey implements support for the annotations defined in JSR-311, making it easy for developers to build RESTful web services with Java and the Java JVM.

What are the Jersey annotations in REST resource class?

Jersey annotations are runtime annotations, therefore, runtime reflection will generate the helper classes and artifacts for the resource, and then the collection of classes and artifacts will be built into a web application archive (WAR).

Can we send body GET request?

So, yes, you can send a body with GET, and no, it is never useful to do so. This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress). Yes, you can send a request body with GET but it should not have any meaning.


1 Answers

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).

@POST public Response go(String x) throws IOException {     ... } 
like image 82
Marcus Leon Avatar answered Sep 21 '22 13:09

Marcus Leon