use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project minijax by minijax.
the class WebSocketTest method testRun.
@Test
public void testRun() throws Exception {
final Minijax minijax = createMinijax();
minijax.register(WebSocketResource.class);
minijax.start();
final MinijaxApplication application = minijax.getDefaultApplication();
final DeploymentInfo deploymentInfo = new DeploymentInfo();
MinijaxWebSocketUtils.init(deploymentInfo, application);
final WebSocketDeploymentInfo webSocketDeploymentInfo = (WebSocketDeploymentInfo) deploymentInfo.getServletContextAttributes().get(WebSocketDeploymentInfo.ATTRIBUTE_NAME);
final ServerEndpointConfig endpointConfig = webSocketDeploymentInfo.getProgramaticEndpoints().get(0);
final MinijaxWebSocketConfigurator configurator = (MinijaxWebSocketConfigurator) endpointConfig.getConfigurator();
final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/echo"));
try (MinijaxRequestContext context = new MinijaxRequestContext(application, request, null)) {
configurator.modifyHandshake(endpointConfig, null, null);
final AnnotatedEndpoint endpoint = configurator.getEndpointInstance(AnnotatedEndpoint.class);
assertNotNull(endpoint);
}
}
use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class TestMessagesReceivedInOrder method setup.
@BeforeClass
public static void setup() throws ServletException {
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(TestMessagesReceivedInOrder.class.getClassLoader()).setContextPath("/").setResourceManager(new TestResourceLoader(TestMessagesReceivedInOrder.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorkerSupplier()).addEndpoint(EchoSocket.class)).setDeploymentName("servletContext.war");
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", deploymentManager.start()));
}
use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class AnnotatedEndpointTest method setup.
@BeforeClass
public static void setup() throws Exception {
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(AnnotatedEndpointTest.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(AnnotatedEndpointTest.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorkerSupplier()).addEndpoint(MessageEndpoint.class).addEndpoint(AnnotatedClientEndpoint.class).addEndpoint(AnnotatedClientEndpointWithConfigurator.class).addEndpoint(IncrementEndpoint.class).addEndpoint(EncodingEndpoint.class).addEndpoint(EncodingGenericsEndpoint.class).addEndpoint(TimeoutEndpoint.class).addEndpoint(ErrorEndpoint.class).addEndpoint(RootContextEndpoint.class).addEndpoint(ThreadSafetyEndpoint.class).addEndpoint(RequestUriEndpoint.class).addListener(readyContainer -> deployment = readyContainer).addEndpoint(ServerEndpointConfig.Builder.create(AnnotatedAddedProgrammaticallyEndpoint.class, AnnotatedAddedProgrammaticallyEndpoint.PATH).build())).addServlet(new ServletInfo("redirect", RedirectServlet.class).addMapping("/redirect")).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 BinaryEndpointTest method setup.
@BeforeClass
public static void setup() throws Exception {
bytes = new byte[256 * 1024];
new Random().nextBytes(bytes);
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(BinaryEndpointTest.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).addServlet(Servlets.servlet("bin", BinaryEndpointServlet.class).setLoadOnStartup(100)).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorkerSupplier()).addListener(serverContainer -> deployment = serverContainer)).setDeploymentName("servletContext.war");
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
DefaultServer.setRootHandler(new RequestDumpingHandler(deploymentManager.start()));
DefaultServer.startSSLServer();
}
use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.
the class JSRWebSocketServer method main.
public static void main(final String[] args) {
PathHandler path = Handlers.path();
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
server.start();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(JSRWebSocketServer.class.getClassLoader()).setContextPath("/").addWelcomePage("index.html").setResourceManager(new ClassPathResourceManager(JSRWebSocketServer.class.getClassLoader(), JSRWebSocketServer.class.getPackage())).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 100)).addEndpoint(JsrChatWebSocketEndpoint.class)).setDeploymentName("chat.war");
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
try {
path.addPrefixPath("/", manager.start());
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
Aggregations