I have written a webservice and tried to throw my custom exception but i am getting error please help me to solve it.
我写了一个webservice,试图抛出我的自定义异常,但是我有错误请帮助我解决它。
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService(name = "WebService")
public class WebServiceTest {
public String sayHello(String name) throws InvalidInputException {
throw new InvalidInputException("I am testing", null);
}
public static void main(String[] args) {
WebServiceTest server = new WebServiceTest();
Endpoint endpoint = Endpoint.publish(
"http://localhost:9191/webServiceTest", server);
}
}
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
@XmlType(name = "InputMessageValidationFaultType")
public class FaultBean {
@XmlAttribute
protected String msg;
public String getMsg() {
return msg;
}
public void setMsg(String value) {
this.msg = value;
}
}
import javax.xml.ws.WebFault;
@WebFault(faultBean = "mytest.com.inc.FaultBean")
public class InvalidInputException extends Exception {
private static final long serialVersionUID = 1L;
private FaultBean faultBean;
public InvalidInputException() {
super();
}
public InvalidInputException(String message, FaultBean faultBean,
Throwable cause) {
super(message, cause);
this.faultBean = faultBean;
}
public InvalidInputException(String message, FaultBean faultBean) {
super(message);
this.faultBean = faultBean;
}
public FaultBean getFaultInfo() {
return faultBean;
}
}
ERROR MESSAGE Exception in thread "main" java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String; at com.sun.xml.ws.model.RuntimeModeler.processExceptions(RuntimeModeler.java:1162) at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:898) at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:666) at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:420) at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:254) at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:338) at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:201) at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:505) at com.sun.xml.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:257) at com.sun.xml.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:181) at com.sun.xml.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:123) at javax.xml.ws.Endpoint.publish(Endpoint.java:170) at mytest.com.inc.WebServiceTest.main(WebServiceTest.java:13)
线程“main”java.lang中的错误消息异常。NoSuchMethodError:javax.xml.ws.WebFault.messageName()Ljava / lang / String;在com.sun.xml. w.w .model. model. runtimemodeler . processer .java . processexceptions (runtimemer .java .create . format .xml. timmanager . runer . format . format .processweb . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . web . webmytest.com.inc.WebServiceTest.main(WebServiceTest.java:13)
2 个解决方案
#1
7
Old question I know but I think the method names in your FaultBean class need to be getMessage and setMessage (as opposed to getMsg and setMsg) - see this excellent article:
我知道这个老问题,但是我认为您的FaultBean类中的方法名需要是getMessage和setMessage(与getMsg和setMsg不同)—请参阅这篇优秀的文章:
http://io.typepad.com/eben_hewitt_on_java/2009/07/using-soap-faults-and-exceptions-in-java-jaxws-web-services.html
#2
12
Last time I saw this error, it was due by a missmatch of version of JAX-WS used (2.1.x and 2.2.x) You are maybe compiling against the 2.1.x version but running against 2.2.x, or the other way round.
上次我看到这个错误,是由于使用了JAX-WS版本的错误匹配(2.1)。x和2.2.x)你可能是在对2.1进行编译。x版本,但是运行在2.2。或者反过来。
Keep in mind that the JDK 6 includes the 2.1.x version of JAX-WS, so you might have to use the endorsed library mechanism to force the usage of 2.2.x
请记住JDK 6包含2.1。x版本的JAX-WS,因此您可能必须使用经过认可的库机制来强制使用2.2.x
#1
7
Old question I know but I think the method names in your FaultBean class need to be getMessage and setMessage (as opposed to getMsg and setMsg) - see this excellent article:
我知道这个老问题,但是我认为您的FaultBean类中的方法名需要是getMessage和setMessage(与getMsg和setMsg不同)—请参阅这篇优秀的文章:
http://io.typepad.com/eben_hewitt_on_java/2009/07/using-soap-faults-and-exceptions-in-java-jaxws-web-services.html
#2
12
Last time I saw this error, it was due by a missmatch of version of JAX-WS used (2.1.x and 2.2.x) You are maybe compiling against the 2.1.x version but running against 2.2.x, or the other way round.
上次我看到这个错误,是由于使用了JAX-WS版本的错误匹配(2.1)。x和2.2.x)你可能是在对2.1进行编译。x版本,但是运行在2.2。或者反过来。
Keep in mind that the JDK 6 includes the 2.1.x version of JAX-WS, so you might have to use the endorsed library mechanism to force the usage of 2.2.x
请记住JDK 6包含2.1。x版本的JAX-WS,因此您可能必须使用经过认可的库机制来强制使用2.2.x