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.hl7v3;
17  
18  import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset;
19  import org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3ClientFactory;
20  import org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3ContinuationAwareWsTransactionConfiguration;
21  import org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3ServiceFactory;
22  import org.openehealth.ipf.commons.ihe.hl7v3.storage.Hl7v3ContinuationStorage;
23  import org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory;
24  import org.openehealth.ipf.commons.ihe.ws.JaxWsServiceFactory;
25  import org.openehealth.ipf.commons.ihe.ws.WsInteractionId;
26  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsComponent;
27  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsEndpoint;
28  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsProducer;
29  
30  import java.util.Map;
31  
32  /**
33   * Camel endpoint implementation for HL7v3-based IHE components
34   * with interactive response continuation support.
35   *
36   * @author Dmytro Rud
37   */
38  public class Hl7v3ContinuationAwareEndpoint
39          extends Hl7v3Endpoint<Hl7v3ContinuationAwareWsTransactionConfiguration> {
40      /**
41       * Whether this endpoint should support HL7v3 continuation.
42       */
43      private boolean supportContinuation = false;
44  
45      /**
46       * Producer-side only: Whether a "cancel continuation" message should
47       * be automatically sent to the server when all continuation fragments
48       * have been read.
49       */
50      private boolean autoCancel = false;
51  
52      /**
53       * Consumer-side only: Default count of data records in the first
54       * response fragment, when the request does not contain "initialQuantity"
55       * element.  Negative values mean "no continuation, when initialQuantity
56       * is not specified".
57       */
58      private int defaultContinuationThreshold = -1;
59  
60      /**
61       * Consumer-side only: Storage bean for continuation fragments.
62       */
63      private Hl7v3ContinuationStorage continuationStorage = null;
64  
65      /**
66       * Whether the system should validate messages which are internally handled
67       * when performing HL7v3 interactive continuation.
68       */
69      private boolean validationOnContinuation = false;
70  
71  
72      protected Hl7v3ContinuationAwareEndpoint(
73              String endpointUri,
74              String address,
75              AbstractWsComponent<Hl7v3AuditDataset, Hl7v3ContinuationAwareWsTransactionConfiguration, ? extends WsInteractionId<Hl7v3ContinuationAwareWsTransactionConfiguration>> component,
76              Map<String, Object> parameters) {
77          super(endpointUri, address, component, parameters, null);
78      }
79  
80      @Override
81      public AbstractWsProducer<Hl7v3AuditDataset,Hl7v3ContinuationAwareWsTransactionConfiguration, ?, ?> getProducer(AbstractWsEndpoint<Hl7v3AuditDataset,Hl7v3ContinuationAwareWsTransactionConfiguration> endpoint, JaxWsClientFactory<Hl7v3AuditDataset> clientFactory) {
82          return new Hl7v3ContinuationAwareProducer(this, getJaxWsClientFactory());
83      }
84  
85      /**
86       * Returns <code>true</code> when this endpoint supports HL7v3 continuation.
87       */
88      public boolean isSupportContinuation() {
89          return supportContinuation;
90      }
91  
92      public void setSupportContinuation(boolean supportContinuation) {
93          this.supportContinuation = supportContinuation;
94      }
95  
96      /**
97       * Returns default count of data records to be sent in the first response
98       * fragment, when the request does not contain "initialQuantity" element.
99       * Negative values mean "no continuation, when initialQuantity is not
100      * specified".
101      * <p/>
102      * This parameter is relevant only on consumer side.
103      */
104     public int getDefaultContinuationThreshold() {
105         return defaultContinuationThreshold;
106     }
107 
108     public void setDefaultContinuationThreshold(int defaultContinuationThreshold) {
109         this.defaultContinuationThreshold = defaultContinuationThreshold;
110     }
111 
112     /**
113      * Returns storage bean for continuation fragments.
114      * <p/>
115      * This parameter is relevant only on consumer side.
116      */
117     public Hl7v3ContinuationStorage getContinuationStorage() {
118         return continuationStorage;
119     }
120 
121     public void setContinuationStorage(Hl7v3ContinuationStorage continuationStorage) {
122         this.continuationStorage = continuationStorage;
123     }
124 
125     /**
126      * Returns <code>true</code> when a "cancel continuation" message should
127      * be automatically sent to the server after all continuation fragments
128      * have been read.
129      * <p/>
130      * This parameter is relevant only on producer side.
131      */
132     public boolean isAutoCancel() {
133         return autoCancel;
134     }
135 
136     public void setAutoCancel(boolean autoCancel) {
137         this.autoCancel = autoCancel;
138     }
139 
140     /**
141      * @return <code>true</code> when messages, which are internally handled
142      * when performing HL7v3 interactive continuation, should be validated.
143      */
144     public boolean isValidationOnContinuation() {
145         return validationOnContinuation;
146     }
147 
148     public void setValidationOnContinuation(boolean validationOnContinuation) {
149         this.validationOnContinuation = validationOnContinuation;
150     }
151 
152 
153     /**
154      * @return <code>true</code> if ATNA audit strategies must be manually applied
155      * in Camel producer and consumer instead of CXF interceptors.
156      * This will be the case when interactive response continuation is supported.
157      */
158     public boolean isManualAudit() {
159         return (isAudit() && isSupportContinuation());
160     }
161 
162 
163     @Override
164     public JaxWsClientFactory<Hl7v3AuditDataset> getJaxWsClientFactory() {
165         return new Hl7v3ClientFactory(
166                 getComponent().getWsTransactionConfiguration(),
167                 getServiceUrl(),
168                 isManualAudit() ? null : getComponent().getClientAuditStrategy(),
169                 getAuditContext(),
170                 getCustomInterceptors(),
171                 getFeatures(),
172                 getProperties(),
173                 getCorrelator());
174     }
175 
176 
177     @Override
178     public JaxWsServiceFactory<Hl7v3AuditDataset> getJaxWsServiceFactory() {
179         return new Hl7v3ServiceFactory(
180                 getComponent().getWsTransactionConfiguration(),
181                 getServiceAddress(),
182                 isManualAudit() ? null : getComponent().getServerAuditStrategy(),
183                 getAuditContext(),
184                 getCustomInterceptors(),
185                 getRejectionHandlingStrategy());
186     }
187 }