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.commons.ihe.hl7v3;
17  
18  import org.apache.cxf.endpoint.Client;
19  import org.apache.cxf.feature.AbstractFeature;
20  import org.apache.cxf.interceptor.InterceptorProvider;
21  import org.openehealth.ipf.commons.audit.AuditContext;
22  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategy;
23  import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset;
24  import org.openehealth.ipf.commons.ihe.ws.JaxWsRequestClientFactory;
25  import org.openehealth.ipf.commons.ihe.ws.correlation.AsynchronyCorrelator;
26  import org.openehealth.ipf.commons.ihe.ws.cxf.databinding.plainxml.PlainXmlDataBinding;
27  import org.openehealth.ipf.commons.ihe.ws.cxf.payload.InNamespaceMergeInterceptor;
28  import org.openehealth.ipf.commons.ihe.ws.cxf.payload.InPayloadExtractorInterceptor;
29  import org.openehealth.ipf.commons.ihe.ws.cxf.payload.InPayloadInjectorInterceptor;
30  
31  import java.util.List;
32  import java.util.Map;
33  
34  import static org.openehealth.ipf.commons.ihe.ws.cxf.payload.StringPayloadHolder.PayloadType.SOAP_BODY;
35  
36  /**
37   * Factory for HL7 v3 Web Service clients.
38   * @author Dmytro Rud
39   */
40  public class Hl7v3ClientFactory extends JaxWsRequestClientFactory<Hl7v3AuditDataset> {
41  
42      /**
43       * Constructs the factory.
44       * @param wsTransactionConfiguration
45       *          the info about the Web Service.
46       * @param serviceUrl
47       *          the URL of the Web Service.
48       * @param auditStrategy
49       *          the audit strategy to use.
50       * @param correlator
51       *          optional asynchrony correlator.
52       * @param customInterceptors
53       *          user-defined custom CXF interceptors.
54       */
55      public Hl7v3ClientFactory(
56              Hl7v3WsTransactionConfiguration wsTransactionConfiguration,
57              String serviceUrl,
58              AuditStrategy<Hl7v3AuditDataset> auditStrategy,
59              AuditContext auditContext,
60              InterceptorProvider customInterceptors,
61              List<AbstractFeature> features,
62              Map<String, Object> properties,
63              AsynchronyCorrelator<Hl7v3AuditDataset> correlator)
64      {
65          super(wsTransactionConfiguration, serviceUrl, auditStrategy, auditContext,
66                  customInterceptors, features, properties, correlator);
67      }
68  
69      @Override
70      protected void configureInterceptors(Client client) {
71          super.configureInterceptors(client);
72  
73          client.getInInterceptors().add(new InPayloadExtractorInterceptor(SOAP_BODY));
74          client.getInInterceptors().add(new InNamespaceMergeInterceptor());
75          client.getInInterceptors().add(new InPayloadInjectorInterceptor(0));
76          client.getEndpoint().getService().setDataBinding(new PlainXmlDataBinding());
77      }
78  }