Skip to content
JakeHoward edited this page Jul 16, 2015 · 1 revision

Getting access to a raw request in a resource

To get access to a raw request just pass a request object as an argument to the resource method.

public class MyResource {
   @GET
   @Path("home")
   public Response serveRequest(Request request) {
      // some logic
   }
}

Utterlyidle doesn't try to hide HTTP details from you.

On the wire representation of the request:

String request = request.toString(); 

HTTP method:

String httpMethod = request.method();

Uri:

Uri uri = request.uri();

HTTP headers:

HeaderParameters headers = request.headers();
Iterator<Pair<String,String>> iterator = headers.iterator();
while(iterator.hasNext()) {
   Pair<String, String> nameValue = iterator.next();
   System.out.println(nameValue.first()+" "+nameValue.second());
}

Entity:

Entity entity = request.entity();
byte[] entityAsBytes = entity.asBytes();
String entityAsString = entity.toString();

Clone this wiki locally