gpt4 book ai didi

java - Axis - 响应类扩展了 AxisFault 并被抛出而不是返回?

转载 作者:太空宇宙 更新时间:2023-11-04 07:40:37 26 4
gpt4 key购买 nike

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

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

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

所以当我做这样的事情时

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

在我的客户端代码中,控制流转到 catch block 并且我实际上捕获了通常应该在 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;
}
}

}


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

最佳答案

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

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

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

关于java - Axis - 响应类扩展了 AxisFault 并被抛出而不是返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16112864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com