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.SoapMessage;
19  import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
20  import org.apache.cxf.interceptor.Fault;
21  import org.apache.cxf.message.Exchange;
22  import org.apache.cxf.phase.Phase;
23  
24  import static java.util.Objects.requireNonNull;
25  
26  
27  /**
28   * CXF interceptor which sends all rejected CXF exchanges
29   * to the user-defined failure handler.
30   * <p>
31   * Usable in outgoing chains (normal and fault) on server side only.
32   *
33   * @author Dmytro Rud
34   */
35  public class RejectionHandlerInterceptor extends AbstractSoapInterceptor {
36      private final WsRejectionHandlingStrategy strategy;
37  
38      public RejectionHandlerInterceptor(WsRejectionHandlingStrategy strategy) {
39          super(Phase.MARSHAL);
40          requireNonNull(strategy);
41          this.strategy = strategy;
42      }
43  
44  
45      @Override
46      public void handleMessage(SoapMessage message) throws Fault {
47          Exchange exchange = message.getExchange();
48          if (strategy.isRejected(exchange)) {
49              strategy.handleRejectedExchange(exchange);
50          }
51      }
52  }