View Javadoc
1   /*
2    * Copyright 2011 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.iti55;
17  
18  import groovy.util.slurpersupport.GPathResult;
19  import org.apache.camel.Exchange;
20  import org.apache.cxf.jaxws.context.WrappedMessageContext;
21  import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset;
22  import org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils;
23  import org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3WsTransactionConfiguration;
24  import org.openehealth.ipf.commons.ihe.hl7v3.iti55.Iti55PortType;
25  import org.openehealth.ipf.commons.ihe.hl7v3.iti55.Iti55Utils;
26  import org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory;
27  import org.openehealth.ipf.commons.ihe.ws.correlation.AsynchronyCorrelator;
28  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsEndpoint;
29  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsProducer;
30  
31  import javax.xml.ws.BindingProvider;
32  import java.util.Map;
33  
34  /**
35   * Camel producer for the ITI-55 XCPD transaction
36   * with support of the Deferred Response option.
37   * @author Dmytro Rud
38   */
39  class Iti55Producer extends AbstractWsProducer<Hl7v3AuditDataset, Hl7v3WsTransactionConfiguration, String, String> {
40      private static final String PROCESSING_MODE_PROPERTY = Iti55Producer.class.getName() + ".MODE";
41  
42      Iti55Producer(AbstractWsEndpoint<Hl7v3AuditDataset, Hl7v3WsTransactionConfiguration> endpoint, JaxWsClientFactory<Hl7v3AuditDataset> clientFactory) {
43          super(endpoint, clientFactory, String.class, String.class);
44      }
45  
46  
47      @Override
48      protected void enrichRequestContext(Exchange exchange, WrappedMessageContext requestContext) {
49          String requestString = exchange.getIn().getBody(String.class);
50          GPathResult requestXml = Hl7v3Utils.slurp(requestString);
51          String processingMode = Iti55Utils.processingMode(requestXml);
52  
53          if ("D".equals(processingMode)) {
54              if (exchange.getIn().getHeader(AbstractWsEndpoint.WSA_REPLYTO_HEADER_NAME, String.class) != null) {
55                  throw new RuntimeException("WS-Addressing asynchrony cannot be combined with the Deferred Response option");
56              }
57              if (Iti55Utils.deferredResponseUri(requestXml) == null) {
58                  throw new RuntimeException("missing deferred response URI in the request");
59              }
60              requestContext.put(AsynchronyCorrelator.FORCE_CORRELATION, Boolean.TRUE);
61          }
62          requestContext.put(PROCESSING_MODE_PROPERTY, processingMode);
63      }
64  
65  
66      @Override
67      protected String callService(Object client, String request) {
68          BindingProvider bindingProvider = (BindingProvider) client;
69          Map<String, Object> requestContext = bindingProvider.getRequestContext();
70  
71          return ("D".equals(requestContext.get(PROCESSING_MODE_PROPERTY))) ?
72              ((Iti55PortType) client).discoverPatientsDeferred(request) :
73              ((Iti55PortType) client).discoverPatients(request);
74      }
75  
76  
77      @Override
78      protected String[] getAlternativeRequestKeys(Exchange exchange) {
79          String requestString = exchange.getIn().getBody(String.class);
80          GPathResult requestXml = Hl7v3Utils.slurp(requestString);
81          return new String[] { Iti55Utils.requestQueryId(requestXml) };
82      }
83  
84  }