Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use JAX-WS webfault

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 = "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)

like image 516
Arvind Avatar asked Jul 07 '11 06:07

Arvind


1 Answers

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

like image 165
gastush Avatar answered Oct 11 '22 10:10

gastush