开发者

Trace SOAP request/responses with JAX-WS on the client side

I'm using JAX-WS reference implementation (2.1.7) and I want to trace SOAP request/responses on the client side. Actually, what I need is to examine some Http headers when I receive the response.

Following these previous questions ( Tracing XML request/responses with JAX-WS and Java JAX-WS web-service client: how log request & response xml? ), I've created my own handler to log when I send a request and receive a response:

public class SHandler implements SOAPHandler<SOAPMessageContext>
{

  private static final Logger log = Logger.getLogger(SHandler.class);

  @Nullable
  @Override
  public Set<QName> getHeaders()
  {    
    log.debug(">>>>>>>>>>> GetHeaders");
    return null;    
  }

  @Override
  public boolean handleMessage(SOAPMessageContext soapMessageContext)
  {
    log.debug(">>>>>>>>>>> HandleMessage");
    return true;
  }

  @Override
  public boolean handleFault(SOAPMessageContext soapMessageContext)
  {
    log.debug(">>>>>>>>>>> HandleFault");
    return true;
  }

  @Override
  public void close(MessageContext messageContext)
  {
    log.debug(">>>>>>>>>>> Close");    
  }
}

and I add the handler to the handler chain during the service initialisation:

@WebServiceClient(name = "MyService", targetNamespace = "http://www.whatever.com/", wsdlLocation = "file:/path/to/wsdl")
public class MyService extends Service
{

    public MyService(URL wsdlLocation) {
        super(...);
        initializeBinding();
    }

    @WebEndpoint(name = "MyOperation")
    public MyPort getMyPort() {
        return super.getPort(new QName("http://www.whatever.com/", "MyPort"), MyPort.class);
    }

    private void initializeBinding() {        
        MyPort port = getMyPort();
        BindingProvider bindingProvider = ((BindingProvider) port);
        List handlerChain = bindingProvider.getBinding().getHandlerChain();
        handlerChain.add(new SHandler());
        bindingProvider.getBinding().setHandlerChain(handlerChain);        
    }

    ...

}

The problem is that this doesn't work at all on the client side. I don't see any logs and my handler is never executed when I send a request and receive a response.

Notice that there is no sp开发者_StackOverflowecific WSDL related to this issue because I work on an MDA platform that generates client/server artifacts from any WSDL. In addition, I cannot do this at configuration level as all is generated, so I can only do it programmatically (I've been googling this and all the solutions that I find are either the one in the original post or using the handler-chain.xml configuration file).

Am I missing something? Is there any other way of doing this?

Thanks in advance.


If you only want to look at the SOAP messages run with

-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true

VM argument.


Why not use @HandlerChain(file = "....") annotation?

From my pov, you can not mix constructor- and annotation-based configurations as on-deploy webservice initialization and creating new instance of your service class are performed in absolutely different contexts.


there are 2 tools that you can use to help with this:

  • soapui
  • Eclipse tcp/ip monitor

Both tools offer a proxy mode, which intercepts, logs and forwards requests and responses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