简体   繁体   English

JAX-WS客户端出错/通用WebService异常

[英]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. 我制作了一个JAX-WS WebService,该WebService应该在身份验证过程中引发一些业务异常,以便客户端可以处理异常并将正确的信息提供给用户。

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. WS是在4个月前开始使用的,那时一切都很好,但是从那时起,我们的客户问了很多新功能,并且这里几乎所有开发人员的合同都发生了变化,我无法弄清楚什么地方出了问题。

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: 现在是Exception类:

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 可能在WSDL中看到我的异常已映射到故障

<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 这是客户端中的方法调用,它总是进入catch(WebServiceException e)块

**All stubs/artifacts were created by WSImport. **所有存根/工件均由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 最后,由WSImport使用我的WS方法创建的接口

@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! 我注意到一些示例在创建代理之前使用QName对象获取服务实例,因此我尝试一下并成功了!

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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