1

我使用 Axis1 (axis-1.4.jar) 生成了一些 java 类文件。我有一个 WS 方法调用(我也可以看到它生成的 java 代码)。

假设此方法调用接受 RequestA 作为参数并返回 ResponseA 类型的对象。我现在遇到的问题是 ResponseA 扩展了 AxisFault(我可以在为 ResponseA 生成的 java 源文件中看到它)。AxisFault 自行扩展 RemoteException。

因此,返回的 ResponseA 对象没有返回给我,而是被扔给/扔给我,因为它是 RemoteException。

所以当我做这样的事情时

try { 
   ResponseA x = call(y); // y is RequestA
} catch (Exception ex) {
    ex.printStackTrace();
}

在我的客户端代码中,控制流转到 catch 块,我实际上正在捕捉我通常应该在 x 变量中得到的内容(即 ex 通常是 x )。

知道是什么让 Axis 将我的 ResponseA 类生成为 AxisFault 的子类吗?另外,一般来说,Axis 何时生成一个类,作为 AxisFault 的子类生成?

我认为这是我目前的问题。我认为我处于奇怪的情况,成功的 WS 方法调用的响应没有返回给我,而是被扔给/扔给我。

提前谢谢了。



    package com.test.fulfillment3;

    // This is the ResponseA
    public class Actionresponse  extends org.apache.axis.AxisFault  implements java.io.Serializable {

    ...

    }


    // --------------------------------------------------------------------------------------------------------------------------------------------


    package com.test.fulfillment3;

    // This is the RequestA
    public class Actionrequest  implements java.io.Serializable {

    ...

    }


    // --------------------------------------------------------------------------------------------------------------------------------------------


    package com.test.fulfillment3;

    public class Status_ServiceBindingStub { 

    ..............


        public com.test.fulfillment3.Actionresponse status_ServiceOp(com.test.fulfillment3.Actionrequest in) throws java.rmi.RemoteException, com.test.fulfillment3.Status_ServiceFault4, com.test.fulfillment3.Status_ServiceFault2, com.test.fulfillment3.Status_ServiceFault3, com.test.fulfillment3.Actionresponse {
            if (super.cachedEndpoint == null) {
                throw new org.apache.axis.NoEndPointException();
            }
            org.apache.axis.client.Call _call = createCall();
            _call.setOperation(_operations[0]);
            _call.setUseSOAPAction(true);
            _call.setSOAPActionURI("http://soa.jboss.org/TEST/Status_ServiceOp");
            _call.setEncodingStyle(null);
            _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
            _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
            _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
            _call.setOperationName(new javax.xml.namespace.QName("", "Status_ServiceOp"));

            setRequestHeaders(_call);
            setAttachments(_call);
     try {        java.lang.Object _resp = _call.invoke(new java.lang.Object[] {in});

            if (_resp instanceof java.rmi.RemoteException) {
                throw (java.rmi.RemoteException)_resp;
            }
            else {
                extractAttachments(_call);
                try {
                    return (com.test.fulfillment3.Actionresponse) _resp;
                } catch (java.lang.Exception _exception) {
                    return (com.test.fulfillment3.Actionresponse) org.apache.axis.utils.JavaUtils.convert(_resp, com.test.fulfillment3.Actionresponse.class);
                }
            }
      } catch (org.apache.axis.AxisFault axisFaultException) {
        if (axisFaultException.detail != null) {
            if (axisFaultException.detail instanceof java.rmi.RemoteException) {
                  throw (java.rmi.RemoteException) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Status_ServiceFault4) {
                  throw (com.test.fulfillment3.Status_ServiceFault4) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Status_ServiceFault2) {
                  throw (com.test.fulfillment3.Status_ServiceFault2) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Status_ServiceFault3) {
                  throw (com.test.fulfillment3.Status_ServiceFault3) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Actionresponse) {
                  throw (com.test.fulfillment3.Actionresponse) axisFaultException.detail;
             }
       }
      throw axisFaultException;
    }
        }

    }


    // --------------------------------------------------------------------------------------------------------------------------------------------


4

1 回答 1

1

几个月前我发现了这个问题。WSDL 文件本身将(该方法的)响应类型定义为错误。因此类 ResponseA/Actionresponse 由 Axis 生成为 AxisFault 的子类。

在这种情况下,在运行时,客户端 Axis 生成的代码(我在上面粘贴的部分代码)“认为”服务器端方法没有在服务器端成功返回(即使它确实返回了),并抛出返回值而不是返回它。

非常奇怪的情况,但我现在倾向于将此视为 WSDL 本身的问题。我认为将返回值/类型同时定义为错误(在 WSDL 文件中)是不正常的。只是想分享这个答案,以防其他人遇到同样的问题。

于 2013-09-27T21:53:42.143 回答