【问题标题】:Apache XML-RPC Exception HandlingApache XML-RPC 异常处理
【发布时间】:2010-09-08 06:32:12
【问题描述】:

从通过 Apache 的 XML-RPC 实现返回的异常中提取原始异常的最简单方法是什么?

【问题讨论】:

  • 这个问题的上下文是什么?你是直接使用 XML-RPC 吗?
  • 我使用的是Apache的实现,即ws.apache.org/xmlrpc

标签: exception xml-rpc


【解决方案1】:

事实证明,从 Apache 异常中获取原因异常是正确的。

} catch (XmlRpcException rpce) {
    Throwable cause = rpce.getCause();
    if(cause != null) {
        if(cause instanceof ExceptionYouCanHandleException) {
            handler(cause);
        }
        else { throw(cause); }
    }
    else { throw(rpce); }
}

【讨论】:

    【解决方案2】:

    根据XML-RPC Spec它返回xml中的“故障”。

    这是您所指的“异常”还是您指的是在进行 XML-RPC 调用时生成的 Java 异常?

    故障示例

    HTTP/1.1 200 OK
    Connection: close
    Content-Length: 426
    Content-Type: text/xml
    Date: Fri, 17 Jul 1998 19:55:02 GMT
    Server: UserLand Frontier/5.1.2-WinNT
    
    <?xml version="1.0"?>
    <methodResponse>
      <fault>
        <value>
          <struct>
          <member>
            <name>faultCode</name>
            <value><int>4</int></value>
          </member>
          <member>
            <name>faultString</name>
            <value>
              <string>Too many parameters.</string>
            </value>
          </member>
          </struct>
        </value>
      </fault>
    </methodResponse> 
    

    【讨论】:

    • 假设使用了基本身份验证......你如何让标头成为 HTTP/1.1 401 Unauthorized 而不是?
    猜你喜欢
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 2017-12-20
    相关资源
    最近更新 更多