Skip to content

Commit 1b1f4ac

Browse files
committed
fix: use the Apache HTTP client connector to support PATCH
- Update the `ApiClient` default `ClientConfig` to use the `ApacheConnectorProvider`. This fixes an issue where it is no longer possible to workaround the lack of `PATCH` support in the native JDK `HttpsURLConnection` on later JDKs. - Re-add the README example for configuring an outbound proxy.
1 parent 16fcb51 commit 1b1f4ac

6 files changed

Lines changed: 66 additions & 31 deletions

File tree

.changeset/gentle-dots-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"java-sdk": patch
3+
---
4+
5+
Use the Apache HTTP client connector by default to enable support for the PATCH HTTP method.

.changeset/weak-eagles-deliver.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ Migrate to Server API v4
1111
- Changed root package for the SDK from `com.fingerprint` to `com.fingerprint.v4`
1212
- Removed `GetVisits` and `GetRelatedVisitors` operations.
1313
- Improved models used by the `GetEvent` and `SearchEvents` operations to use a more concise shape and clearer names.
14+
- Use the Apache HTTP client connector by default to enable support for the PATCH HTTP method.
1415

1516
See [this page in the Fingerprint documentation](https://docs.fingerprint.com/reference/java-server-sdk#migration-guide-for-java-sdk-v8-0-0) for a migration guide.

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,32 @@ class WebhookController {
257257
}
258258
```
259259

260+
## Configure an outbound HTTP proxy
261+
262+
To add an outbound HTTP proxy for the API client, use `ClientConfig`:
263+
```java
264+
265+
import org.glassfish.jersey.client.ClientConfig;
266+
import org.glassfish.jersey.client.ClientProperties;
267+
import com.fingerprint.v4.sdk.*;
268+
import com.fingerprint.v4.api.FingerprintApi;
269+
270+
// ...
271+
272+
ApiClient defaultClient = Configuration.getDefaultApiClient();
273+
ClientConfig clientConfig = defaultClient.getClientConfig();
274+
275+
// The following properties configure the ApacheConnectorProvider, which is the default.
276+
clientConfig.property(ClientProperties.PROXY_URI, "http://proxy_url_here");
277+
clientConfig.property(ClientProperties.PROXY_USERNAME, "proxy_username");
278+
clientConfig.property(ClientProperties.PROXY_PASSWORD, "proxy_password");
279+
280+
defaultClient.setClientConfig(clientConfig);
281+
282+
FingerprintApi apiInstance = new FingerprintApi(defaultClient);
283+
284+
```
285+
260286
## Documentation for API Endpoints
261287

262288
All URIs are relative to *https://api.fpjs.io/v4*

sdk/src/main/java/com/fingerprint/v4/sdk/ApiClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
import javax.net.ssl.SSLContext;
5959
import javax.net.ssl.TrustManager;
6060
import javax.net.ssl.X509TrustManager;
61+
import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
6162
import org.glassfish.jersey.client.ClientConfig;
6263
import org.glassfish.jersey.client.ClientProperties;
63-
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
6464
import org.glassfish.jersey.jackson.JacksonFeature;
6565
import org.glassfish.jersey.logging.LoggingFeature;
6666
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
@@ -1210,7 +1210,8 @@ public ClientConfig getDefaultClientConfig() {
12101210
clientConfig.register(MultiPartFeature.class);
12111211
clientConfig.register(json);
12121212
clientConfig.register(JacksonFeature.class);
1213-
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
1213+
// Use the ApacheConnectorProvider to enable PATCH method support
1214+
clientConfig.connectorProvider(new ApacheConnectorProvider());
12141215
// turn off compliance validation to be able to send payloads with DELETE calls
12151216
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
12161217
applyDebugSetting(clientConfig);

template/README.mustache

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,6 @@ Then manually install the following JARs:
102102

103103
- `sdk/build/libs/{{{artifactId}}}-{{{artifactVersion}}}.jar`
104104

105-
{{#jersey2}}
106-
## Usage
107-
108-
To add a HTTP proxy for the API client, use `ClientConfig`:
109-
```java
110-
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
111-
import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
112-
import org.glassfish.jersey.client.ClientConfig;
113-
import org.glassfish.jersey.client.ClientProperties;
114-
import {{{invokerPackage}}}.*;
115-
import {{{package}}}.{{{classname}}};
116-
117-
...
118-
119-
ApiClient defaultClient = Configuration.getDefaultApiClient();
120-
ClientConfig clientConfig = defaultClient.getClientConfig();
121-
clientConfig.connectorProvider(new ApacheConnectorProvider());
122-
clientConfig.property(ClientProperties.PROXY_URI, "http://proxy_url_here");
123-
clientConfig.property(ClientProperties.PROXY_USERNAME, "proxy_username");
124-
clientConfig.property(ClientProperties.PROXY_PASSWORD, "proxy_password");
125-
defaultClient.setClientConfig(clientConfig);
126-
127-
{{{classname}}} apiInstance = new {{{classname}}}(defaultClient);
128-
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
129-
```
130-
131-
{{/jersey2}}
132105
## Getting Started
133106

134107
Please follow the [installation](#installation) instruction and execute the following Java code:
@@ -283,7 +256,35 @@ class WebhookController {
283256
}
284257
}
285258
```
259+
{{#jersey3}}
260+
261+
## Configure an outbound HTTP proxy
262+
263+
To add an outbound HTTP proxy for the API client, use `ClientConfig`:
264+
```java
265+
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
266+
import org.glassfish.jersey.client.ClientConfig;
267+
import org.glassfish.jersey.client.ClientProperties;
268+
import {{{invokerPackage}}}.*;
269+
import {{{package}}}.{{{classname}}};
270+
271+
// ...
272+
273+
ApiClient defaultClient = Configuration.getDefaultApiClient();
274+
ClientConfig clientConfig = defaultClient.getClientConfig();
275+
276+
// The following properties configure the ApacheConnectorProvider, which is the default.
277+
clientConfig.property(ClientProperties.PROXY_URI, "http://proxy_url_here");
278+
clientConfig.property(ClientProperties.PROXY_USERNAME, "proxy_username");
279+
clientConfig.property(ClientProperties.PROXY_PASSWORD, "proxy_password");
280+
281+
defaultClient.setClientConfig(clientConfig);
282+
283+
{{{classname}}} apiInstance = new {{{classname}}}(defaultClient);
284+
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
285+
```
286286
287+
{{/jersey3}}
287288
## Documentation for API Endpoints
288289
289290
All URIs are relative to *{{basePath}}*

template/libraries/jersey3/ApiClient.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {{javaxPackage}}.ws.rs.core.Response.Status;
1616
{{#hasOAuthMethods}}
1717
import com.github.scribejava.core.model.OAuth2AccessToken;
1818
{{/hasOAuthMethods}}
19+
import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
1920
import org.glassfish.jersey.client.ClientConfig;
2021
import org.glassfish.jersey.client.ClientProperties;
21-
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
2222
import org.glassfish.jersey.jackson.JacksonFeature;
2323
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
2424
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
@@ -1410,7 +1410,8 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
14101410
clientConfig.register(MultiPartFeature.class);
14111411
clientConfig.register(json);
14121412
clientConfig.register(JacksonFeature.class);
1413-
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
1413+
// Use the ApacheConnectorProvider to enable PATCH method support
1414+
clientConfig.connectorProvider(new ApacheConnectorProvider());
14141415
// turn off compliance validation to be able to send payloads with DELETE calls
14151416
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
14161417
applyDebugSetting(clientConfig);

0 commit comments

Comments
 (0)