开发者

how to use JAX-WS webfault

开发者 https://www.devze.com 2023-03-17 17:05 出处:网络
I have written a webservice and tried to throw my custom exception but i am getting error please help me to solve it.

I have written a webservice and tried to throw my custom exception but i am getting error please help me to solve it.

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 = "Input开发者_如何学CMessageValidationFaultType")
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)


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.

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


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:

http://io.typepad.com/eben_hewitt_on_java/2009/07/using-soap-faults-and-exceptions-in-java-jaxws-web-services.html

0

精彩评论

暂无评论...
验证码 换一张
取 消