Skip to content

Commit

Permalink
Issue jetty#3341 - Use HttpClientProvider in WebSocketCoreClient
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Feb 14, 2019
1 parent b9797b0 commit c6fd7a6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
7 changes: 0 additions & 7 deletions jetty-websocket/jetty-websocket-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
<artifactId>jetty-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions jetty-websocket/websocket-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<artifactId>jetty-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
requires org.eclipse.jetty.io;
requires org.eclipse.jetty.http;
requires org.eclipse.jetty.server;
requires static org.eclipse.jetty.xml;
requires org.eclipse.jetty.util;

uses Extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// ========================================================================
//

package org.eclipse.jetty.websocket.client.impl;
package org.eclipse.jetty.websocket.core.client;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.ssl.SslContextFactory;
Expand All @@ -26,13 +26,14 @@ class DefaultHttpClientProvider
{
public static HttpClient newHttpClient()
{
SslContextFactory sslContextFactory = new SslContextFactory();
HttpClient client = new HttpClient(sslContextFactory);
HttpClient client = new HttpClient(new SslContextFactory());
client.getSslContextFactory().setEndpointIdentificationAlgorithm("HTTPS");

QueuedThreadPool threadPool = new QueuedThreadPool();
String name = "WebSocketClient@" + client.hashCode();
threadPool.setName(name);
threadPool.setName("WebSocketClient@" + client.hashCode());
threadPool.setDaemon(true);
client.setExecutor(threadPool);

return client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
// ========================================================================
//

package org.eclipse.jetty.websocket.client.impl;
package org.eclipse.jetty.websocket.core.client;

import java.lang.reflect.Method;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.log.Log;

import java.lang.reflect.Method;

public final class HttpClientProvider
{
public static HttpClient get()
Expand All @@ -31,7 +31,7 @@ public static HttpClient get()
{
if (Class.forName("org.eclipse.jetty.xml.XmlConfiguration") != null)
{
Class<?> xmlClazz = Class.forName("org.eclipse.jetty.websocket.client.XmlBasedHttpClientProvider");
Class<?> xmlClazz = Class.forName("org.eclipse.jetty.websocket.core.client.XmlBasedHttpClientProvider");
Method getMethod = xmlClazz.getMethod("get");
Object ret = getMethod.invoke(null);
if ((ret != null) && (ret instanceof HttpClient))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.ShutdownThread;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.FrameHandler;
Expand Down Expand Up @@ -61,12 +60,9 @@ public WebSocketCoreClient(HttpClient httpClient)

public WebSocketCoreClient(HttpClient httpClient, FrameHandler.Customizer customizer)
{
if (httpClient==null)
{
httpClient = new HttpClient(new SslContextFactory());
httpClient.getSslContextFactory().setEndpointIdentificationAlgorithm("HTTPS");
httpClient.setName(String.format("%s@%x",getClass().getSimpleName(),hashCode()));
}
if (httpClient == null)
httpClient = HttpClientProvider.get();

this.httpClient = httpClient;
this.extensionRegistry = new WebSocketExtensionRegistry();
this.objectFactory = new DecoratedObjectFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
// ========================================================================
//

package org.eclipse.jetty.websocket.client.impl;
package org.eclipse.jetty.websocket.core.client;

import java.io.InputStream;
import java.net.URL;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.xml.XmlConfiguration;

import java.io.InputStream;
import java.net.URL;

class XmlBasedHttpClientProvider
{
public static HttpClient get()
Expand Down

0 comments on commit c6fd7a6

Please sign in to comment.