-
Notifications
You must be signed in to change notification settings - Fork 102
Migrate jetty-client to vertx-web-client #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
google-labs-jules
wants to merge
6
commits into
main
Choose a base branch
from
migrate-jetty-to-vertx-web-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5584bb6
Migrate jetty-client to vertx-web-client
google-labs-jules[bot] f7562b1
Migrate jetty-client to vertx-web-client
google-labs-jules[bot] 547e7b6
Remove unused disableWWWAuthenticationValidation parameter
google-labs-jules[bot] db69e2c
Migrate from Jetty to Vert.x WebClient with proper error handling and…
google-labs-jules[bot] fe097eb
Address review feedback for Vert.x WebClient migration
google-labs-jules[bot] 253edb0
Address final review feedback for Vert.x WebClient migration
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 32 additions & 48 deletions
80
src/main/java/ai/labs/eddi/engine/httpclient/bootstrap/HttpClientModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,73 +1,57 @@ | ||
| package ai.labs.eddi.engine.httpclient.bootstrap; | ||
|
|
||
| import ai.labs.eddi.engine.httpclient.impl.JettyHttpClient; | ||
| import ai.labs.eddi.engine.httpclient.impl.VertxHttpClient; | ||
| import io.vertx.core.Vertx; | ||
| import io.vertx.ext.web.client.WebClient; | ||
| import io.vertx.ext.web.client.WebClientSession; | ||
| import io.vertx.ext.web.client.WebClientOptions; | ||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import jakarta.enterprise.inject.Disposes; | ||
| import jakarta.inject.Inject; | ||
| import jakarta.ws.rs.Produces; | ||
| import org.eclipse.jetty.client.HttpClient; | ||
| import org.eclipse.jetty.client.WWWAuthenticationProtocolHandler; | ||
| import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
| import org.eclipse.microprofile.context.ManagedExecutor; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| @ApplicationScoped | ||
| public class HttpClientModule { | ||
|
|
||
| @Inject | ||
| ManagedExecutor executorService; | ||
| Vertx vertx; | ||
|
|
||
| @Produces | ||
| @ApplicationScoped | ||
| public JettyHttpClient provideHttpClient(@ConfigProperty(name = "httpClient.maxConnectionsQueued") Integer maxConnectionsQueued, | ||
| @ConfigProperty(name = "httpClient.maxConnectionPerRoute") Integer maxConnectionPerRoute, | ||
| @ConfigProperty(name = "httpClient.requestBufferSize") Integer requestBufferSize, | ||
| @ConfigProperty(name = "httpClient.responseBufferSize") Integer responseBufferSize, | ||
| public VertxHttpClient provideHttpClient(@ConfigProperty(name = "httpClient.maxConnectionPerRoute") Integer maxConnectionPerRoute, | ||
| @ConfigProperty(name = "httpClient.maxRedirects") Integer maxRedirects, | ||
| @ConfigProperty(name = "httpClient.idleTimeoutInMillis") Integer idleTimeout, | ||
| @ConfigProperty(name = "httpClient.connectTimeoutInMillis") Integer connectTimeout, | ||
| @ConfigProperty(name = "httpClient.disableWWWAuthenticationValidation") | ||
| Boolean disableWWWAuthenticationValidation) { | ||
| @ConfigProperty(name = "httpClient.connectTimeoutInMillis") Integer connectTimeout) { | ||
|
|
||
| try { | ||
| HttpClient httpClient = new HttpClient(); | ||
| httpClient.setExecutor(executorService); | ||
| httpClient.setMaxConnectionsPerDestination(maxConnectionsQueued); | ||
| httpClient.setMaxRequestsQueuedPerDestination(maxConnectionPerRoute); | ||
| httpClient.setRequestBufferSize(requestBufferSize); | ||
| httpClient.setResponseBufferSize(responseBufferSize); | ||
| httpClient.setMaxRedirects(maxRedirects); | ||
| httpClient.setIdleTimeout(idleTimeout); | ||
| httpClient.setConnectTimeout(connectTimeout); | ||
| httpClient.start(); | ||
| WebClientOptions options = new WebClientOptions(); | ||
|
|
||
| if (disableWWWAuthenticationValidation) { | ||
| httpClient.getProtocolHandlers().remove(WWWAuthenticationProtocolHandler.NAME); | ||
| } | ||
| // Mapping configuration | ||
| options.setMaxPoolSize(maxConnectionPerRoute); | ||
|
|
||
| registerHttpClientShutdownHook(httpClient); | ||
| options.setMaxRedirects(maxRedirects); | ||
|
|
||
| return new JettyHttpClient(httpClient); | ||
| } catch (Exception e) { | ||
| System.out.println(Arrays.toString(e.getStackTrace())); | ||
| throw new RuntimeException(e.getLocalizedMessage(), e); | ||
| int idleTimeoutSeconds; | ||
| if (idleTimeout == 0) { | ||
| idleTimeoutSeconds = 0; | ||
| } else { | ||
| idleTimeoutSeconds = (int) Math.ceil(idleTimeout / 1000.0); | ||
| } | ||
| options.setIdleTimeout(idleTimeoutSeconds); | ||
|
|
||
| options.setConnectTimeout(connectTimeout); | ||
| options.setFollowRedirects(true); | ||
| options.setDecompressionSupported(true); | ||
|
|
||
| WebClient webClient = WebClient.create(vertx, options); | ||
| WebClientSession webClientSession = WebClientSession.create(webClient); | ||
|
|
||
| return new VertxHttpClient(vertx, webClientSession, webClient); | ||
| } | ||
|
|
||
| private void registerHttpClientShutdownHook(final HttpClient httpClient) { | ||
| Runtime.getRuntime().addShutdownHook(new Thread("ShutdownHook_HttpClient") { | ||
| @Override | ||
| public void run() { | ||
| try { | ||
| if (!httpClient.isStopped()) { | ||
| httpClient.stop(); | ||
| } | ||
| } catch (Throwable e) { | ||
| String message = "HttpClient did not stop as expected."; | ||
| System.out.println(message); | ||
| System.out.println(Arrays.toString(e.getStackTrace())); | ||
| } | ||
| } | ||
| }); | ||
| public void close(@Disposes VertxHttpClient client) { | ||
| if (client.getUnderlyingClient() != null) { | ||
| client.getUnderlyingClient().close(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Vertxinstance is injected but Quarkus provides Vert.x through thequarkus-vertxextension. You need to add the Quarkus Vert.x dependency topom.xmlfor this injection to work:Without this dependency, the Vertx injection will fail at runtime.