Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude method from CXF WebService - strange behavior

Tags:

java

cxf

java-ws

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.

like image 277
Betlista Avatar asked Mar 21 '13 16:03

Betlista


2 Answers

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);

}
like image 83
user2641658 Avatar answered Oct 04 '22 03:10

user2641658


Its late but I would like to chip in my answer.

  1. Get rid of all the @WebMethod as they are optional and needed only when a method must be excluded.

    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    @WebService
    public interface MyWebService {
    
      String method1(String s);
    
      String method2(String s);
    
      String methodToExclude(String s);
    
    }
    
  2. Add @WebMethod(exclude = true) to Interface Implementation only

    public class MyWebServiceImpl implements MyWebService {
    
      String method1(String s) {
        // ...
      }
    
      String method2(String s) {
        // ...
      }
    
      @WebMethod(exclude = true)
      String methodToExclude(String s) {
        // ...
      }
    }
    
like image 31
Himalay Majumdar Avatar answered Oct 04 '22 02:10

Himalay Majumdar