Modify SecureClientContainerExample to use the new getContainer(HttpClient) method.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-03-26 14:55:32 +11:00
parent a86a0c2662
commit 47ec9b1a7e
2 changed files with 21 additions and 4 deletions

View File

@ -45,6 +45,17 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -13,6 +13,7 @@
package examples;
import java.lang.management.ManagementFactory;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.websocket.ClientEndpointConfig;
@ -21,9 +22,11 @@ import javax.websocket.WebSocketContainer;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.util.component.Container;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.javax.client.internal.JavaxWebSocketClientContainer;
import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainerProvider;
public class SecureClientContainerExample
{
@ -76,9 +79,12 @@ public class SecureClientContainerExample
clientConnector.setSslContextFactory(ssl);
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP(clientConnector));
JavaxWebSocketClientContainer clientContainer = new JavaxWebSocketClientContainer(httpClient);
clientContainer.addManaged(httpClient); // allow clientContainer to own httpClient (for start/stop lifecycle)
clientContainer.start();
WebSocketContainer clientContainer = JavaxWebSocketClientContainerProvider.getContainer(httpClient);
// Components can be added as a bean to the WebSocketContainer with the Container static method.
MBeanContainer mbeanContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
Container.addBean(clientContainer, mbeanContainer);
return clientContainer;
}
}