Skip to content

Commit

Permalink
Jersey 2.42 (#53)
Browse files Browse the repository at this point in the history
Jersey 2.42
Build with Java 22-23ea
Update libraries and plugins
  • Loading branch information
nhenneaux authored Mar 29, 2024
1 parent 8f3e42f commit 6675e50
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 110 deletions.
57 changes: 31 additions & 26 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: '15 17 * * 0'
- cron: '20 20 * * 2'

jobs:
analyze:
Expand All @@ -34,34 +34,39 @@ jobs:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# 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: Autobuild
uses: github/codeql-action/autobuild@v1
# 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@v4
with:
distribution: 'temurin'
java-version: 21
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
29 changes: 19 additions & 10 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,41 +13,47 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
java: [ 8, 11, 17, 21 ]
java: [ 8, 11, 17, 21, 22 ]
experimental: [ false ]
include:
- java: 22-ea
- java: 23-ea
os: ubuntu-latest
experimental: true
- java: 22-ea
- java: 23-ea
os: macos-latest
experimental: true
- java: 22-ea
- java: 23-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@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B -C verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar "-Dsonar.projectKey=nhenneaux_jersey-http2-jetty-connector"
run: mvn -B -C verify
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Sonar
run: mvn -B -C org.sonarsource.scanner.maven:sonar-maven-plugin:sonar "-Dsonar.projectKey=nhenneaux_jersey-http2-jetty-connector"
if: ${{ matrix.java == 21 && matrix.os == 'ubuntu-latest' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4 changes: 2 additions & 2 deletions jersey-http2-jetty-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jersey-http2-jetty</artifactId>
<groupId>com.github.nhenneaux.jersey.jetty.http2</groupId>
<version>1.0.17</version>
<version>1.0.18</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.20.0</version>
<version>2.23.1</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jetty.connector.JettyClientProperties;
import org.glassfish.jersey.jetty.connector.JettyHttp2Connector;
import org.hamcrest.Matchers;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static com.github.nhenneaux.jersey.http2.jetty.bundle.JettyServer.TlsSecurityConfiguration.getKeyStore;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

@SuppressWarnings("squid:S00112")
Expand Down Expand Up @@ -64,8 +73,8 @@ void testValidTls() throws Exception {
try (AutoCloseable ignored = jerseyServer(
port,
tlsSecurityConfiguration,
DummyRestService.class)) {
final Response ping = getClient(port).path(PING).request().head();
DummyRestService.class);
Response ping = getClient(port).path(PING).request().head()) {
assertEquals(204, ping.getStatus());
}
}
Expand All @@ -77,7 +86,7 @@ void testConcurrent() throws Exception {
}

@Test
@Timeout(60)
@Timeout(120)
void testConcurrentHttp1() throws Exception {
testConcurrent(new ClientConfig().property(JettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION, Boolean.TRUE));
}
Expand All @@ -94,21 +103,43 @@ private void testConcurrent(ClientConfig clientConfig) throws Exception {
final int nThreads = 4;
final int iterations = 10_000;
// Warmup
getClient(port, truststore, clientConfig).path(PING).request().head();

final WebTarget webTarget = getClient(port, truststore, clientConfig).path(PING).path(PING);
webTarget.request().head().close();

AtomicInteger counter = new AtomicInteger();
final Runnable runnable = () -> {
final WebTarget client = getClient(port, truststore, clientConfig);
final long start = System.currentTimeMillis();
long start = System.nanoTime();
for (int i = 0; i < iterations; i++) {
client.path(PING).request().head();
counter.incrementAndGet();
if (i % 1_000 == 0) {
System.out.println((System.currentTimeMillis() - start) * 1.0 / Math.max(i, 1));
try (Response response = webTarget.request().head()) {
final InputStream inputStream = response.readEntity(InputStream.class);
byte[] bytes = new byte[inputStream.available()];
DataInputStream dataInputStream = new DataInputStream(inputStream);
dataInputStream.readFully(bytes);
response.getStatus();
counter.incrementAndGet();
int reportEveryRequests = 1_000;
if (i % reportEveryRequests == 0) {
System.out.println(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) * 1.0 / reportEveryRequests);
start = System.nanoTime();
}
} catch (ProcessingException | IOException e) {
if (e.getMessage().contains("GOAWAY")
|| e.getMessage().contains("Broken pipe") // The HTTP sending process failed with error, Broken pipe
|| e.getMessage().contains("EOF reached while reading")
|| e.getMessage().contains(" cancelled")) {// The HTTP sending process failed with error, Stream 673 cancelled
i--;
} else {
throw new IllegalStateException(e);
}
}
}
};
Thread.setDefaultUncaughtExceptionHandler((t1, e) -> e.printStackTrace());
List<Throwable> thrown = new ArrayList<>();
Thread.setDefaultUncaughtExceptionHandler((t1, e) -> {
thrown.add(e);
e.printStackTrace();
});
final Set<Thread> threads = IntStream
.range(0, nThreads)
.mapToObj(i -> runnable)
Expand All @@ -121,7 +152,7 @@ private void testConcurrent(ClientConfig clientConfig) throws Exception {
for (Thread thread : threads) {
thread.join();
}

assertThat(thrown, Matchers.empty());
assertEquals((long) nThreads * iterations, counter.get());

}
Expand All @@ -134,9 +165,10 @@ void shouldWorkInLoop() throws Exception {
for (int i = 0; i < 100; i++) {
try (
@SuppressWarnings("unused") WeldContainer container = new Weld().initialize();
AutoCloseable ignored = jerseyServer(port, tlsSecurityConfiguration, DummyRestService.class)
AutoCloseable ignored = jerseyServer(port, tlsSecurityConfiguration, DummyRestService.class);
final Response head = getClient(port).path(PING).request().head();
) {
assertEquals(204, getClient(port).path(PING).request().head().getStatus());
assertEquals(204, head.getStatus());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion jersey-http2-jetty-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.nhenneaux.jersey.jetty.http2</groupId>
<artifactId>jersey-http2-jetty</artifactId>
<version>1.0.17</version>
<version>1.0.18</version>
</parent>

<artifactId>jersey-http2-jetty-connector</artifactId>
Expand Down
Loading

0 comments on commit 6675e50

Please sign in to comment.