How to exclude method from CXF WebService - strange behavior
Asked Answered
K

2

11

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.

Katt answered 21/3, 2013 at 16:59 Comment(0)
H
7

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

}
Heinz answered 1/8, 2013 at 10:21 Comment(1)
@Katt cannot afford to take out methodToExclude from the interface to satisfy Spring, all he needs to do is to include @WebMethod(exclude = true) in implementation only.Execration
E
2

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) {
        // ...
      }
    }
    
Execration answered 3/12, 2014 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.