gpt4 book ai didi

java - 无法捕获 AxisFault 异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:06 34 4
gpt4 key购买 nike

我有一个代码,它是一个 web 服务的 java 包装器,在异常时它会抛出一个 AxisFault 异常(如下所示)

org.apache.axis2.AxisFault: Policy enforcement failed to authenticate the request.
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:446)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.tibco.n2.de.services.EntityResolverServiceStub.lookupUser(EntityResolverServiceStub.java:261)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

代码如下所示,

try {
lookupUserResponse = myIntializedObject.lookupUser("someuser", null, null, true);
} catch (InvalidServiceRequestFault e) {
// TODO Auto-generated catch block
//e.printStackTrace();
} catch (InternalServiceFault e) {
// TODO Auto-generated catch block
//e.printStackTrace();
} catch (SecurityFault e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
finally{
if(lookupUserResponse==null)
return false;
}

我也试过只用一个 Exception e block 替换所有 catch block ,但它仍然没有捕获异常

最佳答案

我能够通过以下方式捕获 AxisFault 错误:

try {
...
} catch (RemoteException ex) {
if(ex instanceof AxisFault){
logger.error("Axis Fault error: " + ((AxisFault)ex).getFaultString());
}
}

AxisFaultjava.rmi.RemoteException 的子类。您可以通过查看 API docs 了解这一点.类层次结构显示在页面的左上角。

至于为什么在catch语句中使用java.lang.Exception时没有捕获到这个,也许您可​​以贴出相关代码?

关于java - 无法捕获 AxisFault 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11077988/

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