Search in sources :

Example 1 with WebSocketDeploymentInfo

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);
    }
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication) MinijaxRequestContext(org.minijax.MinijaxRequestContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Minijax(org.minijax.Minijax) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) AnnotatedEndpoint(io.undertow.websockets.jsr.annotated.AnnotatedEndpoint) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Test(org.junit.Test)

Example 2 with WebSocketDeploymentInfo

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()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 3 with WebSocketDeploymentInfo

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()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 4 with WebSocketDeploymentInfo

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();
}
Also used : Random(java.util.Random) ServletContainer(io.undertow.servlet.api.ServletContainer) RequestDumpingHandler(io.undertow.server.handlers.RequestDumpingHandler) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 5 with WebSocketDeploymentInfo

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Undertow(io.undertow.Undertow)

Aggregations

WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)22 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)19 ServletContainer (io.undertow.servlet.api.ServletContainer)14 BeforeClass (org.junit.BeforeClass)11 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)7 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)6 DeploymentManager (io.undertow.servlet.api.DeploymentManager)6 IOException (java.io.IOException)6 ServletException (javax.servlet.ServletException)5 HttpHandler (io.undertow.server.HttpHandler)4 FilterInfo (io.undertow.servlet.api.FilterInfo)4 ServletInfo (io.undertow.servlet.api.ServletInfo)4 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)4 URI (java.net.URI)4 ServerEndpoint (javax.websocket.server.ServerEndpoint)4 PathHandler (io.undertow.server.handlers.PathHandler)3 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)3 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)3 TestClassIntrospector (io.undertow.servlet.test.util.TestClassIntrospector)3 DefaultServer (io.undertow.testutils.DefaultServer)3