简体   繁体   中英

JAX-WS client getting wrong/generic WebService exception

I made a JAX-WS WebService that is supposed to throw some business exceptions during the authentication process, so that the client can handle the exceptions and give the right info to users.

The WS started being used 4 months ago and by that time everything was working fine, but since then our client has asked a lot of new features and the contract has changed for almost every developer here and I can't figure it out what is wrong.

Could you help me, please?

@WebService
@ApplicationScoped
public class MyWS {

    @WebMethod
    public MyVO doSomething(parameters...) throws UserAuthenticationException {
        throw new UserAuthenticationException(
            "The message the business guys asked to send..."
        );
    }

Now the Exception class:

public class UserAuthenticationException extends Exception {

    private String details;

    /**
     *
     */
    private static final long serialVersionUID = -3173043626093972452L;

    public UserAuthenticationException(String msg, Throwable t) {
        super(msg, t);
    }

    public UserAuthenticationException(String reason, String details) {
        super(reason);
        this.details = details;
    }

    public UserAuthenticationException(String msg) {
        super(msg);
        this.details = msg;
    }

    public String getFaultInfo() {
        return this.details;
    }
}

It is possible to see in WSDL that my exception was mapped to a fault

<portType name="MyWS"><operation name="doSomething"><input message="tns:doSomething" wsam:Action="http://ws.../MyWS/doSomethingRequest">
 ...
    </output><fault name="UserAuthenticationException" message="tns:UserAuthenticationException" wsam:Action="http://ws.../MyWS/doSomething/Fault/UserAuthenticationException">
    </fault></operation>

Here is the method call in the client side, it always goes into the catch (WebServiceException e) block

**All stubs/artifacts were created by WSImport.

public void callMyWs() {
    try {
        //we use a proxy
        MyWS myWsPort = MyWS.getMyWSPort();
        myWsPort.doSomething()

    } catch (UserAuthenticationException_Exception e) {
        JOptionPane.showMessageDialog(e.getMessage());
        ->>>> //Here is where I expect it shoud go...

    } catch (MalformedURLException e) {
        ...
    } catch (WebServiceException e) {
        ...
        //here is where it goes
    } catch (Exception e) {
        ....
    }
}

Finally, the interface created by WSImport with my WS methods

@WebService(name = "MyWS", targetNamespace = "...")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface MyWS {


    /**
     * 
     * @return
     *     returns MyVO
     * @throws UserAuthenticationException_Exception
     */
    @WebMethod
    @WebResult(targetNamespace = "")
    @RequestWrapper(...", className = "...")
    @ResponseWrapper(localName = "...", targetNamespace = "...", className = "...")
    @Action(input = "...", output = "...", fault = {
        @FaultAction(className = UserAuthenticationException_Exception.class, value = "ws.../MyWS/doSomething/Fault/UserAuthenticationException")
    })
    public MyVO doSomething(params...)
        throws UserAuthenticationException_Exception
    ;

I just can't see what is wrong

---EDITED----

The stack trace

javax.xml.ws.ProtocolException: The message the business guys asked to send...
    at org.apache.axis2.jaxws.ExceptionFactory.createProtocolException(ExceptionFactory.java:199)
    at org.apache.axis2.jaxws.ExceptionFactory.makeProtocolException(ExceptionFactory.java:97)
    at org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.createSystemException(MethodMarshallerUtils.java:1370)
    at org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.demarshalFaultResponse(MethodMarshallerUtils.java:1089)
    at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitWrappedMethodMarshaller.demarshalFaultResponse(DocLitWrappedMethodMarshaller.java:680)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.getFaultResponse(JAXWSProxyHandler.java:626)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:566)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:432)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:213)
    at com.sun.proxy.$Proxy29.callMyService(Unknown Source)
    at package(Main.java:154)
    at package.Main$1.actionPerformed(Main.java:84)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Finally, I got it working again.

I noticed some examples use a QName object to get service instance before creating the proxy, so I give it a try and it worked!

String wsdlUrl = "http://example.com/ns/foo/MyWSService?wsdl"

URL myURL =  new URL(wsdlUrl);
QName myQName = new QName("http://example.com/ns/foo", "MyWSService");

MyWSService service = new MyWSService(myURL, myQName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM