wsgen 公开未使用 @WebMethod 注释的方法
wsgen exposes methods that are not annotated with @WebMethod
我定义了以下最小网络服务:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class DummyWS {
public static void main(String[] args) {
final String url= "http://localhost:8888/Dummy";
final Endpoint endpoint= Endpoint.create(new DummyWS());
endpoint.publish(url);
}
@WebMethod
public void putData(final String value) {
System.out.println("value: "+value);
}
@WebMethod
public void doSomething() {
System.out.println("doing nothing");
}
public void myInternalMethod() {
System.out.println("should not be exposed via WSDL");
}
}
如您所见,我有两个方法要公开,因为它们用 @WebMethod
注释:putData
和 doSomething
。
但是当 运行 wsgen 时,它会生成一个包含 myInternalMethod
的 WSDL,尽管它是 not 注释。
我这里配置有误吗?为什么公开了未使用 @WebMethod 注释的方法?
好的,我找到了。默认 all public 方法被公开。要排除一种方法,必须用 @WebMethod(exclude=true)
对其进行注释。
这是一个相当奇怪的要求,因为这意味着我只需要用 @WebMethod
注释那些我 而不是 想要公开的方法。
这是正确的代码:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class DummyWS {
public static void main(String[] args) {
final String url= "http://localhost:8888/Dummy";
final Endpoint endpoint= Endpoint.create(new DummyWS());
endpoint.publish(url);
}
public void putData(final String value) {
System.out.println("value: "+value);
}
public void doSomething() {
System.out.println("doing nothing");
}
@WebMethod(exclude=true)
public void myInternalMethod() {
System.out.println("should not be exposed via WSDL");
}
}
我定义了以下最小网络服务:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class DummyWS {
public static void main(String[] args) {
final String url= "http://localhost:8888/Dummy";
final Endpoint endpoint= Endpoint.create(new DummyWS());
endpoint.publish(url);
}
@WebMethod
public void putData(final String value) {
System.out.println("value: "+value);
}
@WebMethod
public void doSomething() {
System.out.println("doing nothing");
}
public void myInternalMethod() {
System.out.println("should not be exposed via WSDL");
}
}
如您所见,我有两个方法要公开,因为它们用 @WebMethod
注释:putData
和 doSomething
。
但是当 运行 wsgen 时,它会生成一个包含 myInternalMethod
的 WSDL,尽管它是 not 注释。
我这里配置有误吗?为什么公开了未使用 @WebMethod 注释的方法?
好的,我找到了。默认 all public 方法被公开。要排除一种方法,必须用 @WebMethod(exclude=true)
对其进行注释。
这是一个相当奇怪的要求,因为这意味着我只需要用 @WebMethod
注释那些我 而不是 想要公开的方法。
这是正确的代码:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class DummyWS {
public static void main(String[] args) {
final String url= "http://localhost:8888/Dummy";
final Endpoint endpoint= Endpoint.create(new DummyWS());
endpoint.publish(url);
}
public void putData(final String value) {
System.out.println("value: "+value);
}
public void doSomething() {
System.out.println("doing nothing");
}
@WebMethod(exclude=true)
public void myInternalMethod() {
System.out.println("should not be exposed via WSDL");
}
}