4

我有一个代码,它是围绕 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 的单个块替换所有 catch 块,但它仍然没有捕获异常

4

1 回答 1

4

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

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

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

至于为什么java.lang.Exceptioncatch语句中使用时没有捕获到,也许您可​​以发布相关代码?

于 2012-07-27T21:30:16.997 回答