0

I'm writing web service with Spring WS. And I have to log all requests and responses. If message is syntactically correct logging is taken care by SoapEnvelopeLoggingInterceptor.

Unfortunately some requests to web service might be syntactically incorrect, for example:

<?xml version="1.0" encoding="UTF-8"?>
<Message>
    <foo>Hello, </foo>
    <!-- > symbol is missing: -->
    <bar>World!</bar
</Message>

When this message is sent to my service, the server refuses to accept it by saying: "The request sent by the client was syntactically incorrect".

Maybe someone could give me a hint about how to log syntactically incorrect messages?

5
  • 1
    Don't. Get the producer to fix it. It's not your problem. Your problem is to process correct requests.
    – user207421
    Nov 12, 2013 at 8:56
  • Yes, I explained the same thing. Unfortunately there is a requirement to log everything... Nov 12, 2013 at 8:58
  • You don't have to parse things to log them. Just log the raw data.
    – user207421
    Nov 12, 2013 at 9:08
  • Could you please provide code example? Because it would be very helpful. Nov 12, 2013 at 9:10
  • 1
    I'd still agree with @EJP's first point. The problem is with the client, not the service. If the client fires incorrectly formed XML at the service, there is a bug in their code, which needs to be fixed.
    – Steve
    Nov 12, 2013 at 9:11

2 Answers 2

1

Invalid SOAP requests will not reach your web service methods, however when it comes to SOAP, the responsibility is with the client to send valid requests. If they don't there is a bug in their code, not yours.

However, if you wish to log invalid requests, then you could use Log4J (or whatever logging framework you have hooked in) to do it. If you take a look at the SoapEnvelopeLoggingInterceptor code, you will see that it implements debug-level logging of SOAP faults.

https://github.com/spring-projects/spring-ws/blob/master/core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/SoapEnvelopeLoggingInterceptor.java?source=cc

public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
    if (logFault && logger.isDebugEnabled()) {
        logMessageSource("Fault: ", getSource(messageContext.getResponse()));
    }
    return true;
}

So by configuring things to log SOAP faults in their own file, you could have some kind of audit of failed requests. You could even monitor that file so that any entries in it would cause alerts.

<appender name="soapFaultAppender" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="/var/log/myapp/soap-faults.log" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %p [%c{3}] %m%n" />
    </layout>
</appender>
<appender name="async" class="org.apache.log4j.AsyncAppender">
    <param name="BufferSize" value="1024"/> 
    <appender-ref ref="soapFaultAppender"/>
</appender>
<logger name="org.springframework.ws.soap.server.endpoint.interceptor">
    <level value="debug" />
</logger>
3
  • Hopefully that's correct. I'm not totally sure that all invalid requests would raise SOAP faults rather than some other exception.
    – Steve
    Nov 12, 2013 at 9:23
  • They wouldn't. A syntax error could raise anything from an HTTP 500 on.
    – user207421
    Nov 12, 2013 at 9:49
  • 1
    Well if you find any invalid message constructions which don't get picked up by the logging interceptor, you just take a look at what raised them and hunt for where Spring logs them, and set their logging level to debug. Rinse and repeat.
    – Steve
    Nov 12, 2013 at 11:13
0

I'd think about putting a filter into your application stack to handle the logging for you. I think you'd lose the ability to use your SoapEnvelopeLoggingInterceptor, but you'd be dealing with the message before your application has decided that it's only interested in correctly formatted XML messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.