View Javadoc
1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.server.endpoint.interceptor;
18  
19  import javax.xml.transform.Source;
20  
21  import org.springframework.ws.WebServiceMessage;
22  import org.springframework.ws.context.MessageContext;
23  import org.springframework.ws.server.endpoint.AbstractLoggingInterceptor;
24  import org.springframework.ws.soap.SoapHeaderElement;
25  import org.springframework.ws.soap.SoapMessage;
26  import org.springframework.ws.soap.server.SoapEndpointInterceptor;
27  
28  /**
29   * SOAP-specific <code>EndpointInterceptor</code> that logs the complete request and response envelope of
30   * <code>SoapMessage</code> messages. By default, request, response and fault messages are logged, but this behaviour
31   * can be changed using the <code>logRequest</code>, <code>logResponse</code>, <code>logFault</code> properties.
32   *
33   * @author Arjen Poutsma
34   * @see #setLogRequest(boolean)
35   * @see #setLogResponse(boolean)
36   * @see #setLogFault(boolean)
37   * @since 1.0.0
38   */
39  public class SoapEnvelopeLoggingInterceptor extends AbstractLoggingInterceptor implements SoapEndpointInterceptor {
40  
41      private boolean logFault = true;
42  
43      /** Indicates whether a SOAP Fault should be logged. Default is <code>true</code>. */
44      public void setLogFault(boolean logFault) {
45          this.logFault = logFault;
46      }
47  
48      @Override
49      public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
50          if (logFault && logger.isDebugEnabled()) {
51              logMessageSource("Fault: ", getSource(messageContext.getResponse()));
52          }
53          return true;
54      }
55  
56      public boolean understands(SoapHeaderElement header) {
57          return false;
58      }
59  
60      @Override
61      protected Source getSource(WebServiceMessage message) {
62          if (message instanceof SoapMessage) {
63              SoapMessage soapMessage = (SoapMessage) message;
64              return soapMessage.getEnvelope().getSource();
65          }
66          else {
67              return null;
68          }
69      }
70  }