diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/Constants.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/Constants.java index de8fc52f2b..7f82d31ebc 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/Constants.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/Constants.java @@ -43,7 +43,13 @@ public interface Constants { String HTTP_CLIENT_IP_ADDRESS = "FhirHttpClientIpAddress"; String HTTP_LOCALES = "FhirHttpAcceptLanguage"; String HTTP_USER = "FhirHttpUserPrincipal"; - String HTTP_HEADERS = "FhirHttpHeaders"; + String HTTP_INCOMING_HEADERS = "FhirHttpHeaders"; + String HTTP_OUTGOING_HEADERS = "FhirHttpOutgoingHeaders"; + /** + * @deprecated use {@link #HTTP_INCOMING_HEADERS} instead + */ + @Deprecated + String HTTP_HEADERS = HTTP_INCOMING_HEADERS; String HTTP_X509_CERTIFICATES = "FhirHttpCertificates"; String FHIR_RESOURCE_TYPE_HEADER = "RESOURCE_TYPE_HEADER"; diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java index 8dc60d06bd..6f329f3f96 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java @@ -100,7 +100,7 @@ protected Map enrichParameters(FhirSearchParameters parameters, enriched.put(Constants.HTTP_USER, httpServletRequest.getUserPrincipal()); var headers = extractHttpHeaders(httpServletRequest); - enriched.put(Constants.HTTP_HEADERS, headers); + enriched.put(Constants.HTTP_INCOMING_HEADERS, headers); var cipherSuite = (String) httpServletRequest.getAttribute("javax.servlet.request.cipher_suite"); if (cipherSuite != null) { diff --git a/platform-camel/ihe/fhir/core/src/main/java/org/openehealth/ipf/platform/camel/ihe/fhir/core/FhirProducer.java b/platform-camel/ihe/fhir/core/src/main/java/org/openehealth/ipf/platform/camel/ihe/fhir/core/FhirProducer.java index cb404c0e12..e144c0f962 100644 --- a/platform-camel/ihe/fhir/core/src/main/java/org/openehealth/ipf/platform/camel/ihe/fhir/core/FhirProducer.java +++ b/platform-camel/ihe/fhir/core/src/main/java/org/openehealth/ipf/platform/camel/ihe/fhir/core/FhirProducer.java @@ -19,6 +19,7 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor; import ca.uhn.fhir.rest.gclient.IClientExecutable; +import lombok.extern.slf4j.Slf4j; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.support.DefaultProducer; @@ -28,12 +29,14 @@ import org.openehealth.ipf.platform.camel.core.util.Exchanges; import org.openehealth.ipf.platform.camel.ihe.fhir.core.intercept.producer.HapiClientAuditInterceptor; +import java.util.List; import java.util.Map; /** * @author Christian Ohr * @since 3.1 */ +@Slf4j public class FhirProducer extends DefaultProducer { public FhirProducer(Endpoint endpoint) { @@ -94,6 +97,17 @@ public void process(Exchange exchange) { getClient(exchange), exchange.getIn().getBody(), exchange.getIn().getHeaders()); + + Object httpHeadersObject = exchange.getIn().getHeader(Constants.HTTP_OUTGOING_HEADERS); + if (httpHeadersObject instanceof Map) { + Map> headers = (Map>) httpHeadersObject; + for (Map.Entry> entry : headers.entrySet()) { + for (String value : entry.getValue()) { + executableClient.withAdditionalHeader(entry.getKey(), value); + } + } + } + var result = executableClient.execute(); var resultMessage = Exchanges.resultMessage(exchange); resultMessage.setBody(result); diff --git a/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3Test.java b/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3Test.java index bbbe37f51e..c0e534d729 100644 --- a/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3Test.java +++ b/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3Test.java @@ -35,6 +35,7 @@ import org.openehealth.ipf.platform.camel.ihe.fhir.test.FhirTestContainer; import java.util.List; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -68,6 +69,10 @@ private Exchange send(Object request, String httpMethod) throws Exception { Exchange exchange = new DefaultExchange(camelContext, ExchangePattern.InOut); exchange.getMessage().setBody(request); exchange.getMessage().setHeader(Constants.HTTP_METHOD, httpMethod); + exchange.getMessage().setHeader(Constants.HTTP_OUTGOING_HEADERS, Map.of( + "Authorization", List.of("Bearer d2h5IGFyZSB5b3UgcmVhZGluZyB0aGlzPw=="), + "Header2", List.of("Value1", "Value2", "Value3") + )); exchange = producerTemplate.send("ch-ppq3://localhost:" + DEMO_APP_PORT, exchange); Exception exception = Exchanges.extractException(exchange); if (exception != null) { @@ -113,6 +118,10 @@ public void testUpdate2() throws Exception { .resource(consent) .conditional() .where(Consent.IDENTIFIER.exactly().identifier(createUuid())) + .withAdditionalHeader("Header2", "Value2") + .withAdditionalHeader("Authorization", "Bearer d2h5IGFyZSB5b3UgcmVhZGluZyB0aGlzPw==") + .withAdditionalHeader("Header2", "Value3") + .withAdditionalHeader("Header2", "Value1") .execute(); List auditMessages = auditSender.getMessages(); @@ -126,6 +135,10 @@ public void testDelete1() throws Exception { MethodOutcome methodOutcome = client.delete() .resourceConditionalByType(Consent.class) .where(Consent.IDENTIFIER.exactly().identifier(createUuid())) + .withAdditionalHeader("Header2", "Value2") + .withAdditionalHeader("Authorization", "Bearer d2h5IGFyZSB5b3UgcmVhZGluZyB0aGlzPw==") + .withAdditionalHeader("Header2", "Value3") + .withAdditionalHeader("Header2", "Value1") .execute(); List auditMessages = auditSender.getMessages(); diff --git a/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3TestRouteBuilder.java b/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3TestRouteBuilder.java index b2a47f9756..4e0d09e138 100644 --- a/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3TestRouteBuilder.java +++ b/platform-camel/ihe/fhir/r4/chppqm/src/test/java/org/openehealth/ipf/platform/camel/ihe/fhir/chppqm/chppq3/ChPpq3TestRouteBuilder.java @@ -18,11 +18,13 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import org.apache.camel.builder.RouteBuilder; -import org.hl7.fhir.r4.model.Consent; import org.hl7.fhir.r4.model.IdType; +import static org.junit.jupiter.api.Assertions.*; import org.openehealth.ipf.commons.ihe.fhir.Constants; import org.openehealth.ipf.platform.camel.core.adapter.ValidatorAdapter; +import java.util.List; +import java.util.Map; import java.util.UUID; import static org.openehealth.ipf.platform.camel.ihe.fhir.core.FhirCamelValidators.*; @@ -36,6 +38,10 @@ public void configure() throws Exception { .setHeader(VALIDATION_MODE, constant(MODEL)) .process(itiRequestValidator()) .process(exchange -> { + Map> httpHeaders = (Map>) exchange.getMessage().getHeader(Constants.HTTP_INCOMING_HEADERS); + assertEquals(1, httpHeaders.get("Authorization").size()); + assertEquals(3, httpHeaders.get("Header2").size()); + //Consent request = exchange.getMessage().getMandatoryBody(Consent.class); log.info("Method = {}", exchange.getMessage().getHeader(Constants.HTTP_METHOD)); exchange.getMessage().setBody(new MethodOutcome(new IdType(UUID.randomUUID().toString())));