ServerSOAPFaultException and how to read it?

笑着哭i 提交于 2020-01-23 05:21:30

问题


I did a request and my program spit out

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)
    ....

I see via mitmproxy that the server sent back

<?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>

How do I read the first bit and get the details in the second bit? I don't have access to the server log, as in, the log on the server that hosts the web service.

I notice that the xml elements inside of soapenv:Fault don't have an xmlns. Is this how most SOAP errors are reported back? Is this a nonstandard way to do things? Am I going to have to rely completely on mitmproxy to debug these kinds of problems with web services?


回答1:


You must create a SOAPHandler to intercept the SOAP response/fault.

Use this tutorial to learn how to create an handler and register it to the service port:

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

Then remember to override the handleFault(SOAPMessageContext) method to intercept server faults.



来源:https://stackoverflow.com/questions/25750446/serversoapfaultexception-and-how-to-read-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!