Reputation: 1525
Anyone know how to get content of httprequest in REST webservice using java?
thanks
Upvotes: 2
Views: 5945
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