POST 中的 Jersey @HeaderParam null
Jersey @HeaderParam null in POST
我在 POST 上的资源中得到 NULL @HeaderParam。但是,身份验证过滤器会在调用到达资源之前拦截该调用并成功提取 header 信息。相同的 header 信息。结果在资源中为空。
构造函数失败并抛出 NullPointerException。
资源代码class:
@Path("/profile")
@Consumes(MediaType.APPLICATION_JSON)
public class UserAccountEP {
@HeaderParam("userId")
public String userId;
public UserAccountEP()
{
if(userId==null)
throw new NullPointerException("UserId is null");
}
@POST
@Path("/action")
public void action(String ip) throws IOException {}
}
有人可以看看我做错了什么吗?
谢谢。
注入发生在构造 class 之后,因此您无法在构造函数中访问注入的值。
使用@PostConstruct 注释回调方法,如下所示。
@PostConstruct
private void validate() {
....
}
我在 POST 上的资源中得到 NULL @HeaderParam。但是,身份验证过滤器会在调用到达资源之前拦截该调用并成功提取 header 信息。相同的 header 信息。结果在资源中为空。
构造函数失败并抛出 NullPointerException。
资源代码class:
@Path("/profile")
@Consumes(MediaType.APPLICATION_JSON)
public class UserAccountEP {
@HeaderParam("userId")
public String userId;
public UserAccountEP()
{
if(userId==null)
throw new NullPointerException("UserId is null");
}
@POST
@Path("/action")
public void action(String ip) throws IOException {}
}
有人可以看看我做错了什么吗?
谢谢。
注入发生在构造 class 之后,因此您无法在构造函数中访问注入的值。
使用@PostConstruct 注释回调方法,如下所示。
@PostConstruct
private void validate() {
....
}