View Javadoc
1   /*
2    * Copyright 2010 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.ws;
17  
18  import org.apache.camel.impl.DefaultComponent;
19  import org.apache.cxf.feature.AbstractFeature;
20  import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
21  import org.apache.cxf.interceptor.Interceptor;
22  import org.apache.cxf.interceptor.InterceptorProvider;
23  import org.apache.cxf.message.Message;
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.ws.WsInteractionId;
27  import org.openehealth.ipf.commons.ihe.ws.WsTransactionConfiguration;
28  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.WsAuditDataset;
29  import org.openehealth.ipf.platform.camel.ihe.atna.AuditableComponent;
30  import org.openehealth.ipf.platform.camel.ihe.atna.util.AuditConfiguration;
31  
32  import java.util.List;
33  import java.util.Map;
34  
35  /**
36   * Base component class for Web Service-based IHE components.
37   *
38   * @param <AuditDatasetType> audit type
39   * @param <ConfigType>       configuration type
40   * @author Dmytro Rud
41   */
42  abstract public class AbstractWsComponent<
43          AuditDatasetType extends WsAuditDataset,
44          ConfigType extends WsTransactionConfiguration<AuditDatasetType>,
45          InteractionIdType extends WsInteractionId<ConfigType>>
46          extends DefaultComponent implements AuditableComponent<AuditDatasetType> {
47  
48      private final InteractionIdType interactionId;
49  
50      public AbstractWsComponent(InteractionIdType interactionId) {
51          this.interactionId = interactionId;
52      }
53  
54      public InteractionIdType getInteractionId() {
55          return interactionId;
56      }
57  
58      protected InterceptorProvider getCustomInterceptors(Map<String, Object> parameters) {
59          AbstractBasicInterceptorProvider provider = new AbstractBasicInterceptorProvider() {
60          };
61          provider.setInInterceptors(castList(resolveAndRemoveReferenceListParameter(
62                  parameters, "inInterceptors", Interceptor.class)));
63          provider.setInFaultInterceptors(castList(resolveAndRemoveReferenceListParameter(
64                  parameters, "inFaultInterceptors", Interceptor.class)));
65          provider.setOutInterceptors(castList(resolveAndRemoveReferenceListParameter(
66                  parameters, "outInterceptors", Interceptor.class)));
67          provider.setOutFaultInterceptors(castList(resolveAndRemoveReferenceListParameter(
68                  parameters, "outFaultInterceptors", Interceptor.class)));
69          return provider;
70      }
71  
72      protected AuditContext getAuditContext(Map<String, Object> parameters) {
73          return AuditConfiguration.obtainAuditContext(this, parameters);
74      }
75  
76      @SuppressWarnings({"unchecked", "rawtypes"})
77      private List<Interceptor<? extends Message>> castList(
78              List<Interceptor> param) {
79          return (List<Interceptor<? extends Message>>) (List<?>) param;
80      }
81  
82      protected List<AbstractFeature> getFeatures(Map<String, Object> parameters) {
83          return resolveAndRemoveReferenceListParameter(parameters, "features", AbstractFeature.class);
84      }
85  
86      protected List<String> getSchemaLocations(Map<String, Object> parameters) {
87          return resolveAndRemoveReferenceListParameter(parameters, "schemaLocations", String.class);
88      }
89  
90      protected Map<String, Object> getProperties(Map<String, Object> parameters) {
91          List<Map> mapList = resolveAndRemoveReferenceListParameter(parameters, "properties", Map.class);
92          return (mapList != null && mapList.size() == 1) ? mapList.get(0) : null;
93      }
94  
95      @Override
96      public AuditStrategy<AuditDatasetType> getClientAuditStrategy() {
97          return getWsTransactionConfiguration().getClientAuditStrategy();
98      }
99  
100     @Override
101     public AuditStrategy<AuditDatasetType> getServerAuditStrategy() {
102         return getWsTransactionConfiguration().getServerAuditStrategy();
103     }
104 
105     /**
106      * @return static configuration parameters of the Web Service which
107      * server endpoints of this transaction.
108      */
109     public ConfigType getWsTransactionConfiguration() {
110         return interactionId.getWsTransactionConfiguration();
111     }
112 }