You can inject @Context
values into properties just like the form, path, and header parameters.
Example Resource Method:
@POST
@Path("/test/{personId}/{addressId}")
public void createUser(@Form MyForm form)
{
System.out.println(form.toString());
}
Example Form Class:
public class MyForm {
private String personId;
private String addressId;
private HttpRequest request;
public MyForm() {
}
@PathParam("personId")
public void setPersonId(String personId) {
this.personId = personId;
}
@PathParam("addressId")
public void setAddressId(String addressId) {
this.addressId = addressId;
}
public HttpRequest getRequest() {
return request;
}
@Context
public void setRequest(HttpRequest request) {
this.request = request;
}
@Override
public String toString() {
return String.format("MyForm: [personId: '%s', addressId: '%s', request: '%s']",
this.personId, this.addressId, this.request);
}
}
Url:
http://localhost:7016/v1/test/1/1
Output:
MyForm: [personId: '1', addressId: '1', request: 'org.jboss.resteasy.plugins.server.servlet.HttpServletInputMessage@15d694da']