View Javadoc
1   /*
2    * Copyright 2009 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.hl7v2.intercept;
17  
18  import ca.uhn.hl7v2.model.Message;
19  import org.apache.camel.Exchange;
20  import org.openehealth.ipf.commons.ihe.hl7v2.Hl7v2TransactionConfiguration;
21  import org.openehealth.ipf.platform.camel.core.util.Exchanges;
22  import org.openehealth.ipf.platform.camel.ihe.core.InterceptorSupport;
23  import org.openehealth.ipf.platform.camel.ihe.hl7v2.HL7v2Endpoint;
24  
25  
26  /**
27   * Generic functionality for HL7v2 acceptance checking interceptors.
28   * @author Dmytro Rud
29   */
30  public class AcceptanceInterceptorUtils {
31  
32      private AcceptanceInterceptorUtils() {
33          throw new IllegalStateException("Helper class");
34      }
35  
36      
37      /**
38       * Checks acceptance of the input message and calls the route.
39       */
40      public static void processRequest(
41              InterceptorSupport<HL7v2Endpoint> interceptor,
42              Exchange exchange) throws Exception
43      {
44          // check input message
45          Hl7v2TransactionConfiguration config = interceptor.getEndpoint().getHl7v2TransactionConfiguration();
46          config.checkRequestAcceptance(exchange.getIn().getBody(Message.class));
47          
48          // run the route
49          interceptor.getWrappedProcessor().process(exchange);
50      }
51      
52      
53      /**
54       * Calls the route and checks acceptance of the output message.
55       */
56      public static void processResponse(
57              InterceptorSupport<HL7v2Endpoint> interceptor,
58              Exchange exchange) throws Exception 
59      {
60          // run the route
61          interceptor.getWrappedProcessor().process(exchange);
62  
63          // check output message
64          Hl7v2TransactionConfiguration config = interceptor.getEndpoint().getHl7v2TransactionConfiguration();
65          config.checkResponseAcceptance(Exchanges.resultMessage(exchange).getBody(Message.class));
66      }
67  }