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.platform.camel.ihe.hl7v2ws;
17  
18  import org.apache.camel.Consumer;
19  import org.apache.camel.Processor;
20  import org.apache.camel.Producer;
21  import org.apache.cxf.endpoint.Server;
22  import org.apache.cxf.frontend.ServerFactoryBean;
23  import org.openehealth.ipf.commons.ihe.hl7v2.Hl7v2InteractionId;
24  import org.openehealth.ipf.commons.ihe.hl7v2.Hl7v2TransactionConfiguration;
25  import org.openehealth.ipf.commons.ihe.hl7v2.NakFactory;
26  import org.openehealth.ipf.commons.ihe.hl7v2.audit.MllpAuditDataset;
27  import org.openehealth.ipf.commons.ihe.ws.*;
28  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.WsAuditDataset;
29  import org.openehealth.ipf.platform.camel.ihe.core.Interceptor;
30  import org.openehealth.ipf.platform.camel.ihe.core.InterceptorUtils;
31  import org.openehealth.ipf.platform.camel.ihe.hl7v2.HL7v2Endpoint;
32  import org.openehealth.ipf.platform.camel.ihe.hl7v2.intercept.producer.ProducerAdaptingInterceptor;
33  import org.openehealth.ipf.platform.camel.ihe.hl7v2.intercept.producer.ProducerMarshalInterceptor;
34  import org.openehealth.ipf.platform.camel.ihe.hl7v2.intercept.producer.ProducerRequestAcceptanceInterceptor;
35  import org.openehealth.ipf.platform.camel.ihe.hl7v2.intercept.producer.ProducerResponseAcceptanceInterceptor;
36  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWebService;
37  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsComponent;
38  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsEndpoint;
39  import org.openehealth.ipf.platform.camel.ihe.ws.DefaultWsConsumer;
40  
41  import java.util.Arrays;
42  import java.util.List;
43  import java.util.Map;
44  
45  /**
46   * Camel endpoint for HL7v2-WS transaction with a single operation.
47   */
48  public abstract class SimpleHl7v2WsEndpoint<
49          ComponentType extends AbstractHl7v2WsComponent>
50          extends AbstractWsEndpoint<WsAuditDataset, WsTransactionConfiguration<WsAuditDataset>> implements HL7v2Endpoint<MllpAuditDataset> {
51  
52      public SimpleHl7v2WsEndpoint(
53              String endpointUri,
54              String address,
55              AbstractWsComponent<WsAuditDataset, WsTransactionConfiguration<WsAuditDataset>, ? extends WsInteractionId<WsTransactionConfiguration<WsAuditDataset>>> component,
56              Map<String, Object> parameters,
57              Class<? extends AbstractWebService> serviceClass) {
58          super(endpointUri, address, component, parameters, serviceClass);
59      }
60  
61      protected List<Interceptor> getProducerInterceptorChain() {
62          return Arrays.asList(
63                  new ProducerMarshalInterceptor(),
64                  new ProducerResponseAcceptanceInterceptor(),
65                  new ProducerRequestAcceptanceInterceptor(),
66                  new ProducerAdaptingInterceptor()
67          );
68      }
69  
70  
71      @Override
72      public Producer createProducer() {
73          return InterceptorUtils.adaptProducerChain(
74                  getProducerInterceptorChain(),
75                  this,
76                  getProducer(this, getJaxWsClientFactory()));
77      }
78  
79  
80      @Override
81      public Consumer createConsumer(Processor processor) {
82          AbstractHl7v2WebService serviceInstance = (AbstractHl7v2WebService) getServiceInstance();
83          serviceInstance.setHl7v2Configuration(this);
84          ServerFactoryBean serverFactory = getJaxWsServiceFactory().createServerFactory(serviceInstance);
85          Server server = serverFactory.create();
86          AbstractWebService service = (AbstractWebService) serverFactory.getServiceBean();
87          return new DefaultWsConsumer<>(this, processor, service, server);
88      }
89  
90  
91      @Override
92      public JaxWsClientFactory<WsAuditDataset> getJaxWsClientFactory() {
93          return new JaxWsRequestClientFactory<>(
94                  getComponent().getWsTransactionConfiguration(),
95                  getServiceUrl(),
96                  null,
97                  getAuditContext(),
98                  getCustomInterceptors(),
99                  getFeatures(),
100                 getProperties(),
101                 null);
102     }
103 
104 
105     @Override
106     public JaxWsServiceFactory<WsAuditDataset> getJaxWsServiceFactory() {
107         return new JaxWsRequestServiceFactory<>(
108                 getComponent().getWsTransactionConfiguration(),
109                 getServiceAddress(),
110                 null,
111                 getAuditContext(),
112                 getCustomInterceptors(),
113                 getRejectionHandlingStrategy());
114     }
115 
116     @SuppressWarnings("unchecked")
117     @Override
118     public ComponentType getComponent() {
119         return (ComponentType) super.getComponent();
120     }
121 
122     @Override
123     public Hl7v2TransactionConfiguration<MllpAuditDataset> getHl7v2TransactionConfiguration() {
124         return getComponent().getHl7v2TransactionConfiguration();
125     }
126 
127     @Override
128     public NakFactory<MllpAuditDataset> getNakFactory() {
129         return getComponent().getNakFactory();
130     }
131 
132     @Override
133     public Hl7v2InteractionId<MllpAuditDataset> getInteractionId() {
134         return getComponent().getInteractionId();
135     }
136 }