View Javadoc
1   /*
2    * Copyright 2017 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.ws;
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.ws.correlation.AsynchronyCorrelator;
24  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.AuditOutRequestInterceptor;
25  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.AuditResponseInterceptor;
26  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.WsAuditDataset;
27  
28  import java.util.List;
29  import java.util.Map;
30  
31  /**
32   * Factory for ITI Web Service stubs.
33   */
34  public class JaxWsRequestClientFactory<AuditDatasetType extends WsAuditDataset> extends JaxWsClientFactory<AuditDatasetType> {
35  
36      public JaxWsRequestClientFactory(
37              WsTransactionConfiguration<AuditDatasetType> wsTransactionConfiguration,
38              String serviceUrl,
39              AuditStrategy<AuditDatasetType> auditStrategy,
40              AuditContext auditContext,
41              InterceptorProvider customInterceptors,
42              List<AbstractFeature> features,
43              Map<String, Object> properties,
44              AsynchronyCorrelator<AuditDatasetType> correlator)
45      {
46          super(wsTransactionConfiguration, serviceUrl, auditStrategy, auditContext,
47                  customInterceptors, features, properties, correlator);
48      }
49  
50      @Override
51      protected void configureInterceptors(Client client) {
52          super.configureInterceptors(client);
53  
54          // install auditing-related interceptors if the user has not switched auditing off
55          if (auditStrategy != null) {
56              if (wsTransactionConfiguration.isAuditRequestPayload()) {
57                  installPayloadInterceptors(client);
58              }
59  
60              client.getOutInterceptors().add(new AuditOutRequestInterceptor<>(
61                      auditStrategy, auditContext, correlator, getWsTransactionConfiguration()));
62  
63              AuditResponseInterceptor<AuditDatasetType> auditInterceptor =
64                      new AuditResponseInterceptor<>(auditStrategy, auditContext, false, correlator, false);
65              client.getInInterceptors().add(auditInterceptor);
66              client.getInFaultInterceptors().add(auditInterceptor);
67          }
68      }
69  }