webservice SOAP消息监视或记录

时间:2008-11-21 13:24:03

标签: soap

有人可以告诉我如何捕获客户端和服务器webservice应用程序之间传递的SOAP消息。

我尝试使用这两种工具。 口袋肥皂 http://www.pocketsoap.com/pocketsoap/

的Fiddler http://www.fiddlertool.com/fiddler/

我可能会错过一些设置,但这对我不起作用。

帮助将更受欢迎。

4 个答案:

答案 0 :(得分:5)

尝试tcpmon

soapUI与tcpmon集成,可以为您提供更好的界面。

See also;您也可以尝试使用MS Visual Roundtrip Analyzer分析仪。

答案 1 :(得分:4)

如果您感兴趣,可以在Java中编写一个扩展GenericSOAPHandler类的处理程序,并将输出打印到您喜欢的位置。在这个(简单)的情况下,服务器日志:

@SuppressWarnings("rawtypes")
public class MyHandler extends GenericSOAPHandler {

    private void print(InputStream input, OutputStream out) throws Exception {
        try {
            DocumentBuilder parser;
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            parser = factory.newDocumentBuilder();
            Document document = parser.parse(input);
            Transformer serializer = TransformerFactory.newInstance().newTransformer();
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            serializer.transform(new DOMSource(document), new StreamResult(out));
        } catch (TransformerException e) {
            // A fatal error occurred
            throw new Exception(e);
        }
    }


    @Override
    protected boolean handleInbound(MessageContext msgContext) {
        SOAPMessageContext soapMessageCtx = (SOAPMessageContext) msgContext;
        SOAPMessage soapMessage = soapMessageCtx.getMessage();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            soapMessage.writeTo(outputStream);
            byte[] array = outputStream.toByteArray();
            ByteArrayInputStream inputStream = new ByteArrayInputStream(array);
            System.out.println("SOAP request message:\n");
            print(inputStream, System.out);
        } catch (SOAPException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

    @Override
    protected boolean handleOutbound(MessageContext msgContext) {
        SOAPMessageContext soapMessageCtx = (SOAPMessageContext) msgContext;
        SOAPMessage soapMessage = soapMessageCtx.getMessage();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            soapMessage.writeTo(outputStream);
            byte[] array = outputStream.toByteArray();
            ByteArrayInputStream inputStream = new ByteArrayInputStream(array);
            System.out.println("SOAP response message:\n");
            print(inputStream, System.out);
        } catch (SOAPException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

}

您还需要确保您的处理程序包含在服务器实现的jaxws-handlers-server.xml中:

<handler-chains xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee javaee_web_services_1_2.xsd">
   <handler-chain>
      <protocol-bindings>##SOAP11_HTTP</protocol-bindings>
      <handler>
         <handler-name>DebugHandler</handler-name>
         <handler-class>handlers.MyHandler</handler-class>
      </handler>
   </handler-chain>
</handler-chains>

答案 2 :(得分:1)

这里是我在C ++中的代码,用于在发送之前使用Soap Toolkit 3.0检索xml消息。

.
.
.
   Serializer->EndEnvelope();
/* ___________________ */

    char * bufferxml = NULL;

   _variant_t punt = _variant_t((IUnknown*)Serializer);
   punt.lVal += 48;
   _variant_t punt1 = *punt.ppunkVal;
   punt1.lVal += 32;
   _variant_t punt2 = *punt1.ppunkVal;
   punt2.lVal += 4;
   memcpy(&bufferxml, (char *) *punt2.ppunkVal, sizeof(char *));

   punt2.lVal += 4;
   int lengxml = *(punt2.pintVal);
   bufferxml[lengxml] = '\0';
/* ___________________ */

  // Send the message to the web service
    Connector->EndMessage();      
.
.
.
   punt.Detach();
   punt1.Detach();
   punt2.Detach();
   punt.Clear();
   punt1.Clear();
   punt2.Clear();

   Serializer.Release();
.
.
.

我希望真的能帮助你,这是我的设计,它对我有用。

答案 3 :(得分:0)

还有用于eclipse的WTP插件捆绑的TCP / IP Monitor,它允许您在端口上设置监视器以查看SOAP请求。