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.frontend.ServerFactoryBean;
19  import org.apache.cxf.interceptor.InterceptorProvider;
20  import org.openehealth.ipf.commons.audit.AuditContext;
21  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategy;
22  import org.openehealth.ipf.commons.ihe.ws.cxf.WsRejectionHandlingStrategy;
23  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.AuditInRequestInterceptor;
24  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.AuditResponseInterceptor;
25  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.WsAuditDataset;
26  import org.openehealth.ipf.commons.ihe.ws.cxf.payload.InPayloadExtractorInterceptor;
27  
28  import static org.openehealth.ipf.commons.ihe.ws.cxf.payload.StringPayloadHolder.PayloadType.SOAP_BODY;
29  
30  /**
31   * Factory for Web Services serving requests
32   */
33  public class JaxWsRequestServiceFactory<AuditDatasetType extends WsAuditDataset> extends JaxWsServiceFactory<AuditDatasetType> {
34  
35      public JaxWsRequestServiceFactory(
36              WsTransactionConfiguration<AuditDatasetType> wsTransactionConfiguration,
37              String serviceAddress,
38              AuditStrategy<AuditDatasetType> auditStrategy,
39              AuditContext auditContext,
40              InterceptorProvider customInterceptors,
41              WsRejectionHandlingStrategy rejectionHandlingStrategy)
42      {
43          super(wsTransactionConfiguration, serviceAddress, auditStrategy, auditContext, customInterceptors, rejectionHandlingStrategy);
44      }
45  
46      protected void configureInterceptors(ServerFactoryBean svrFactory) {
47          super.configureInterceptors(svrFactory);
48  
49          // install auditing-related interceptors if the user has not switched auditing off
50          if (auditStrategy != null) {
51              if (wsTransactionConfiguration.isAuditRequestPayload()) {
52                  svrFactory.getInInterceptors().add(new InPayloadExtractorInterceptor(SOAP_BODY));
53              }
54  
55              svrFactory.getInInterceptors().add(new AuditInRequestInterceptor<>(
56                      auditStrategy, auditContext, wsTransactionConfiguration));
57  
58              AuditResponseInterceptor<AuditDatasetType> auditInterceptor =
59                      new AuditResponseInterceptor<>(auditStrategy, auditContext, true, null, false);
60              svrFactory.getOutInterceptors().add(auditInterceptor);
61              svrFactory.getOutFaultInterceptors().add(auditInterceptor);
62          }
63      }
64  
65  }