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 に答える