0

Sorry for multiple edits.Should have reviewed before posting

I am using the getRequest method provided by MessageContext (org.springframework.ws.context.MessageContext) to retrieve the backend soap request in an interceptor that extends ClientInterceptor. This is beind done within handleRequest method. I am fetching this to log the request into a file. When I do this , the security section within the header which has the user id and password is also getting logged. I would like to remove this before logging. Are there any available mechanisms to remove this element or should I manipulate the String in order to take the element out?

@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
                   getPayloadFromSoapMessage((SoapMessage) messageContext.getRequest());
}

protected String getPayloadFromSoapMessage(SoapMessage message) {
    String payload = "Error parsing";
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        message.writeTo(bos);
        payload = bos.toString();
    } catch (IOException e) {
        LOG.error("Error parsing the SoapMessage", e);
    }
    return payload;
}
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • You are making it too complex. Remove your interceptor and simply set `org.springframework.ws.client.MessageTracing.sent` and/or `org.springframework.ws.client.MessageTracing.received` to the `DEBUG` level this will only log the payload if you set it to `TRACE` it will log the whole message. You don't need to do anything with an interceptor as this is already build into the framework. See also http://stackoverflow.com/questions/7109251/how-can-i-make-spring-webservices-log-all-soap-requests – M. Deinum Feb 07 '17 at 06:59
  • Thanks @M.Deinum. I also want to log this into a db. I and trying to send this an async process for logging. Can you please help suggest an approach? – Punter Vicky Feb 07 '17 at 15:41
  • That is not what your initial question was about :). I suggest you take a look at the `WebServiceTemplate` and how the message writing is done there. With DEBUG it only writes the payload (no header) with TRACE is logs the whole SOAP Message. – M. Deinum Feb 07 '17 at 15:55
  • Thanks @M.Deinum. I see I can fetch SoapMessage and SoapHeader from soapmessage. Is there a way to set remove security header by using these objects? I need the header but not the security header – Punter Vicky Feb 07 '17 at 21:08
  • If you remove them you also remove them from the message that isn't what you want. You will have to filter the writing and not remove them from the objects as that will influence further processing. – M. Deinum Feb 08 '17 at 06:46
  • Thanks , I ended up converting it into a document and removed the security header. Please post your answer and I'll accept it. – Punter Vicky Feb 16 '17 at 03:39

0 Answers0