use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class ProgramaticAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8192);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).setDispatchToWorkerThread(true).addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")).addExtension(new PerMessageDeflateHandshake()));
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
openListener.setRootHandler(deploymentManager.start());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class ClientEndpointReconnectTestCase method setup.
@BeforeClass
public static void setup() throws Exception {
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(ClientEndpointReconnectTestCase.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(ClientEndpointReconnectTestCase.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 8192)).setWorker(DefaultServer.getWorkerSupplier()).addEndpoint(DisconnectServerEndpoint.class).addEndpoint(AnnotatedClientReconnectEndpoint.class).addListener(containerReady -> deployment = containerReady).setReconnectHandler(new WebSocketReconnectHandler() {
@Override
public long disconnected(CloseReason closeReason, URI connectionUri, Session session, int disconnectCount) {
if (disconnectCount < 3) {
return 1;
} else {
return -1;
}
}
@Override
public long reconnectFailed(IOException exception, URI connectionUri, Session session, int failedCount) {
failed = true;
return -1;
}
})).setDeploymentName("servletContext.war");
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", deploymentManager.start()));
}
use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class WebsocketBasicAuthTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler path = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
ServletIdentityManager identityManager = new ServletIdentityManager();
identityManager.addUser("user1", "password1", "role1");
identityManager.addUser("charsetUser", "password-ΓΌ", "role1");
LoginConfig loginConfig = new LoginConfig(REALM_NAME);
Map<String, String> props = new HashMap<>();
props.put("charset", "ISO_8859_1");
props.put("user-agent-charsets", "Chrome,UTF-8,OPR,UTF-8");
loginConfig.addFirstAuthMethod(new AuthMethodConfig("BASIC", props));
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(loginConfig).addFilter(Servlets.filter("wrapper", WrapperFilter.class)).addFilterUrlMapping("wrapper", "/wrapper/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(SecuredEndpoint.class).addListener(containerReady -> deployment = containerReady));
builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role1").setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
path.addPrefixPath(builder.getContextPath(), deploymentManager.start());
DefaultServer.setRootHandler(path);
}
use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class AnnotatedAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
DeploymentManager deploymentManager = null;
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8024);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(AnnotatedAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).addEndpoint(AutobahnAnnotatedEndpoint.class).setDispatchToWorkerThread(true).addExtension(new PerMessageDeflateHandshake())).addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST);
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
openListener.setRootHandler(deploymentManager.start());
} catch (Exception e) {
log.error("failed to start server", e);
} finally {
if (deploymentManager != null) {
deploymentManager.undeploy();
try {
deploymentManager.stop();
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
}
}
use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class WebsocketStressTestCase method setup.
@BeforeClass
public static void setup() throws Exception {
defaultContainer = ContainerProvider.getWebSocketContainer();
executor = Executors.newFixedThreadPool(NUM_THREADS);
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(WebsocketStressTestCase.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(WebsocketStressTestCase.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(StressEndpoint.class).setDispatchToWorkerThread(true).addListener(containerReady -> deployment = containerReady)).setDeploymentName("servletContext.war");
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", deploymentManager.start()));
}
Aggregations