View Javadoc

1   /*
2    * Copyright 2005-2011 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.server.endpoint.interceptor;
18  
19  import org.springframework.util.Assert;
20  import org.springframework.ws.WebServiceMessage;
21  import org.springframework.ws.context.MessageContext;
22  import org.springframework.ws.server.EndpointInterceptor;
23  import org.springframework.ws.server.SmartEndpointInterceptor;
24  
25  /**
26   * Implementation of the {@link SmartEndpointInterceptor} interface that delegates to a delegate {@link
27   * EndpointInterceptor}.
28   *
29   * @author Arjen Poutsma
30   * @since 2.0
31   */
32  public class DelegatingSmartEndpointInterceptor implements SmartEndpointInterceptor {
33  
34      private final EndpointInterceptor delegate;
35  
36      /**
37       * Creates a new instance of the {@code DelegatingSmartEndpointInterceptor} with the given delegate.
38       *
39       * @param delegate the endpoint interceptor to delegate to.
40       */
41      public DelegatingSmartEndpointInterceptor(EndpointInterceptor delegate) {
42          Assert.notNull(delegate, "'delegate' must not be null");
43          this.delegate = delegate;
44      }
45  
46      /**
47       * Returns the delegate.
48       * @return the delegate
49       */
50      public EndpointInterceptor getDelegate() {
51          return delegate;
52      }
53  
54      /**
55       * {@inheritDoc}
56       * <p/>
57       * This implementation delegates to {@link #shouldIntercept(WebServiceMessage, Object)}.
58       */
59      public boolean shouldIntercept(MessageContext messageContext, Object endpoint) {
60          WebServiceMessage request = messageContext.getRequest();
61          return request != null && shouldIntercept(request, endpoint);
62      }
63  
64      /**
65       * Indicates whether this interceptor should intercept the given request message.
66       * <p/>
67       * This implementation always returns {@code true}.
68       *
69       * @param request  the request message
70       * @param endpoint chosen endpoint to invoke
71       * @return {@code true} to indicate that this interceptor applies; {@code false} otherwise
72       */
73      protected boolean shouldIntercept(WebServiceMessage request, Object endpoint) {
74          return true;
75      }
76  
77      public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
78          return getDelegate().handleRequest(messageContext, endpoint);
79      }
80  
81      public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
82          return getDelegate().handleResponse(messageContext, endpoint);
83      }
84  
85      public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
86          return getDelegate().handleFault(messageContext, endpoint);
87      }
88  
89      public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) throws Exception {
90          getDelegate().afterCompletion(messageContext, endpoint, ex);
91      }
92  }