1 /*
2 * Copyright 2006 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 public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
49 if (logFault && logger.isDebugEnabled()) {
50 logMessageSource("Fault: ", getSource(messageContext.getResponse()));
51 }
52 return true;
53 }
54
55 public boolean understands(SoapHeaderElement header) {
56 return false;
57 }
58
59 protected Source getSource(WebServiceMessage message) {
60 if (message instanceof SoapMessage) {
61 SoapMessage soapMessage = (SoapMessage) message;
62 return soapMessage.getEnvelope().getSource();
63 }
64 else {
65 return null;
66 }
67 }
68 }