我有一个代码,它是围绕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;
}
我也尝试用只有一个异常e块来替换所有catch块,但它仍然没有捕获异常
答案 0 :(得分:3)
我能够通过以下方式捕获AxisFault错误:
try {
...
} catch (RemoteException ex) {
if(ex instanceof AxisFault){
logger.error("Axis Fault error: " + ((AxisFault)ex).getFaultString());
}
}
AxisFault
是java.rmi.RemoteException
的子类。你可以通过查看API docs来了解这一点。类层次结构显示在页面的左上角。
至于为什么在java.lang.Exception
语句中使用catch
时未捕获到此内容,或许您可以发布相关代码?