Skip to content

Commit

Permalink
Align with master
Browse files Browse the repository at this point in the history
Upgrade dependencies aligned with Jersey 2.x
  • Loading branch information
nhenneaux committed Jan 11, 2024
1 parent 3027d77 commit f3e217e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 81 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '21 13 * * 1'
- cron: '20 20 * * 2'

jobs:
analyze:
Expand All @@ -35,11 +35,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -50,11 +50,12 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Setup Java JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'temurin'
java-version: 21
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +69,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
22 changes: 13 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Java CI

on: [ push ]
on:
push:
schedule:
- cron: '0 5 */1 * *'

jobs:
build:
Expand All @@ -10,35 +13,36 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
java: [ 11, 17]
java: [ 11, 17, 21]
experimental: [ false ]
include:
- java: 19-ea
- java: 22-ea
os: ubuntu-latest
experimental: true
- java: 19-ea
- java: 22-ea
os: macos-latest
experimental: true
- java: 19-ea
- java: 22-ea
os: windows-latest
experimental: true
name: Build with Java ${{ matrix.java }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup Java
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- name: Cache SonarCloud packages
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
36 changes: 16 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.nhenneaux.jersey.connector.httpclient</groupId>
<artifactId>jersey-httpclient-connector</artifactId>
<version>0.3.5</version>
<version>0.3.6</version>

<name>Jersey Connector using java.net.http.HttpClient</name>
<description>A Jersey connector using java.net.http.HttpClient and supporting HTTP/1.1 and HTTP/2.0 with the same client. The protocol is selected based on the server capabilities.</description>
Expand All @@ -22,11 +22,11 @@
<sonar.organization>nhenneaux</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<jersey.version>2.37</jersey.version>
<jersey.version>2.41</jersey.version>

<jetty.version>9.4.49.v20220914</jetty.version>
<jetty.version>9.4.53.v20231009</jetty.version>
<weld-se-core.version>3.1.9.Final</weld-se-core.version>
<log4j.version>2.19.0</log4j.version>
<log4j.version>2.22.1</log4j.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.2</version>
<version>2.0.11</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -129,7 +129,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -141,15 +141,15 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.8.0</version>
<version>5.8.0</version>
<scope>test</scope>
</dependency>

<!-- Needed for mocking org.glassfish.jersey.client.ClientRequest-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.6</version>
<version>2.3.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -159,7 +159,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<version>0.8.10</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down Expand Up @@ -226,7 +226,7 @@
<goal>sign</goal>
</goals>
<configuration>
<keyname>24CB0C2DAB84FC5C84BC0631A41ACFF32C0A49B9</keyname>
<keyname>8C334D53759C56CAFF1B5E9BBE0ED98B46B1B2EA</keyname>
<!-- Configuration to prevent the 'Signing Prompt' or the -->
<!-- 'gpg: signing failed: No such file or directory' error -->
<!-- See https://myshittycode.com/2017/08/07/maven-gpg-plugin-prevent-signing-prompt-or-gpg-signing-failed-no-such-file-or-directory-error/ -->
Expand Down Expand Up @@ -272,39 +272,35 @@
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<version>3.2.5</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.2.5</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
Expand Down Expand Up @@ -343,7 +339,7 @@
<developers>
<developer>
<name>Nicolas Henneaux</name>
<email>nicolas.henneaux@gmail.com</email>
<email>nicolas@henneaux.io</email>
<roles>
<role>Lead maintainer</role>
</roles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ public class HttpClientConnector implements Connector {

private static final Runnable NO_OP = () -> {
};
private final HttpClient httpClient;
private final Supplier<HttpClient> httpClientSupplier;

public HttpClientConnector(HttpClient httpClient) {
this.httpClient = httpClient;
this(() -> httpClient);
}

public HttpClientConnector(Supplier<HttpClient> httpClientSupplier) {
this.httpClientSupplier = httpClientSupplier;
}

public HttpClientConnector(Client jaxRsClient, Configuration configuration) {
Expand All @@ -73,10 +77,11 @@ public HttpClientConnector(Client jaxRsClient, Configuration configuration) {
.map(URI::create)
.ifPresent(proxyUri -> builder.proxy(ProxySelector.of(InetSocketAddress.createUnresolved(proxyUri.getHost(), proxyUri.getPort()))));

this.httpClient = getDurationTimeout(configuration, CONNECT_TIMEOUT)
final var client = getDurationTimeout(configuration, CONNECT_TIMEOUT)
.map(builder::connectTimeout)
.orElse(builder)
.build();
this.httpClientSupplier = () -> client;
}

static <R> R handleInterruption(Interruptable<R> interruptable) {
Expand Down Expand Up @@ -112,19 +117,31 @@ public ClientResponse apply(ClientRequest clientRequest) {
HttpResponse<InputStream> send(HttpRequest request) {
return handleInterruption(() -> {
try {
return httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
return getHttpClient().send(request, HttpResponse.BodyHandlers.ofInputStream());
} catch (IOException e) {
throw new ProcessingException("The async sending process failed with error, " + e.getMessage(), e);
throw new ProcessingException("The HTTP sending process failed with error, " + e.getMessage(), e);
}
});
}

private ClientResponse toJerseyResponse(ClientRequest clientRequest, HttpResponse<InputStream> inputStreamHttpResponse) {
final Response.StatusType responseStatus = Statuses.from(inputStreamHttpResponse.statusCode());
final ClientResponse jerseyResponse = new ClientResponse(responseStatus, clientRequest);
final var headers = inputStreamHttpResponse.headers();

final var contentLengthHeader = headers.firstValueAsLong("content-length");
if ((contentLengthHeader.isEmpty() || contentLengthHeader.getAsLong() > 0) && inputStreamHttpResponse.statusCode() != Response.Status.NO_CONTENT.getStatusCode()) {
final InputStream entityStream = inputStreamHttpResponse.body();
jerseyResponse.setEntityStream(entityStream);
inputStreamHttpResponse.headers().map().forEach((name, values) -> values.forEach(value -> jerseyResponse.header(name, value)));
} else {
//noinspection EmptyTryBlock
try (var ignored = inputStreamHttpResponse.body()) {
// nothing to do
} catch (IOException e) {
// ignored exception since stream is not used
}
}
headers.map().forEach((name, values) -> values.forEach(value -> jerseyResponse.header(name, value)));
return jerseyResponse;
}

Expand All @@ -135,7 +152,7 @@ public Future<?> apply(ClientRequest clientRequest, AsyncConnectorCallback async
}

private CompletableFuture<HttpResponse<InputStream>> getSendAsync(HttpRequest request) {
final var httpResponseCompletableFuture = httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream());
final var httpResponseCompletableFuture = getHttpClient().sendAsync(request, HttpResponse.BodyHandlers.ofInputStream());
return futureTimeout(request, httpResponseCompletableFuture);
}

Expand Down Expand Up @@ -199,6 +216,9 @@ Future<ClientResponse> toJerseyResponseWithCallback(ClientRequest clientRequest,
asyncConnectorCallback.response(response);
} else {
asyncConnectorCallback.failure(cause);
if (response != null) {
response.close();
}
}
});
return clientResponseCompletableFuture;
Expand Down Expand Up @@ -230,11 +250,11 @@ <R> R streamRequestBody(ClientRequest clientRequest, HttpRequest.Builder request
}

private <T> CompletableFuture<T> supplyAsync(HttpRequest httpRequest, Supplier<T> entityWriter) {
return futureTimeout(httpRequest, httpClient.executor().map(executor -> CompletableFuture.supplyAsync(entityWriter, executor)).orElseGet(() -> CompletableFuture.supplyAsync(entityWriter)));
return futureTimeout(httpRequest, getHttpClient().executor().map(executor -> CompletableFuture.supplyAsync(entityWriter, executor)).orElseGet(() -> CompletableFuture.supplyAsync(entityWriter)));
}

private static Void writeEntity(ClientRequest clientRequest, Runnable onError) {
try {
try (var ignoredOnlyForClose = clientRequest.getEntityStream()) {
clientRequest.writeEntity();
return null;
} catch (IOException e) {
Expand All @@ -244,7 +264,7 @@ private static Void writeEntity(ClientRequest clientRequest, Runnable onError) {
}

public HttpClient getHttpClient() {
return httpClient;
return httpClientSupplier.get();
}

@Override
Expand Down
Loading

0 comments on commit f3e217e

Please sign in to comment.