use of javax.websocket.Extension in project tomcat by apache.
the class TesterWsClientAutobahn method executeTestCase.
private static void executeTestCase(WebSocketContainer wsc, int testCase) throws Exception {
URI uri = new URI("ws://" + HOST + ":" + PORT + "/runCase?case=" + testCase + "&agent=" + USER_AGENT);
TestCaseClient testCaseClient = new TestCaseClient();
Extension permessageDeflate = new WsExtension("permessage-deflate");
// Advertise support for client_max_window_bits
// Client only supports some values so there will be some failures here
// Note Autobahn returns a 400 response if you provide a value for
// client_max_window_bits
permessageDeflate.getParameters().add(new WsExtensionParameter("client_max_window_bits", null));
List<Extension> extensions = new ArrayList<>(1);
extensions.add(permessageDeflate);
Endpoint ep = new PojoEndpointClient(testCaseClient, null);
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
ClientEndpointConfig config = builder.extensions(extensions).build();
wsc.connectToServer(ep, config, uri);
testCaseClient.waitForClose();
}
use of javax.websocket.Extension in project tomcat by apache.
the class TestWsWebSocketContainer method doTestPerMessageDeflateClient.
private void doTestPerMessageDeflateClient(String msg, int count) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
tomcat.start();
Extension perMessageDeflate = new WsExtension(PerMessageDeflate.NAME);
List<Extension> extensions = new ArrayList<>(1);
extensions.add(perMessageDeflate);
ClientEndpointConfig clientConfig = ClientEndpointConfig.Builder.create().extensions(extensions).build();
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
Session wsSession = wsContainer.connectToServer(TesterProgrammaticEndpoint.class, clientConfig, new URI("ws://" + getHostName() + ":" + getPort() + TesterEchoServer.Config.PATH_ASYNC));
CountDownLatch latch = new CountDownLatch(count);
BasicText handler = new BasicText(latch, msg);
wsSession.addMessageHandler(handler);
for (int i = 0; i < count; i++) {
wsSession.getBasicRemote().sendText(msg);
}
boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);
Assert.assertTrue(latchResult);
((WsWebSocketContainer) wsContainer).destroy();
}
use of javax.websocket.Extension in project jetty.project by eclipse.
the class ClientContainer method getInstalledExtensions.
@Override
public Set<Extension> getInstalledExtensions() {
Set<Extension> ret = new HashSet<>();
ExtensionFactory extensions = client.getExtensionFactory();
for (String name : extensions.getExtensionNames()) {
ret.add(new JsrExtension(name));
}
return ret;
}
use of javax.websocket.Extension in project undertow by undertow-io.
the class Bootstrap method handleDeployment.
@Override
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
WebSocketDeploymentInfo info = (WebSocketDeploymentInfo) deploymentInfo.getServletContextAttributes().get(WebSocketDeploymentInfo.ATTRIBUTE_NAME);
if (info == null) {
return;
}
XnioWorker worker = info.getWorker();
if (worker == null) {
ServerWebSocketContainer defaultContainer = UndertowContainerProvider.getDefaultContainer();
if (defaultContainer == null) {
throw JsrWebSocketLogger.ROOT_LOGGER.xnioWorkerWasNullAndNoDefault();
}
JsrWebSocketLogger.ROOT_LOGGER.xnioWorkerWasNull();
worker = defaultContainer.getXnioWorker();
}
ByteBufferPool buffers = info.getBuffers();
if (buffers == null) {
ServerWebSocketContainer defaultContainer = UndertowContainerProvider.getDefaultContainer();
if (defaultContainer == null) {
throw JsrWebSocketLogger.ROOT_LOGGER.bufferPoolWasNullAndNoDefault();
}
JsrWebSocketLogger.ROOT_LOGGER.bufferPoolWasNull();
buffers = defaultContainer.getBufferPool();
}
final List<ThreadSetupHandler> setup = new ArrayList<>();
setup.add(new ContextClassLoaderSetupAction(deploymentInfo.getClassLoader()));
setup.addAll(deploymentInfo.getThreadSetupActions());
InetSocketAddress bind = null;
if (info.getClientBindAddress() != null) {
bind = new InetSocketAddress(info.getClientBindAddress(), 0);
}
List<Extension> extensions = new ArrayList<>();
for (ExtensionHandshake e : info.getExtensions()) {
extensions.add(new ExtensionImpl(e.getName(), Collections.emptyList()));
}
ServerWebSocketContainer container = new ServerWebSocketContainer(deploymentInfo.getClassIntrospecter(), servletContext.getClassLoader(), worker, buffers, setup, info.isDispatchToWorkerThread(), bind, info.getReconnectHandler(), extensions);
try {
for (Class<?> annotation : info.getAnnotatedEndpoints()) {
container.addEndpoint(annotation);
}
for (ServerEndpointConfig programatic : info.getProgramaticEndpoints()) {
container.addEndpoint(programatic);
}
} catch (DeploymentException e) {
throw new RuntimeException(e);
}
servletContext.setAttribute(ServerContainer.class.getName(), container);
info.containerReady(container);
SecurityActions.addContainer(deploymentInfo.getClassLoader(), container);
deploymentInfo.addListener(Servlets.listener(WebSocketListener.class));
}
use of javax.websocket.Extension in project undertow by undertow-io.
the class ServerWebSocketContainer method connectToServer.
public Session connectToServer(final Endpoint endpointInstance, final ClientEndpointConfig config, WebSocketClient.ConnectionBuilder connectionBuilder) throws DeploymentException, IOException {
if (closed) {
throw new ClosedChannelException();
}
ClientEndpointConfig cec = config != null ? config : ClientEndpointConfig.Builder.create().build();
WebSocketClientNegotiation clientNegotiation = connectionBuilder.getClientNegotiation();
IoFuture<WebSocketChannel> session = connectionBuilder.connect();
Number timeout = (Number) cec.getUserProperties().get(TIMEOUT);
if (session.await(timeout == null ? DEFAULT_WEB_SOCKET_TIMEOUT_SECONDS : timeout.intValue(), TimeUnit.SECONDS) == IoFuture.Status.WAITING) {
//add a notifier to close the channel if the connection actually completes
session.cancel();
session.addNotifier(new IoFuture.HandlingNotifier<WebSocketChannel, Object>() {
@Override
public void handleDone(WebSocketChannel data, Object attachment) {
IoUtils.safeClose(data);
}
}, null);
throw JsrWebSocketMessages.MESSAGES.connectionTimedOut();
}
WebSocketChannel channel;
try {
channel = session.get();
} catch (UpgradeFailedException e) {
throw new DeploymentException(e.getMessage(), e);
}
EndpointSessionHandler sessionHandler = new EndpointSessionHandler(this);
final List<Extension> extensions = new ArrayList<>();
final Map<String, Extension> extMap = new HashMap<>();
for (Extension ext : cec.getExtensions()) {
extMap.put(ext.getName(), ext);
}
for (WebSocketExtension e : clientNegotiation.getSelectedExtensions()) {
Extension ext = extMap.get(e.getName());
if (ext == null) {
throw JsrWebSocketMessages.MESSAGES.extensionWasNotPresentInClientHandshake(e.getName(), clientNegotiation.getSupportedExtensions());
}
extensions.add(ExtensionImpl.create(e));
}
ConfiguredClientEndpoint configured = clientEndpoints.get(endpointInstance.getClass());
if (configured == null) {
synchronized (clientEndpoints) {
configured = clientEndpoints.get(endpointInstance.getClass());
if (configured == null) {
clientEndpoints.put(endpointInstance.getClass(), configured = new ConfiguredClientEndpoint());
}
}
}
EncodingFactory encodingFactory = EncodingFactory.createFactory(classIntrospecter, cec.getDecoders(), cec.getEncoders());
UndertowSession undertowSession = new UndertowSession(channel, connectionBuilder.getUri(), Collections.<String, String>emptyMap(), Collections.<String, List<String>>emptyMap(), sessionHandler, null, new ImmediateInstanceHandle<>(endpointInstance), cec, connectionBuilder.getUri().getQuery(), encodingFactory.createEncoding(cec), configured, clientNegotiation.getSelectedSubProtocol(), extensions, connectionBuilder);
endpointInstance.onOpen(undertowSession, cec);
channel.resumeReceives();
return undertowSession;
}
Aggregations