Skip to content

Commit

Permalink
issue #3256 - change the default fhirVersion to 4.3
Browse files Browse the repository at this point in the history
and document how to set it via the `fhirclient.default.mimetype`
configuration property (PROPNAME_DEFAULT_MIMETYPE)

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Jun 2, 2022
1 parent f225e5e commit f40dc01
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 96 deletions.
25 changes: 23 additions & 2 deletions docs/src/pages/guides/FHIRServerUsersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ The set of search parameters can filtered / refined via `fhirServer/resources/[r
## 4.7 FHIR client API

### 4.7.1 Overview
In addition to the server, we also offer a Java API for invoking the FHIR REST APIs. The IBM FHIR Client API is based on the JAX-RS 2.0 standard and provides a simple properties-driven client that can be easily configured for a given endpoint, mutual authentication, request/response logging, and more.
In addition to the server, we also offer a Java API for invoking FHIR REST APIs. The IBM FHIR Client is built on JAX-RS 2.1 and provides a simple properties-driven client that can be configured for a given endpoint, mutual authentication, request/response logging, and more.

### 4.7.2 Maven coordinates
To use the FHIR Client from your application, specify the `fhir-client` artifact as a dependency within your `pom.xml` file, as in the following example:
Expand All @@ -910,7 +910,28 @@ To use the FHIR Client from your application, specify the `fhir-client` artifact
</dependency>
```

### 4.7.3 Sample usage
### 4.7.3 Client properties
Applicable client properties are documented in the FHIRClient interface.
Below is a summary of the most pertinent ones:

| Property | Default | Description |
| -------- | ------- | ----------- |
| fhirclient.rest.base.url<sup>*</sup> | | The target FHIR Server's [base URL](https://hl7.org/fhir/R4B/http.html#root) |
| fhirclient.default.mimetype | application/fhir+json; fhirVersion=4.3 | The value to use in the HTTP headers (Accept and Content-Type) passed to the FHIR Server. |
| fhirclient.truststore.location | | The client truststore's filename. The client truststore contains the server's public key certificates and is used to verify the server's identity. |
| fhirclient.truststore.password | | The client truststore's password. |
| fhirclient.hostnameVerification.enabled | true | Indicates whether or not to enable hostname verification when connecting over TLS. |
| fhirclient.basicauth.enabled | false | Indicates whether Basic Authentication should be used. If enabled, then the username and password properties are required. |
| fhirclient.basicauth.username | | The username to use with Basic Authentication. |
| fhirclient.basicauth.password | | The password to use with Basic Authentication. |
| fhirclient.clientauth.enabled | false | Indicates whether mutual TLS certificate-based authentication should be used. If enabled, then keystore properties are required. |
| fhirclient.keystore.location | | The client keystore's filename. The client keystore constains the client's public/private key pair. When using client certificate-based authentication, this is now the client supplies its identity to the server|
| fhirclient.keystore.password | | The client keystore's password. |
| fhirclient.keystore.key.password | | The password associated with the client's certificate within the keystore. |
| fhirclient.logging.enabled | false | Whether to enable request/response logging (useful for debug). |
| fhirclient.http.receive.timeout | 130000 (130 seconds) | The time, in seconds, to wait for a server response. |

### 4.7.4 Sample usage
For examples on how to use the IBM FHIR Client, look for tests like `com.ibm.fhir.client.test.mains.FHIRClientSample` from the `fhir-client` project in git. Additionally, the FHIR Client is heavilly used from our integration tests in `fhir-server-test`.

