sudo
sudo

Reputation: 1525

get content of http request in REST web service using java

Anyone know how to get content of httprequest in REST webservice using java?

thanks

Upvotes: 2

Views: 5945

Answers (2)

Jonas Kongslund
Jonas Kongslund

Reputation: 5268

You can inject context about the individual requests. As an example, the code snippet below shows how the HTTP request headers can be injected.

@GET  
@Produces{"text/plain"}  
public String listHeaderNames(@Context HttpHeaders headers) {  
  StringBuilder buf = new StringBuilder();  
  for (String header: headers.getRequestHeaders().keySet()) {  
    buf.append(header);  
    buf.append("\n");  
  }  
  return buf.toString();  
}

See the relevant part of the JAX-RS 1.1 specification for more information.

Upvotes: 3

sbridges
sbridges

Reputation: 25150

Look at Restlet

// Create the client resource  
ClientResource resource = new ClientResource("http://www.restlet.org");  

// Write the response entity on the console
resource.get().write(System.out);

Upvotes: 1

Related Questions