View Javadoc
1   /*
2    * Copyright 2010 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.platform.camel.ihe.hl7v3;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  import java.util.concurrent.atomic.AtomicInteger;
21  
22  import org.apache.cxf.interceptor.Fault;
23  import org.apache.cxf.message.Message;
24  import org.apache.cxf.phase.AbstractPhaseInterceptor;
25  import org.apache.cxf.phase.Phase;
26  
27  /**
28   * Custom interceptor for testing custom interceptors.
29   * @author Dmytro Rud
30   */
31  public class CustomInterceptor extends AbstractPhaseInterceptor<Message> {
32      private static Map<String, AtomicInteger> map = new HashMap<>();
33      
34      public CustomInterceptor(String id) {
35          super(id, Phase.PRE_PROTOCOL);
36          map.put(id, new AtomicInteger(0));
37      }
38  
39      @Override
40      public void handleMessage(Message message) throws Fault {
41          map.get(getId()).incrementAndGet();
42      }
43  
44      public static int getAt(String key) {
45          return map.get(key).get();
46      }
47      
48      public static void clear() {
49          map.clear();
50      }
51  }