Add credit and docs for #6520 (#6542)

This commit is contained in:
James Agnew 2024-12-06 13:56:12 -05:00 committed by GitHub
parent 43ce89cda6
commit 83381ac5f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 54 additions and 9 deletions

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId> <artifactId>hapi-deployable-pom</artifactId>
<version>7.7.7-SNAPSHOT</version> <version>7.7.10-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath> <relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent> </parent>

View File

@ -129,7 +129,13 @@
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
</dependency> </dependency>
</dependencies> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-client-apache-http5</artifactId>
<version>7.7.10-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -22,10 +22,13 @@ package ca.uhn.hapi.fhir.docs;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.PerformanceOptionsEnum; import ca.uhn.fhir.context.PerformanceOptionsEnum;
import ca.uhn.fhir.model.api.IResource; 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.DeleteCascadeModeEnum;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SearchStyleEnum; import ca.uhn.fhir.rest.api.SearchStyleEnum;
import ca.uhn.fhir.rest.api.SummaryEnum; 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.IGenericClient;
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
@ -52,14 +55,34 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class GenericClientExample { 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() { public static void deferModelScanning() {
// START SNIPPET: deferModelScanning // START SNIPPET: deferModelScanning
// Create a context and configure it for deferred child scanning // Create a context and configure it for deferred child scanning
FhirContext ctx = FhirContext.forDstu2(); FhirContext ctx = FhirContext.forR5();
ctx.setPerformanceOptions(PerformanceOptionsEnum.DEFERRED_MODEL_SCANNING); ctx.setPerformanceOptions(PerformanceOptionsEnum.DEFERRED_MODEL_SCANNING);
// Now create a client and use it // 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); IGenericClient client = ctx.newRestfulGenericClient(serverBase);
// END SNIPPET: deferModelScanning // END SNIPPET: deferModelScanning
} }
@ -67,13 +90,13 @@ public class GenericClientExample {
public static void performance() { public static void performance() {
// START SNIPPET: dontValidate // START SNIPPET: dontValidate
// Create a context // Create a context
FhirContext ctx = FhirContext.forDstu2(); FhirContext ctx = FhirContext.forR5();
// Disable server validation (don't pull the server's metadata first) // Disable server validation (don't pull the server's metadata first)
ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
// Now create a client and use it // 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); IGenericClient client = ctx.newRestfulGenericClient(serverBase);
// END SNIPPET: dontValidate // END SNIPPET: dontValidate
} }
@ -134,8 +157,8 @@ public class GenericClientExample {
public static void simpleExample() { public static void simpleExample() {
// START SNIPPET: simple // START SNIPPET: simple
// We're connecting to a DSTU1 compliant server in this example // We're connecting to a DSTU1 compliant server in this example
FhirContext ctx = FhirContext.forDstu2(); FhirContext ctx = FhirContext.forR5();
String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; String serverBase = "http://hapi.fhir.org/baseR5";
IGenericClient client = ctx.newRestfulGenericClient(serverBase); IGenericClient client = ctx.newRestfulGenericClient(serverBase);

View File

@ -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!"

View File

@ -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 * 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. 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}}
```

View File

@ -956,7 +956,7 @@
</developer> </developer>
<developer> <developer>
<id>iyt-trifork</id> <id>iyt-trifork</id>
<name>Ibrahim</name> <name>Ibrahim Tallouzi</name>
<organization>Trifork A/S</organization> <organization>Trifork A/S</organization>
</developer> </developer>
</developers> </developers>