1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.ihe.hl7v2.intercept.producer;
17
18 import ca.uhn.hl7v2.model.Message;
19 import org.apache.camel.Exchange;
20 import org.apache.camel.ExchangePattern;
21 import org.apache.commons.lang3.ClassUtils;
22 import org.openehealth.ipf.platform.camel.ihe.core.InterceptorSupport;
23 import org.openehealth.ipf.platform.camel.ihe.hl7v2.HL7v2Endpoint;
24 import org.openehealth.ipf.platform.camel.ihe.hl7v2.Hl7v2AdaptingException;
25 import org.openehealth.ipf.platform.camel.ihe.hl7v2.Hl7v2MarshalUtils;
26
27
28
29
30
31
32
33
34 public class ProducerAdaptingInterceptor extends InterceptorSupport<HL7v2Endpoint> {
35
36 private final String charsetName;
37
38
39
40
41
42
43
44
45
46
47 public ProducerAdaptingInterceptor(String charsetName) {
48 super();
49 this.charsetName = charsetName;
50 }
51
52
53
54
55
56
57
58 public ProducerAdaptingInterceptor() {
59 this(null);
60 }
61
62
63
64
65
66
67 @Override
68 public void process(Exchange exchange) throws Exception {
69 if (charsetName != null) {
70 exchange.setProperty(Exchange.CHARSET_NAME, charsetName);
71 }
72 Message msg = Hl7v2MarshalUtils.extractHapiMessage(
73 exchange.getIn(),
74 characterSet(exchange),
75 getEndpoint().getHl7v2TransactionConfiguration().getParser());
76
77 if (msg == null) {
78 throw new Hl7v2AdaptingException("Cannot create HL7v2 message from the given " +
79 ClassUtils.getSimpleName(exchange.getIn().getBody(), "<null>"));
80 }
81
82 exchange.getIn().setBody(msg);
83 exchange.setPattern(ExchangePattern.InOut);
84
85
86 getWrappedProcessor().process(exchange);
87 }
88 }