我正在使用REST服务进行测试,我需要从它获得一个HttpServletResponse对象。
当我像这样调用这个函数时:
http://localhost:8080/wsService/api/servicetest/testify
我得到的HttpServletResponse总是空的。
@Path("/testify")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response Testify(HttpServletResponse response) throws Exception {
try {
return Utilities.getSvc(true, "OK");
} catch (Exception e) {
return Utilities.getSvc(false, "ERROR");
}
}我遗漏了什么吗?
发布于 2017-12-14 17:27:07
我最终做到了,只需要将@Context注释放到HttpServletResponse对象中,并添加一个HttpServletRequest参数:
@Path("/testify")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response Testify(@Context HttpServletResponse response,
@Context HttpServletRequest request) throws Exception {
try {
return Utilities.getSvc(true, "OK");
} catch (Exception e) {
return Utilities.getSvc(false, "ERROR");
}
}https://stackoverflow.com/questions/47818464
复制相似问题