我正在使用一个 REST Web 服务,该服务公开了类似的方法
public boolean uploadConfig(String configContent);
在我的客户端中,我用这种方式注释了这个接口(interface):
public boolean uploadConfig(@WebParam(name = "configContent") String configContent);
因此“configContent”参数应该是 Body 参数。
问题是,如果我传递 null configContent,则会从 ClientProxyImpl.invoke() 方法引发 NullPointerException。
我当然可以在代码中检查输入参数是否为空,但我想知道如何使用 CXF 客户端库本地管理此检查。 也许界面中缺少一些注释?
非常感谢!
最佳
cghersi
最佳答案
@WebParam 注释仅适用于 JAX-WS。
假设您尝试以 HTML 表单帖子的形式发送数据,则应使用 JAX-RS @FormParam 注释该参数。 .
public boolean uploadConfig(@FormParam("configContent") String configContent);
空值将导致请求中不发送任何参数。
关于java - 传递 null 参数时,CXF REST 调用方法中出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19536165/