Skip to content
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

Remove deprecation of HttpClient replacement methods in WebSocketClient #3663

Closed
joakime opened this issue May 16, 2019 · 9 comments
Closed
Assignees

Comments

@joakime
Copy link
Contributor

joakime commented May 16, 2019

No description provided.

@joakime joakime self-assigned this May 16, 2019
@joakime
Copy link
Contributor Author

joakime commented May 16, 2019

As reported by the cometd project - cometd/cometd#862

If the jetty-client-<ver>.jar is present on the server classpath, because something on the server classpath needs to use Jetty's HttpClient, and a webapp uses code like this ...

webSocketClient.getHttpClient().setConnectTimeout(30000);
webSocketClient.getHttpClient().setCookieStore(cookieStore);

That can result in a linkage error ...

java.lang.LinkageError: loader constraint violation: when resolving method "org.eclipse.jetty.websocket.client.WebSocketClient.getHttpClient()Lorg/eclipse/jetty/client/HttpClient;" the class loader (instance of org/eclipse/jetty/web
app/WebAppClassLoader) of the current class, org/cometd/websocket/client/JettyWebSocketTransport, and the class loader (instance of org/eclipse/jetty/start/Classpath$Loader) for the method's defining class, org/eclipse/jetty/websocket/client/WebSocketClient, have different Class objects for the type org/eclipse/jetty/client/HttpClient used in the signature

all because they followed the recommendations in the @Deprecation on WebSocketClient.

joakime added a commit that referenced this issue May 16, 2019
+ Those methods and constructors that had @Deprecation assigned
  that urged the use of HttpClient directly are no longer
  annotated as deprecated because of legitimate possibility of
  a valid LinkageError

Signed-off-by: Joakim Erdfelt <[email protected]>
@joakime
Copy link
Contributor Author

joakime commented May 16, 2019

Opened PR #3665

sbordet added a commit that referenced this issue May 20, 2019
…-wsclient-with-httpclient

Issue #3663 - Remove @Deprecation's from WebSocketClient
@joakime
Copy link
Contributor Author

joakime commented May 22, 2019

Closing due to merge into mainline jetty-9.4.x

@joakime joakime closed this as completed May 22, 2019
@jwhgithub
Copy link

Seems this change was overridden by #3730 (PR #4423)? Could someone comment on this?

I got same error in version 9.4.35.v20201120 when create WebsocketClient with given HttpClient.

`
SslContextFactory sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setTrustAll(true);
sslContextFactory.setEndpointIdentificationAlgorithm("HTTPS");

HttpClient httpClient = new org.eclipse.jetty.client.HttpClient(sslContextFactory);
httpClient.setConnectTimeout(timeout);
httpClient.start();
WebSocketClient webSocketClient = new WebSocketClient(httpClient);
webSocketClient.getPolicy().setIdleTimeout(timeout);
webSocketClient.getPolicy().setMaxTextMessageSize(Integer.MAX_VALUE);
webSocketClient.start();
return webSocketClient;
`

@sbordet
Copy link
Contributor

sbordet commented Dec 20, 2020

@jwhgithub what exact error do you get? The LinkageError?

The code snippet above it's done inside a web application?

@jwhgithub
Copy link

@jwhgithub what exact error do you get? The LinkageError?

The code snippet above it's done inside a web application?

Hi Sbordet,

Thanks for your reply.

Yes, the code above is inside a web application. Error message is like below:

2020-12-15T23:18:31,189 [qtp738772871-36] WARN [AbstractWebSocketWrapper] - WebSocket error.

java.lang.LinkageError: loader constraint violation: when resolving method
"org.eclipse.jetty.websocket.client.WebSocketClient.(Lorg/eclipse/jetty/client/HttpClient;)V"
the class loader org.eclipse.jetty.webapp.WebAppClassLoader @b8b2184 (instance of org.eclipse.jetty.webapp.WebAppClassLoader,
child of org.codehaus.plexus.classworlds.realm.ClassRealm @2cd3fc29 org.codehaus.plexus.classworlds.realm.ClassRealm)
of the current class, com/scb/sabre/sapp/common/websocket/WSClient$WebSocketClientCreator,
and the class loader org.codehaus.plexus.classworlds.realm.ClassRealm @2cd3fc29 (instance of org.codehaus.plexus.classworlds.realm.ClassRealm, child of 'bootstrap')
for the method's defining class, org/eclipse/jetty/websocket/client/WebSocketClient,
have different Class objects for the type org/eclipse/jetty/client/HttpClient used in the signature

@lachlan-roberts
Copy link
Contributor

@jwhgithub do you have the websocket client jars included in your WEB-INF/lib, or are you using provided dependency from the server?

If you are using the websocket client jars as provided dependencies from the server, you would need to configure the HttpClient with jetty-websocket-httpclient.xml file in your resources directory. This xml file will be run with the server classloader instead of the webapps one.
see jetty-websocket-httpclient.xml

If you are not using a provided dependency and have the jars in WEB-INF/lib then you will need to hide the servers jetty-websocket-client classes from the webapp. You should add the following configuration to your start.ini file.

jetty.webapp.addServerClasses+=,+org.eclipse.jetty.websocket.
jetty.webapp.addSystemClasses+=,-org.eclipse.jetty.websocket.

This will also mean for the server you will only be able to use the javax.websocket API and not the Jetty WebSocket API.

@jwhgithub
Copy link

@jwhgithub do you have the websocket client jars included in your WEB-INF/lib, or are you using provided dependency from the server?

If you are using the websocket client jars as provided dependencies from the server, you would need to configure the HttpClient with jetty-websocket-httpclient.xml file in your resources directory. This xml file will be run with the server classloader instead of the webapps one.
see jetty-websocket-httpclient.xml

If you are not using a provided dependency and have the jars in WEB-INF/lib then you will need to hide the servers jetty-websocket-client classes from the webapp. You should add the following configuration to your start.ini file.

jetty.webapp.addServerClasses+=,+org.eclipse.jetty.websocket.
jetty.webapp.addSystemClasses+=,-org.eclipse.jetty.websocket.

This will also mean for the server you will only be able to use the javax.websocket API and not the Jetty WebSocket API.

@lachlan-roberts Thanks a lot for your detailed reply. Sorry for providing my feedback so late.
I tried the first solution with XML Config. It works with jetty 9.4.35.v20201120.

When I tried the same with jetty 9.4.14.v20181114, I noticed the "DefaultHttpClientProvider" could provide a httpClient with SslContextFactory[trustAll=false], seems the XML Config doesn't impact DefaultHTTPClientProvider.

@lachlan-roberts
Copy link
Contributor

@jwhgithub there have been fixes to the HttpClientProvider mechanism since 9.4.14 so that could explain your issues with that. It should be all working now but if you experience similar problems after 9.4.35 you should open a new issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants