[英]NullPointerException in CXF REST invoke method when passing a null parameter
I'm consuming a REST web service which exposes a method like 我正在使用REST Web服务,该服务公开了类似
public boolean uploadConfig(String configContent);
In my client I annotated this interface in this way: 在我的客户端中,我以这种方式注释了此接口:
public boolean uploadConfig(@WebParam(name = "configContent") String configContent);
So that 'configContent' param should be a Body parameter. 因此,“ configContent”参数应为Body参数。
The problem is that if I pass a null configContent, a NullPointerException is thrown from ClientProxyImpl.invoke() method. 问题是,如果我传递一个空的configContent,则会从ClientProxyImpl.invoke()方法中引发NullPointerException。
I surely can check in my code for the null-ness of the input param, but I'd like to know how may I manage this check natively with CXF client lib. 我当然可以在代码中检查输入参数的无效性,但是我想知道如何使用CXF客户端库本机管理此检查。 Perhaps some annotation missing in the interface? 也许界面中缺少一些注释?
Thank you very much! 非常感谢你!
Best 最好
cghersi cghersi
The @WebParam annotation is only applicable for JAX-WS. @WebParam批注仅适用于JAX-WS。
Assuming you are trying to send the data as in an HTML form post, you should annotate the parameter with the JAX-RS @FormParam . 假设您要尝试按HTML表单发布中的方式发送数据,则应使用JAX-RS @FormParam注释该参数。
public boolean uploadConfig(@FormParam("configContent") String configContent);
A null value will result in no parameter being sent with the request. 空值将导致不随请求一起发送任何参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.