1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
36
37
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 }