Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Jan 16, 2023
1 parent 4fa2dee commit a2c1dee
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/main/java/com/postmarkapp/postmark/client/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,34 @@ public Client getClient() {
}

/**
* Build HTTP client used for requests
* Build default HTTP client used for requests
*
* @return initialized HTTP client
*/
private Client buildClient() {
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
return clientBuilder.withConfig(clientConfig()).build();
}

/** Jersey client uses HttpUrlConnection by default which doesn't have PATCH method:
* Jersey client uses HttpUrlConnection by default which doesn't have PATCH method:
* https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html#setRequestMethod-java.lang.String-
* https://github.com/eclipse-ee4j/jersey/issues/4825
*
* Workaround for being able to do PATCH requests is by using reflection, which would work up to Java 16.
* https://stackoverflow.com/questions/55778145/how-to-use-patch-method-with-jersey-invocation-builder
*
* This workaround doesn't need to be set if custom connector like grizzly is used
* supported connector list can be seen here:
* https://www.cwiki.us/display/JERSEYEN/Client+Transport+Connectors
* https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/client.html#d0e4979
* @return initialized HTTP client
*/
private Client buildClient() {
Client client = ClientBuilder.newClient();
// this allows calls to PATCH by using reflection
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
return client;
}

/**
* Build HTTP client with custom config used for requests
* like:
*
* @return client configuration which determines connection provider used by Jersey HTTP client.
* ClientConfig clientConfig = new ClientConfig();
* clientConfig.connectorProvider(new GrizzlyConnectorProvider());
* clientConfig.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround());
*/
private ClientConfig clientConfig() {
ClientConfig clientConfig = new ClientConfig();
// use default provider, you can also use providers that support jdk 16+ like:
//clientConfig.connectorProvider(new GrizzlyConnectorProvider());
clientConfig.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround());
return clientConfig;
private Client buildClient(ClientConfig config) {
return ClientBuilder.newClient(config);
}

/**
Expand Down

0 comments on commit a2c1dee

Please sign in to comment.