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.soap.server.endpoint.interceptor;
18  
19  import org.springframework.util.Assert;
20  import org.springframework.util.StringUtils;
21  import org.springframework.ws.WebServiceMessage;
22  import org.springframework.ws.server.EndpointInterceptor;
23  import org.springframework.ws.soap.SoapMessage;
24  
25  /**
26   * Implementation of the {@link org.springframework.ws.server.SmartEndpointInterceptor} interface that only intercepts
27   * requests that have a specified soap action.
28   *
29   * @author Arjen Poutsma
30   * @since 2.0
31   */
32  public class SoapActionSmartEndpointInterceptor extends DelegatingSmartSoapEndpointInterceptor {
33  
34      private final String soapAction;
35  
36      public SoapActionSmartEndpointInterceptor(EndpointInterceptor delegate, String soapAction) {
37          super(delegate);
38          Assert.hasLength(soapAction, "soapAction can not be empty");
39          this.soapAction = soapAction;
40      }
41  
42      @Override
43      protected boolean shouldIntercept(WebServiceMessage request, Object endpoint) {
44          if (request instanceof SoapMessage) {
45              String soapAction = ((SoapMessage) request).getSoapAction();
46              if (StringUtils.hasLength(soapAction) && soapAction.charAt(0) == '"' &&
47                      soapAction.charAt(soapAction.length() - 1) == '"') {
48                  soapAction = soapAction.substring(1, soapAction.length() - 1);
49              }
50              return this.soapAction.equals(soapAction);
51          }
52          else {
53              return false;
54          }
55      }
56  }