## 4.8 Using local references within request bundles
Expand Down
14 changes: 7 additions & 7 deletions fhir-client/src/main/java/com/ibm/fhir/client/FHIRClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public interface FHIRClient {

/**
* Specifies the default mimetype to be used by the FHIRClient instance when invoking
* FHIR REST APIs. If not specified a value of "application/fhir+json" will be used.
* FHIR REST APIs. If not specified a value of "application/fhir+json; fhirVersion=4.3" will be used.
*/
public static final String PROPNAME_DEFAULT_MIMETYPE = "fhirclient.default.mimetype";

/**
* Indicates whether OAuth 2.0 should be used when invoking REST API requests.
* Valid values are "true" and "false" (the default). If enabled, then the authorizeURL, tokenURL and grantType properties
* are required as well.
* Valid values are "true" and "false" (the default). If enabled, then fhirclient.oAuth2.accessToken
* is required as well.
*/
public static final String PROPNAME_OAUTH2_ENABLED = "fhirclient.oAuth2.enabled";

Expand All @@ -45,7 +45,7 @@ public interface FHIRClient {

/**
* Indicates whether Basic Authentication should be used when invoking REST API requests.
* Valid values are "true" and "false" (the default). If enabled, then the username and password properties
* Valid values are "true" and "false" (the default). If enabled, then the username and password properties
* are required as well.
*/
public static final String PROPNAME_BASIC_AUTH_ENABLED = "fhirclient.basicauth.enabled";
Expand All @@ -61,9 +61,9 @@ public interface FHIRClient {
public static final String PROPNAME_CLIENT_PASSWORD = "fhirclient.basicauth.password";

/**
* Indicates whether Client Certificate-based Authentication should be used when invoking REST API requests.
* Valid values are "true" and "false" (the default). If enabled, then the rest of the "clientauth"-related properties
* are required as well.
* Indicates whether client certificate-based authentication should be used when invoking REST API requests.
* Valid values are "true" and "false" (the default). If enabled, then the keystore properties
* are required.
*/
public static final String PROPNAME_CLIENT_AUTH_ENABLED = "fhirclient.clientauth.enabled";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.ibm.fhir.config.FHIRConfiguration;
import com.ibm.fhir.core.FHIRMediaType;
import com.ibm.fhir.core.FHIRUtilities;
import com.ibm.fhir.core.FHIRVersionParam;
import com.ibm.fhir.core.HTTPReturnPreference;
import com.ibm.fhir.model.resource.Bundle;
import com.ibm.fhir.model.resource.Parameters;
Expand All @@ -67,7 +68,7 @@ public class FHIRClientImpl implements FHIRClient {
private Client client = null;
private Properties clientProperties = null;
private String baseEndpointURL = null;
private String defaultMimeType = FHIRMediaType.APPLICATION_FHIR_JSON;
private String defaultMimeType = FHIRMediaType.APPLICATION_FHIR_JSON + "; fhirVersion=" + FHIRVersionParam.VERSION_43.value();

private boolean basicAuthEnabled = false;
private String basicAuthUsername = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016, 2020
* (C) Copyright IBM Corp. 2016, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -33,6 +33,9 @@ public static void main(String[] args) throws Exception {
// Create properties to be used to configure the client.
Properties clientProperties = new Properties();
clientProperties.setProperty(FHIRClient.PROPNAME_BASE_URL, "https://localhost:9443/fhir-server/api/v4");
clientProperties.setProperty(FHIRClient.PROPNAME_TRUSTSTORE_LOCATION, "src/test/resources/fhirClientTrustStore.p12");
clientProperties.setProperty(FHIRClient.PROPNAME_TRUSTSTORE_PASSWORD, "change-password");
clientProperties.setProperty(FHIRClient.PROPNAME_LOGGING_ENABLED, "false");

// Retrieve an instance of the FHIRClient interface.
FHIRClient client = FHIRClientFactory.getClient(clientProperties);
Expand Down
14 changes: 3 additions & 11 deletions fhir-client/src/test/resources/test.basic.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@
fhirclient.rest.base.url = https://jigsaw.w3.org/HTTP/Basic/
fhirclient.default.mimetype = application/fhir+json

fhirclient.basicauth.enabled = true
fhirclient.basicauth.username = guest
fhirclient.basicauth.password = guest

fhirclient.clientauth.enabled = false
fhirclient.keystore.location = fhirClientKeyStore.p12
fhirclient.keystore.password = change-password
fhirclient.keystore.key.password = change-password
fhirclient.truststore.location = fhirClientTrustStore.p12
fhirclient.truststore.password = change-password

fhirclient.oAuth2.enabled = false

fhirclient.encryption.enabled = false
fhirclient.basicauth.enabled = true
fhirclient.basicauth.username = guest
fhirclient.basicauth.password = guest

fhirclient.logging.enabled = false

Expand Down
18 changes: 3 additions & 15 deletions fhir-client/src/test/resources/test.properties
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# Properties file containing test-related properties

fhirclient.rest.base.url = https://localhost:9443/fhir-server/api/v4
fhirclient.default.mimetype = application/fhir+json
fhirclient.default.mimetype = application/fhir+json; fhirVersion=4.3

fhirclient.basicauth.enabled = false
fhirclient.basicauth.username = fhiruser
fhirclient.basicauth.password = change-password
fhirclient.truststore.location = fhirClientTrustStore.p12
fhirclient.truststore.password = change-password

fhirclient.clientauth.enabled = true
fhirclient.keystore.location = fhirClientKeyStore.p12
fhirclient.keystore.password = change-password
fhirclient.keystore.key.password = change-password
fhirclient.truststore.location = fhirClientTrustStore.p12
fhirclient.truststore.password = change-password

fhirclient.oAuth2.enabled = false
#Use fhir-client > FHIROAuth2Test.java to generate the accessToken and encode it using "wlp/bin/securityUtility encode" command
fhirclient.oAuth2.accessToken = change-password

fhirclient.encryption.enabled = false
fhirclient.encryption.keystore.location = fhirkeys.jceks
fhirclient.encryption.keystore.password = change-password
fhirclient.encryption.key.password = change-password

fhirclient.logging.enabled = false

Expand Down
Loading

0 comments on commit f40dc01

Please sign in to comment.