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.deferredresponse;
17  
18  import org.apache.camel.Exchange;
19  import org.apache.cxf.jaxws.context.WrappedMessageContext;
20  import org.apache.cxf.ws.addressing.AddressingProperties;
21  import org.apache.cxf.ws.addressing.RelatesToType;
22  import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset;
23  import org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3WsTransactionConfiguration;
24  import org.openehealth.ipf.commons.ihe.hl7v3.iti55.asyncresponse.Iti55DeferredResponsePortType;
25  import org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory;
26  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.AbstractAuditInterceptor;
27  import org.openehealth.ipf.commons.ihe.ws.cxf.audit.WsAuditDataset;
28  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsEndpoint;
29  import org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsProducer;
30  
31  import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES;
32  
33  /**
34   * @author Dmytro Rud
35   */
36  public class Iti55DeferredResponseProducer extends AbstractWsProducer<Hl7v3AuditDataset, Hl7v3WsTransactionConfiguration, String, String> {
37  
38      public Iti55DeferredResponseProducer(AbstractWsEndpoint<Hl7v3AuditDataset, Hl7v3WsTransactionConfiguration> endpoint,
39                                           JaxWsClientFactory<Hl7v3AuditDataset> clientFactory) {
40          super(endpoint, clientFactory, String.class, String.class);
41      }
42  
43  
44      @Override
45      protected void enrichRequestContext(Exchange exchange, WrappedMessageContext requestContext) {
46          // NB: Camel message headers used here are set in Iti55Service's intern Callable.
47  
48          // propagate WS-Addressing request message ID
49          String requestMessageId = exchange.getIn().getHeader("iti55.deferred.requestMessageId", String.class);
50          if (requestMessageId != null) {
51              RelatesToType relatesToHolder = new RelatesToType();
52              relatesToHolder.setValue(requestMessageId);
53              AddressingProperties apropos = new AddressingProperties();
54              apropos.setRelatesTo(relatesToHolder);
55              requestContext.put(CLIENT_ADDRESSING_PROPERTIES, apropos);
56          }
57  
58          // inject audit dataset
59          WsAuditDataset auditDataset = exchange.getIn().getHeader("iti55.deferred.auditDataset", WsAuditDataset.class);
60          if (auditDataset != null) {
61              requestContext.put(AbstractAuditInterceptor.DATASET_CONTEXT_KEY, auditDataset);
62          }
63      }
64  
65  
66      @Override
67      protected String callService(Object client, String responseString) throws Exception {
68          return ((Iti55DeferredResponsePortType) client).receiveDeferredResponse(responseString);
69      }
70  }