View Javadoc
1   /*
2    * Copyright 2016 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.openehealth.ipf.platform.camel.ihe.fhir.iti68;
18  
19  import org.apache.camel.Consumer;
20  import org.apache.camel.Processor;
21  import org.apache.camel.Producer;
22  import org.apache.camel.component.servlet.ServletComponent;
23  import org.apache.camel.component.servlet.ServletEndpoint;
24  import org.openehealth.ipf.commons.audit.AuditContext;
25  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategy;
26  import org.openehealth.ipf.commons.ihe.fhir.iti68.Iti68AuditDataset;
27  import org.openehealth.ipf.platform.camel.ihe.atna.AuditableEndpoint;
28  import org.openehealth.ipf.platform.camel.ihe.atna.AuditableEndpointConfiguration;
29  import org.openehealth.ipf.platform.camel.ihe.core.InterceptableEndpoint;
30  import org.openehealth.ipf.platform.camel.ihe.core.Interceptor;
31  
32  import java.net.URI;
33  import java.net.URISyntaxException;
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * @author Christian Ohr
39   * @since 3.4
40   */
41  public class Iti68Endpoint extends ServletEndpoint
42          implements InterceptableEndpoint<AuditableEndpointConfiguration, Iti68Component>, AuditableEndpoint<Iti68AuditDataset> {
43  
44      private AuditableEndpointConfiguration config;
45  
46      public Iti68Endpoint(String endPointURI, ServletComponent component, URI httpUri) throws URISyntaxException {
47          super(endPointURI, component, httpUri);
48      }
49  
50      void setConfig(AuditableEndpointConfiguration config) {
51          this.config = config;
52      }
53  
54      // Redirect consumer creation to include interceptor chain
55  
56      @Override
57      public Consumer createConsumer(Processor processor) throws Exception {
58          return InterceptableEndpoint.super.createConsumer(processor);
59      }
60  
61      @Override
62      public Consumer doCreateConsumer(Processor processor) throws Exception {
63          return super.createConsumer(processor);
64      }
65  
66  
67      // No producers are ever created
68  
69      @Override
70      public Producer doCreateProducer() throws Exception {
71          return super.createProducer();
72      }
73  
74      @Override
75      public Iti68Component getInterceptableComponent() {
76          return (Iti68Component) getComponent();
77      }
78  
79      @Override
80      public AuditableEndpointConfiguration getInterceptableConfiguration() {
81          return config;
82      }
83  
84      @Override
85      public AuditStrategy<Iti68AuditDataset> getClientAuditStrategy() {
86          return getInterceptableComponent().getClientAuditStrategy();
87      }
88  
89      @Override
90      public AuditStrategy<Iti68AuditDataset> getServerAuditStrategy() {
91          return getInterceptableComponent().getServerAuditStrategy();
92      }
93  
94      @Override
95      public AuditContext getAuditContext() {
96          return getInterceptableConfiguration().getAuditContext();
97      }
98  
99      @Override
100     public List<Interceptor> createInitialConsumerInterceptorChain() {
101         List<Interceptor> initialChain = new ArrayList<>();
102         if (isAudit()) {
103             initialChain.add(new Iti68ConsumerAuditInterceptor(getAuditContext()));
104         }
105         return initialChain;
106     }
107 
108     @Override
109     public List<Interceptor> createInitialProducerInterceptorChain() {
110         // Producers are never created
111         return null;
112     }
113 }