How to exclude method from CXF WebService - strange behavior

Betlista picture Betlista · Mar 21, 2013 · Viewed 9.7k times · Source

Can someone explain to me the following behavior of CXF?

I have simple WebService:

import javax.jws.WebMethod;

public interface MyWebService {

    @WebMethod
    String method1(String s);

    @WebMethod
    String method2(String s);

    @WebMethod(exclude = true)
    String methodToExclude(String s);

}

I want to have my methodToExclude in interface (for Spring), but I do not want to have this method in generated WSDL file. The code above does exactly that.

But when I add @WebService annotation to the interface I get error:

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface MyWebService {

    @WebMethod
    String method1(String s);

    @WebMethod
    String method2(String s);

    @WebMethod(exclude = true)
    String methodToExclude(String s);

}

org.apache.cxf.jaxws.JaxWsConfigurationException: The @javax.jws.WebMethod(exclude=true) cannot be used on a service endpoint interface. Method: methodToExclude

Can someone explain this to me? What's the difference? Also I'm not sure if it will work fine later, but I didn't find the way how to exclude the methodToExclude when I use @WebService.

Answer

user2641658 picture user2641658 · Aug 1, 2013

The @javax.jws.WebMethod(exclude=true) is used on the implementation:

public class MyWebServiceImpl implements MyWebService {
    ...
    @WebMethod(exclude = true)
    String methodToExclude(String s) {
        // your code
    }
}

Don´t include the method methodToExclude in the interface:

@WebService
public interface MyWebService {
    @WebMethod
    String method1(String s);

    @WebMethod
    String method2(String s);

}