简体   繁体   中英

NullPointerException in CXF REST invoke method when passing a null parameter

I'm consuming a REST web service which exposes a method like

    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.

The problem is that if I pass a null configContent, a NullPointerException is thrown from ClientProxyImpl.invoke() method.

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. Perhaps some annotation missing in the interface?

Thank you very much!

Best

cghersi

The @WebParam annotation is only applicable for 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 .

public boolean uploadConfig(@FormParam("configContent") String configContent);

A null value will result in no parameter being sent with the request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM