View Javadoc
1   /*
2    * Copyright 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  package org.openehealth.ipf.commons.ihe.ws.cxf;
17  
18  import org.apache.cxf.binding.soap.Soap12;
19  import org.apache.cxf.binding.soap.SoapMessage;
20  import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
21  import org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor;
22  import org.apache.cxf.interceptor.Fault;
23  import org.apache.cxf.message.Message;
24  import org.apache.cxf.phase.Phase;
25  
26  import java.util.regex.Pattern;
27  
28  /**
29   * According to ITI TF CP-510, SOAP Action should be ignored.
30   * CXF contains a direct contradiction to this requirement —
31   * see <a href="https://issues.apache.org/jira/browse/CXF-3791">CXF-3791</a>.
32   * <p>
33   * This interceptor simply deletes the SOAP action from HTTP Content-Type header
34   * and is intended for incoming chains on both client and server sides.
35   *
36   * @see SoapActionInInterceptor
37   * @see <a href="http://www.w3.org/TR/2003/REC-soap12-part2-20030624/#ietf-action">SOAP 1.2 specification</a>
38   *
39   * @author Dmytro Rud
40   */
41  public class Cxf3791WorkaroundInterceptor extends AbstractSoapInterceptor {
42      static final Pattern PATTERN = Pattern.compile(";\\s*action\\s*=\\s*(\"?)[\\S&&[^\"]]+(\\1)\\s*");
43  
44      public Cxf3791WorkaroundInterceptor() {
45          super(Phase.READ);
46          addBefore(SoapActionInInterceptor.class.getName());
47      }
48  
49      @Override
50      public void handleMessage(SoapMessage message) throws Fault {
51          if (message.getVersion() instanceof Soap12) {
52              String s = (String) message.get(Message.CONTENT_TYPE);
53              if (s != null) {
54                  s = PATTERN.matcher(s).replaceFirst("");
55                  message.put(Message.CONTENT_TYPE, s);
56              }
57          }
58      }
59  }