I have a broken unit test after trying do get the HttpServletRequest that is passed as a parameter in a Jersey Web Service post call:
@RequestScoped
@Path("/por/req")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public class MyOwnWs {
@POST
@Path("/confirm")
public Response confirmarRequerimento(
@ApiParam(value = "Description", required = false)
final InputJson input,
@Context HttpServletRequest request) throws MyException {
Response response = null;
MyResult result = null;
String ipAdress = IpUtil.getIp(request);
// do stuff
return response;
}
}
testing in the browser is fine, the request object contains my test machine ip adress. But int the unit tests with grizzly the request object is always null and I still didn't figured out a way of mocking it. The relevant part of my test code is like:
MyResult response = target(URL).
request().
post(Entity.json(input), MyResult.class);
This was working fine before adding the @Context HTTPServletRequest in the service call. Any Sugestions about what I'm missing?