From 83381ac5f928c157ca1ac626ccb81b12cfedd40f Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 6 Dec 2024 13:56:12 -0500 Subject: [PATCH] Add credit and docs for #6520 (#6542) --- hapi-fhir-client-apache-http5/pom.xml | 2 +- hapi-fhir-docs/pom.xml | 8 ++++- .../hapi/fhir/docs/GenericClientExample.java | 35 +++++++++++++++---- .../7_8_0/6520-add-httpclient5-support.yaml | 8 +++++ .../uhn/hapi/fhir/docs/client/introduction.md | 8 +++++ pom.xml | 2 +- 6 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6520-add-httpclient5-support.yaml diff --git a/hapi-fhir-client-apache-http5/pom.xml b/hapi-fhir-client-apache-http5/pom.xml index 00c91cb4f2b..92225bfd717 100644 --- a/hapi-fhir-client-apache-http5/pom.xml +++ b/hapi-fhir-client-apache-http5/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-deployable-pom - 7.7.7-SNAPSHOT + 7.7.10-SNAPSHOT ../hapi-deployable-pom/pom.xml diff --git a/hapi-fhir-docs/pom.xml b/hapi-fhir-docs/pom.xml index 0a55640077f..e79379e3353 100644 --- a/hapi-fhir-docs/pom.xml +++ b/hapi-fhir-docs/pom.xml @@ -129,7 +129,13 @@ com.fasterxml.jackson.core jackson-databind - + + ca.uhn.hapi.fhir + hapi-fhir-client-apache-http5 + 7.7.10-SNAPSHOT + compile + + diff --git a/hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/GenericClientExample.java b/hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/GenericClientExample.java index 8c32f40f887..26058f7c4fd 100644 --- a/hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/GenericClientExample.java +++ b/hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/GenericClientExample.java @@ -22,10 +22,13 @@ package ca.uhn.hapi.fhir.docs; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.PerformanceOptionsEnum; import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory; import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.SearchStyleEnum; import ca.uhn.fhir.rest.api.SummaryEnum; +import ca.uhn.fhir.rest.client.apache.ApacheHttp5RestfulClientFactory; +import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; @@ -52,14 +55,34 @@ import java.util.ArrayList; import java.util.List; public class GenericClientExample { + public static void chooseProvider() { + // START SNIPPET: chooseProvider + // Create a context and configure it for deferred child scanning + FhirContext ctx = FhirContext.forR5(); + + // Use Apache HttpClient 4.x client (this is the default) + ctx.setRestfulClientFactory(new ApacheRestfulClientFactory(ctx)); + + // Use OkHttp as the HTTP provider + ctx.setRestfulClientFactory(new OkHttpRestfulClientFactory(ctx)); + + // Use Apache HttpClient 5.x client + ctx.setRestfulClientFactory(new ApacheHttp5RestfulClientFactory(ctx)); + + // Now create a client and use it + String serverBase = "http://hapi.fhir.org/baseR5"; + IGenericClient client = ctx.newRestfulGenericClient(serverBase); + // END SNIPPET: chooseProvider + } + public static void deferModelScanning() { // START SNIPPET: deferModelScanning // Create a context and configure it for deferred child scanning - FhirContext ctx = FhirContext.forDstu2(); + FhirContext ctx = FhirContext.forR5(); ctx.setPerformanceOptions(PerformanceOptionsEnum.DEFERRED_MODEL_SCANNING); // Now create a client and use it - String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; + String serverBase = "http://hapi.fhir.org/baseR5"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // END SNIPPET: deferModelScanning } @@ -67,13 +90,13 @@ public class GenericClientExample { public static void performance() { // START SNIPPET: dontValidate // Create a context - FhirContext ctx = FhirContext.forDstu2(); + FhirContext ctx = FhirContext.forR5(); // Disable server validation (don't pull the server's metadata first) ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); // Now create a client and use it - String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; + String serverBase = "http://hapi.fhir.org/baseR5"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // END SNIPPET: dontValidate } @@ -134,8 +157,8 @@ public class GenericClientExample { public static void simpleExample() { // START SNIPPET: simple // We're connecting to a DSTU1 compliant server in this example - FhirContext ctx = FhirContext.forDstu2(); - String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; + FhirContext ctx = FhirContext.forR5(); + String serverBase = "http://hapi.fhir.org/baseR5"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6520-add-httpclient5-support.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6520-add-httpclient5-support.yaml new file mode 100644 index 00000000000..91187879132 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6520-add-httpclient5-support.yaml @@ -0,0 +1,8 @@ +--- +type: add +issue: 6520 +title: "A new FHIR client implementation based on Apache HttpClient 5.x has been + added to HAPI FHIR. This implementation is optional for now, with the default + remaining to use HttpClient 4.x, but this will likely become the default (and only + supported version of the HttpClient library) in the future. Thanks to + Ibrahim Tallouzi for the contribution!" diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/client/introduction.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/client/introduction.md index dfe36527a08..6e5723b5683 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/client/introduction.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/client/introduction.md @@ -11,3 +11,11 @@ There are two types of REST clients provided by HAPI: * The [Annotation Client](./annotation_client.html) client relies on static binding to specific operations to give better compile-time checking against servers with a specific set of capabilities exposed. This second model takes more effort to use, but can be useful if the person defining the specific methods to invoke is not the same person who is using those methods. +# HTTP Providers + +The HAPI FHIR Client framework uses an underlying HTTP provider to handle the transport communication. Most of the documentation in this section describes how to perform FHIR REST operations using the client, but you may need to select a specific provider if you need to customize the transport in any way. The following example shows how to choose from several providers. + +```java +{{snippet:classpath:/ca/uhn/hapi/fhir/docs/GenericClientExample.java|chooseProvider}} +``` + diff --git a/pom.xml b/pom.xml index 82e20acaf66..53e232b5c0f 100644 --- a/pom.xml +++ b/pom.xml @@ -956,7 +956,7 @@ iyt-trifork - Ibrahim + Ibrahim Tallouzi Trifork A/S