Upgrade org.eclipse.jetty to 12.1.10 - #365
Conversation
There was a problem hiding this comment.
Code Review
This pull request upgrades Jetty to version 12.1.10 and refactors the codebase to adapt to Jetty 12 APIs. However, several critical issues have been identified. In Jetty 12, SslContextFactory is abstract, and instantiating HttpClient with the default constructor will fail to configure SSL/TLS, causing HTTPS requests to Salesforce to fail. Additionally, excluding Jetty 9.4.x transitive dependencies while using CometD 4.x will result in runtime compatibility errors, as CometD 4.x is not compatible with Jetty 12 APIs.
| import org.eclipse.jetty.client.api.Request; | ||
| import org.eclipse.jetty.client.Request; | ||
| import org.eclipse.jetty.http.HttpHeader; | ||
| import org.eclipse.jetty.http.HttpMethod; |
|
|
||
| SslContextFactory sslContextFactory = new SslContextFactory(); | ||
| HttpClient httpClient = new HttpClient(sslContextFactory); | ||
| HttpClient httpClient = new HttpClient(); |
There was a problem hiding this comment.
In Jetty 12, SslContextFactory is abstract, and the default constructor new HttpClient() does not configure SSL/TLS support. Since Salesforce APIs strictly require HTTPS, using new HttpClient() without an explicit SslContextFactory.Client will cause all requests to fail with an exception (e.g., IllegalStateException: Scheme-specific transport not found: https). To fix this, instantiate HttpClient with an instance of SslContextFactory.Client.
| HttpClient httpClient = new HttpClient(); | |
| SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(); | |
| HttpClient httpClient = new HttpClient(sslContextFactory); |
| import org.eclipse.jetty.client.ProxyConfiguration; | ||
| import org.eclipse.jetty.client.api.Request; | ||
| import org.eclipse.jetty.util.ssl.SslContextFactory; | ||
| import org.eclipse.jetty.client.Request; |
|
|
||
| SslContextFactory sslContextFactory = new SslContextFactory(); | ||
| HttpClient httpClient = new HttpClient(sslContextFactory); | ||
| HttpClient httpClient = new HttpClient(); |
There was a problem hiding this comment.
In Jetty 12, SslContextFactory is abstract, and the default constructor new HttpClient() does not configure SSL/TLS support. Since Salesforce APIs strictly require HTTPS, using new HttpClient() without an explicit SslContextFactory.Client will cause all requests to fail with an exception (e.g., IllegalStateException: Scheme-specific transport not found: https). To fix this, instantiate HttpClient with an instance of SslContextFactory.Client.
| HttpClient httpClient = new HttpClient(); | |
| SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(); | |
| HttpClient httpClient = new HttpClient(sslContextFactory); |
| import org.eclipse.jetty.client.HttpClient; | ||
| import org.eclipse.jetty.client.api.Request; | ||
| import org.eclipse.jetty.util.ssl.SslContextFactory; | ||
| import org.eclipse.jetty.client.Request; |
|
|
||
| // Set up a Jetty HTTP client to use with CometD | ||
| HttpClient httpClient = new HttpClient(sslContextFactory); | ||
| HttpClient httpClient = new HttpClient(); |
There was a problem hiding this comment.
In Jetty 12, SslContextFactory is abstract, and the default constructor new HttpClient() does not configure SSL/TLS support. Since Salesforce APIs strictly require HTTPS, using new HttpClient() without an explicit SslContextFactory.Client will cause all requests to fail with an exception (e.g., IllegalStateException: Scheme-specific transport not found: https). To fix this, instantiate HttpClient with an instance of SslContextFactory.Client.
| HttpClient httpClient = new HttpClient(); | |
| SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(); | |
| HttpClient httpClient = new HttpClient(sslContextFactory); |
| import org.eclipse.jetty.client.api.Request; | ||
| import org.eclipse.jetty.client.Request; | ||
| import org.eclipse.jetty.http.HttpHeader; | ||
| import org.eclipse.jetty.http.HttpMethod; |
| PowerMockito.whenNew(HttpClient.class).withNoArguments() | ||
| .thenReturn(httpClient); |
There was a problem hiding this comment.
Since SalesforceQueryUtil needs to instantiate HttpClient with SslContextFactory.Client to support HTTPS, update the PowerMockito expectation to match the constructor call with arguments.
| PowerMockito.whenNew(HttpClient.class).withNoArguments() | |
| .thenReturn(httpClient); | |
| PowerMockito.whenNew(HttpClient.class).withArguments(Mockito.any(SslContextFactory.Client.class)) | |
| .thenReturn(httpClient); |
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-http</artifactId> | ||
| </exclusion> | ||
| <exclusion> |
There was a problem hiding this comment.
Excluding Jetty 9.4.x transitive dependencies from cometd-java-client version 4.0.0 and forcing it to run with Jetty 12 will cause critical runtime failures (such as NoClassDefFoundError or NoSuchMethodError). CometD 4.x is compiled against Jetty 9.4.x APIs (e.g., it references org.eclipse.jetty.client.api.Request which has been refactored/removed in Jetty 12). To support Jetty 12, you must upgrade cometd-java-client to a compatible version (such as CometD 7.x or 8.x depending on the Jakarta EE namespace used by the project).
Summary
Upgrades
org.eclipse.jettydependencies from9.4.xto12.1.10inpom.xml, excludes outdated transitive Jetty dependencies, and updates codebase to adhere to Jetty 12 API changes.Key Changes
Dependency Management & Upgrades (
pom.xml):<jetty.version>12.1.10</jetty.version>to<properties>.jetty-httpand explicitly addedjetty-clientandjetty-utildependencies with${jetty.version}.9.4.12.v20180830Jetty artifacts fromcometd-java-client.hydrator-test.Jetty 12 API Migrations:
Authenticator.java&SalesforceQueryUtil.java:org.eclipse.jetty.client.api.*toorg.eclipse.jetty.client.*.new HttpClient(SslContextFactory)with defaultnew HttpClient().Request.headers(...).SalesforcePushTopicListener.java:httpClient.getRequestListeners().addListener(...)withRequest.Listenerinstead of overriding deprecatedLongPollingTransport.customize(Request).SalesforceQueryUtilTest.java:HttpClientinitialization and headers.Verification
mvn dependency:tree -Dincludes=org.eclipse.jetty*to ensure no legacy 9.4.x artifacts remain in compile scope.mvn compile(BUILD SUCCESS).