ServerSOAPFaultException以及如何读取它?

时间:2014-09-09 17:17:07

标签: jax-ws

我做了一个请求,我的程序吐了出来

WARNING: Input Action on WSDL operation Search and @Action on its associated Web Method search did not match and will cause problems in dispatching the requests
Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Client error Please see the server log to find more detail regarding exact cause of the failure.
    at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:124)
    at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:238)
    ....

我通过mitmproxy看到服务器发回了

<?xml version='1.0' encoding='utf-8'?>
<!--pageview_candidate-->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>soapenv:Client</faultcode>
      <faultstring>Client error</faultstring>
      <faultactor>http://api.bing.net:80/soap.asmx</faultactor>
      <detail>
        <Errors xmlns="http://schemas.microsoft.com/LiveSearch/2008/03/Search">
          <Error>
            <Code>1001</Code>
            <Message>Required parameter is missing.</Message>
            <HelpUrl>http://msdn.microsoft.com/en-us/library/dd251042.aspx</HelpUrl>
            <Parameter>SearchRequest.AppId</Parameter>
          </Error>
          <Error>
            <Code>1001</Code>
            <Message>Required parameter is missing.</Message>
            <HelpUrl>http://msdn.microsoft.com/en-us/library/dd251042.aspx</HelpUrl>
            <Parameter>SearchRequest.Sources</Parameter>
          </Error>
        </Errors>
      </detail>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>

如何读取第一位并在第二位获取详细信息?我无法访问服务器日志,例如托管Web服务的服务器上的日志。

我注意到soapenv:Fault里面的xml元素没有xmlns。这是大多数SOAP错误报告的方式吗?这是一种非标准的做事方式吗?我是否必须完全依赖mitmproxy来调试Web服务的这些问题?

1 个答案:

答案 0 :(得分:7)

您必须创建一个SOAPHandler来拦截SOAP响应/错误。

使用本教程学习如何创建处理程序并将其注册到服务端口:

http://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-client-side/

然后记得覆盖handleFault(SOAPMessageContext)方法来拦截服务器故障。