Registrar solicitud y respuesta http jax-ws

Necesito registrar la solicitud y respuesta http completa en una llamada al servicio web JAX-WS. Para la solicitud, necesito los encabezados de solicitud y el cuerpo, y para la respuesta, encabezados de respuesta y cuerpo.

Después de investigar un poco, he encontrado que puedo obtener esta información con la propiedad:

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

y muestro la información que necesito, pero la descarga en la consola y necesito almacenarla en la base de datos con un ID de solicitud interno.

He intentado implementar un controlador:

public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {

    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outbound) {
            System.out.println("SOAP outbound!!!!!");
            Map<String, List<String>> responseHeaders = (Map<String, List<String>>) context
                    .get(SOAPMessageContext.HTTP_RESPONSE_HEADERS);
            try {
                String headers = getHeaders(responseHeaders);
                System.out.println(headers);
                String body = getBody(context.getMessage());
                System.out.println(body);
            } catch (Exception ex) {
                // TODO: What do I have to do in this case?
            }
        } else {
            System.out.println("SOAP inbound!!!!!");
            Map<String, List<String>> requestHeaders = (Map<String, List<String>>) context
                    .get(SOAPMessageContext.HTTP_REQUEST_HEADERS);
            try {
                String headers = getHeaders(requestHeaders);
                System.out.println(headers);
                String body = getBody(context.getMessage());
                System.out.println(body);
            } catch (Exception ex) {
                // TODO: What do I have to do in this case?
            }
        }
        return true;
    }

    private String getBody(SOAPMessage message) throws SOAPException, IOException {
        OutputStream stream = new ByteArrayOutputStream();
        message.writeTo(stream);
        return stream.toString();
    }

    public String getFullHttpRequest(HttpServletRequest request) throws IOException {
        InputStream in = request.getInputStream();
        String encoding = request.getCharacterEncoding();
        encoding = encoding == null ? "UTF-8" : encoding;
        String body = IOUtils.toString(in, encoding);
        return body;
    }

    private String getHeaders(Map<String, List<String>> headers) throws IOException {
        StringBuffer result = new StringBuffer();
        if (headers != null) {
            for (Entry<String, List<String>> header : headers.entrySet()) {
                if (header.getValue().isEmpty()) {
                    // I don't think this is legal, but let's just dump it,
                    // as the point of the dump is to uncover problems.
                    result.append(header.getValue());
                } else {
                    for (String value : header.getValue()) {
                        result.append(header.getKey() + ": " + value);
                    }
                }
                result.append("\n");
            }
        }
        return result.toString();
    }

}

pero en este caso, puedo obtener los encabezados y el cuerpo de la solicitud http, pero en la respuesta, solo obtengo el cuerpo, los encabezados de respuesta http siempre están vacíos.

¿Alguna idea sobre cómo archivar esto? El objetivo es poder almacenar la solicitud y respuesta http completa en una base de datos.

¡¡Gracias!!

Respuestas a la pregunta(1)

Su respuesta a la pregunta