简体   繁体   English

传递null参数时,CXF REST调用方法中的NullPointerException

[英]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.

相关问题 放心 - post() - java.lang.NullPointerException: 无法在 null 对象上调用方法 trim() - Rest Assured - post() - java.lang.NullPointerException: Cannot invoke method trim() on null object 无法调用其他cxf服务 - unable to invoke rest cxf service 调用REST控制器方法返回404 null - Invoke REST controller method returns 404 null 发生NullPointerException尝试在空对象引用上调用虚拟方法 - occur NullPointerException Attempt to invoke virtual method on a null object reference Android Studio:NullPointerException:尝试在 null object 参考上调用虚拟方法“...” - Android Studio: NullPointerException: Attempt to invoke virtual method '...' on a null object reference java.lang.NullPointerException:无法在 null 上调用方法 get() object - java.lang.NullPointerException: Cannot invoke method get() on null object java.lang.NullPointerException:无法在空对象上调用方法queryForList() - java.lang.NullPointerException: Cannot invoke method queryForList() on null object CXF - 方法 arguments 是 null - CXF - method arguments are null java,如果参数为null,则字符串方法应返回null,但它会抛出NullPointerException - java, a string method should return null if the parameter is null but it throws NullPointerException 具有apache camel和cxf的REST Web服务:启动时出现NullPointerException - REST webservices with apache camel and cxf : NullPointerException on startup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM