1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.platform.camel.ihe.fhir.core.intercept.producer;
18
19 import ca.uhn.fhir.rest.client.api.IClientInterceptor;
20 import ca.uhn.fhir.rest.client.api.IHttpRequest;
21 import ca.uhn.fhir.rest.client.api.IHttpResponse;
22 import org.apache.camel.Exchange;
23 import org.openehealth.ipf.platform.camel.ihe.fhir.core.FhirEndpoint;
24 import org.openehealth.ipf.platform.camel.ihe.fhir.core.HapiClientInterceptorFactory;
25
26 import java.io.IOException;
27 import java.util.Map;
28
29 import static org.openehealth.ipf.commons.ihe.core.Constants.*;
30
31
32
33
34
35
36
37
38 public class ProducerTracingInterceptor implements IClientInterceptor, HapiClientInterceptorFactory {
39
40 private final Map<String, Object> headers;
41
42 private ProducerTracingInterceptor(Map<String, Object> headers) {
43 this.headers = headers;
44 }
45
46 @Override
47 public IClientInterceptor newInstance(FhirEndpoint endpoint, Exchange exchange) {
48 return new ProducerTracingInterceptor(exchange.getIn().getHeaders());
49 }
50
51 @Override
52 public void interceptRequest(IHttpRequest request) {
53 if (headers.containsKey(TRACE_ID)) {
54 request.addHeader(TRACE_ID, headers.get(TRACE_ID).toString());
55 }
56 if (headers.containsKey(SPAN_ID)) {
57 request.addHeader(SPAN_ID, headers.get(SPAN_ID).toString());
58 }
59 if (headers.containsKey(PARENT_SPAN_ID)) {
60 request.addHeader(PARENT_SPAN_ID, headers.get(PARENT_SPAN_ID).toString());
61 }
62 if (headers.containsKey(SAMPLED)) {
63 request.addHeader(SAMPLED, headers.get(SAMPLED).toString());
64 }
65 if (headers.containsKey(FLAGS)) {
66 request.addHeader(FLAGS, headers.get(FLAGS).toString());
67 }
68 }
69
70 @Override
71 public void interceptResponse(IHttpResponse theResponse) throws IOException {
72
73 }
74 }