Cristiano Ghersi
Cristiano Ghersi

Reputation: 2122

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

Upvotes: 1

Views: 574

Answers (1)

Patrick
Patrick

Reputation: 2122

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.

Upvotes: 1

Related Questions