Log jax-ws http request and response

后端 未结 1 1725
一个人的身影
一个人的身影 2021-01-18 06:44

I need to log the full http request and response in a JAX-WS WebService call. For the request I need the request headers and the body and for the response, response headers

相关标签:
1条回答
  • 2021-01-18 07:37

    You could also try

        -Dcom.sun.xml.ws.transport.http.HttpAdapter.dump=true
    

    I'm assuming you're providing your web service from within a Java EE application server of some sort (and not from a standalone client). You cannot have access to Java EE infrastructure like HttpServletRequest and HttpServletResponse outside of the context of a web/Java EE container.

    You could try to get your hands on the actual servlet response object (within a web context) with

        HttpServletResponse response = (HttpServletResponse) messageContext.get(SOAPMessageContext.SERVLET_RESPONSE); //messageContext is the SOAPMessageContext
        List<String> responseHeaderNames = (List<String>)response.getHeaderNames();
            for(String headerName : responseHeaderNames){
                 //Do whatever you want with it.
                  }
    

    I seriously doubt that you'll be able to get your hands on the full response headers within a handler though. Your question really intrigued me and I've spent quite some time researching that part. In all the code samples I've seen, Not even the example on the metro site attempt to implement this functionality and I think the reason is simple. As at the point where a handler is invoked, the container may not have enough definitive information to stamp an http header on the outbound message. You might be able to add stuff but that's doubtful as well.

    0 讨论(0)
提交回复
热议问题