Issue #3341 - Use HttpClientProvider in WebSocketCoreClient
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
b9797b01eb
commit
c6fd7a616f
|
@ -32,13 +32,6 @@
|
||||||
<artifactId>jetty-client</artifactId>
|
<artifactId>jetty-client</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
|
||||||
<artifactId>jetty-xml</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-server</artifactId>
|
<artifactId>jetty-server</artifactId>
|
||||||
|
|
|
@ -31,6 +31,12 @@
|
||||||
<artifactId>jetty-http</artifactId>
|
<artifactId>jetty-http</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-xml</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-client</artifactId>
|
<artifactId>jetty-client</artifactId>
|
||||||
|
|
|
@ -37,6 +37,7 @@ module org.eclipse.jetty.websocket.core
|
||||||
requires org.eclipse.jetty.io;
|
requires org.eclipse.jetty.io;
|
||||||
requires org.eclipse.jetty.http;
|
requires org.eclipse.jetty.http;
|
||||||
requires org.eclipse.jetty.server;
|
requires org.eclipse.jetty.server;
|
||||||
|
requires static org.eclipse.jetty.xml;
|
||||||
requires org.eclipse.jetty.util;
|
requires org.eclipse.jetty.util;
|
||||||
|
|
||||||
uses Extension;
|
uses Extension;
|
||||||
|
|
|
@ -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.client.HttpClient;
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
|
@ -26,13 +26,14 @@ class DefaultHttpClientProvider
|
||||||
{
|
{
|
||||||
public static HttpClient newHttpClient()
|
public static HttpClient newHttpClient()
|
||||||
{
|
{
|
||||||
SslContextFactory sslContextFactory = new SslContextFactory();
|
HttpClient client = new HttpClient(new SslContextFactory());
|
||||||
HttpClient client = new HttpClient(sslContextFactory);
|
client.getSslContextFactory().setEndpointIdentificationAlgorithm("HTTPS");
|
||||||
|
|
||||||
QueuedThreadPool threadPool = new QueuedThreadPool();
|
QueuedThreadPool threadPool = new QueuedThreadPool();
|
||||||
String name = "WebSocketClient@" + client.hashCode();
|
threadPool.setName("WebSocketClient@" + client.hashCode());
|
||||||
threadPool.setName(name);
|
|
||||||
threadPool.setDaemon(true);
|
threadPool.setDaemon(true);
|
||||||
client.setExecutor(threadPool);
|
client.setExecutor(threadPool);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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.client.HttpClient;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public final class HttpClientProvider
|
public final class HttpClientProvider
|
||||||
{
|
{
|
||||||
public static HttpClient get()
|
public static HttpClient get()
|
||||||
|
@ -31,7 +31,7 @@ public final class HttpClientProvider
|
||||||
{
|
{
|
||||||
if (Class.forName("org.eclipse.jetty.xml.XmlConfiguration") != null)
|
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");
|
Method getMethod = xmlClazz.getMethod("get");
|
||||||
Object ret = getMethod.invoke(null);
|
Object ret = getMethod.invoke(null);
|
||||||
if ((ret != null) && (ret instanceof HttpClient))
|
if ((ret != null) && (ret instanceof HttpClient))
|
|
@ -27,7 +27,6 @@ import org.eclipse.jetty.util.DecoratedObjectFactory;
|
||||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
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.util.thread.ShutdownThread;
|
||||||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||||
|
@ -61,12 +60,9 @@ public class WebSocketCoreClient extends ContainerLifeCycle implements FrameHand
|
||||||
|
|
||||||
public WebSocketCoreClient(HttpClient httpClient, FrameHandler.Customizer customizer)
|
public WebSocketCoreClient(HttpClient httpClient, FrameHandler.Customizer customizer)
|
||||||
{
|
{
|
||||||
if (httpClient==null)
|
if (httpClient == null)
|
||||||
{
|
httpClient = HttpClientProvider.get();
|
||||||
httpClient = new HttpClient(new SslContextFactory());
|
|
||||||
httpClient.getSslContextFactory().setEndpointIdentificationAlgorithm("HTTPS");
|
|
||||||
httpClient.setName(String.format("%s@%x",getClass().getSimpleName(),hashCode()));
|
|
||||||
}
|
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
this.extensionRegistry = new WebSocketExtensionRegistry();
|
this.extensionRegistry = new WebSocketExtensionRegistry();
|
||||||
this.objectFactory = new DecoratedObjectFactory();
|
this.objectFactory = new DecoratedObjectFactory();
|
||||||
|
|
|
@ -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.client.HttpClient;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
class XmlBasedHttpClientProvider
|
class XmlBasedHttpClientProvider
|
||||||
{
|
{
|
||||||
public static HttpClient get()
|
public static HttpClient get()
|
Loading…
Reference in New Issue