@BeforeClass public static void setup() throws Exception { final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(ProgramaticLazyEndpointTest.class.getClassLoader()) .setContextPath("/") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .addServlet(Servlets.servlet("add", AddEndpointServlet.class).setLoadOnStartup(100)) .addServletContextAttribute( WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo() .setBuffers(new ByteBufferSlicePool(100, 1000)) .setWorker(DefaultServer.getWorker()) .addListener( new WebSocketDeploymentInfo.ContainerReadyListener() { @Override public void ready(ServerWebSocketContainer container) { deployment = container; } })) .setDeploymentName("servletContext.war"); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); DefaultServer.setRootHandler(manager.start()); }
@Override public void destroy() throws Exception { manager.undeploy(); ServletContainer container = server.getValue().getServletContainer().getValue().getServletContainer(); container.removeDeployment(deploymentInfo); }
@Test public void testExtensionMatchServletWithGlobalFilter() throws IOException, ServletException { DeploymentInfo builder = new DeploymentInfo(); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class).addMapping("*.jsp")); builder.addFilter(new FilterInfo("/*", PathFilter.class)); builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST); builder .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(FilterPathMappingTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war"); final DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); TestHttpClient client = new TestHttpClient(); try { runTest(client, "aa.jsp", "*.jsp - /aa.jsp - null", "/*"); } finally { client.getConnectionManager().shutdown(); } }
@Override public void create() throws Exception { ServletContainer container = server.getValue().getServletContainer().getValue().getServletContainer(); manager = container.addDeployment(deploymentInfo); manager.deploy(); }
@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 ByteBufferSlicePool(100, 1000)) .setWorker(DefaultServer.getWorker()) .addEndpoint(DisconnectServerEndpoint.class) .addEndpoint(AnnotatedClientReconnectEndpoint.class) .addListener( new WebSocketDeploymentInfo.ContainerReadyListener() { @Override public void ready(ServerWebSocketContainer container) { deployment = container; } }) .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 manager = container.addDeployment(builder); manager.deploy(); DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start())); }
@Override public ServletContext getContext(final String uripath) { DeploymentManager deploymentByPath = servletContainer.getDeploymentByPath(uripath); if (deploymentByPath == null) { return null; } return deploymentByPath.getDeployment().getServletContext(); }
protected PathHandler mountServerEndpoints( final PathHandler pathHandler, List<Class<?>> serverEndpoints) throws ServletException { if (!serverEndpoints.isEmpty()) { DeploymentInfo builder = new DeploymentInfo().setClassLoader(this.getClass().getClassLoader()).setContextPath("/"); WebSocketDeploymentInfo wsDeployInfo = new WebSocketDeploymentInfo(); wsDeployInfo.setBuffers(new ByteBufferSlicePool(100, 1000)); for (Class<?> serverEndpoint : serverEndpoints) { wsDeployInfo.addEndpoint(serverEndpoint); } builder.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, wsDeployInfo); builder.setDeploymentName("websocketDeploy.war"); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); pathHandler.addPrefixPath("/", manager.start()); } return pathHandler; }
@BeforeClass public static void setup() throws Exception { js = UndertowJS.builder() .addResources( new ClassPathResourceManager( JavascriptSecurityTestCase.class.getClassLoader(), JavascriptSecurityTestCase.class.getPackage()), "security.js") .build(); js.start(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletIdentityManager identityManager = new ServletIdentityManager(); identityManager.addUser("user1", "password1", "admin"); identityManager.addUser("user2", "password2", "user"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(JavascriptSecurityTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .setIdentityManager(identityManager) .setLoginConfig(new LoginConfig("BASIC", "Test Realm")) .addInnerHandlerChainWrapper( new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return js.getHandler(handler); } }); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); PathHandler root = new PathHandler(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
private void deployServlet(final ServerWebSocketContainer deployment) throws ServletException { final DeploymentInfo builder; builder = new DeploymentInfo() .setClassLoader(getClass().getClassLoader()) .setContextPath("/") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("websocket.war") .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)) .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST) .addServletContextAttribute( javax.websocket.server.ServerContainer.class.getName(), deployment); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo s = new ServletInfo("servlet", HelloServlet.class).addMapping("/aa"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(MockRequestTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlet(s); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); deployment = manager.getDeployment(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
@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(new ByteBufferSlicePool(100, 1000)) .setWorker(DefaultServer.getWorker()) .addEndpoint(EchoSocket.class)) .setDeploymentName("servletContext.war"); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", manager.start())); }
@Test public void testBasicFilterMappings() throws IOException, ServletException { DeploymentInfo builder = new DeploymentInfo(); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); builder.addServlet(new ServletInfo("/a/*", PathMappingServlet.class).addMapping("/a/*")); builder.addServlet(new ServletInfo("/aa", PathMappingServlet.class).addMapping("/aa")); builder.addServlet(new ServletInfo("/", PathMappingServlet.class).addMapping("/")); builder.addServlet(new ServletInfo("contextRoot", PathMappingServlet.class).addMapping("")); builder.addServlet( new ServletInfo("/myservlet/*", PathMappingServlet.class).addMapping("/myservlet/*")); builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class).addMapping("*.jsp")); builder.addServlet( new ServletInfo("/hello/*", PathMappingServlet.class).addMapping("/hello/*")); builder.addServlet(new ServletInfo("/test/*", PathMappingServlet.class).addMapping("/test/*")); builder.addFilter(new FilterInfo("/*", PathFilter.class)); builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST); // non standard, but we still support it builder.addFilter(new FilterInfo("*", PathFilter.class)); builder.addFilterUrlMapping("*", "*", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("/a/*", PathFilter.class)); builder.addFilterUrlMapping("/a/*", "/a/*", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("/aa", PathFilter.class)); builder.addFilterUrlMapping("/aa", "/aa", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("*.bop", PathFilter.class)); builder.addFilterUrlMapping("*.bop", "*.bop", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("/myservlet/myfilter/*", PathFilter.class)); builder.addFilterUrlMapping( "/myservlet/myfilter/*", "/myservlet/myfilter/*", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("/myfilter/*", PathFilter.class)); builder.addFilterUrlMapping("/myfilter/*", "/myfilter/*", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("contextRoot", PathFilter.class)); builder.addFilterServletNameMapping("contextRoot", "contextRoot", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("defaultName", PathFilter.class)); builder.addFilterServletNameMapping("defaultName", "/", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("/helloworld/index.html", PathFilter.class)); builder.addFilterUrlMapping( "/helloworld/index.html", "/helloworld/index.html", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("/test", PathFilter.class)); builder.addFilterUrlMapping("/test", "/test", DispatcherType.REQUEST); builder .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(FilterPathMappingTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war"); final DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); TestHttpClient client = new TestHttpClient(); try { runTest(client, "test", "/test/* - /test - null", "/*", "*", "/test"); runTest(client, "aa", "/aa - /aa - null", "/*", "*", "/aa"); runTest(client, "a/c", "/a/* - /a - /c", "/*", "*", "/a/*"); runTest(client, "a", "/a/* - /a - null", "/*", "*", "/a/*"); runTest(client, "aa/b", "/ - /aa/b - null", "/*", "*", "defaultName"); runTest(client, "a/b/c/d", "/a/* - /a - /b/c/d", "/*", "*", "/a/*"); runTest(client, "defaultStuff", "/ - /defaultStuff - null", "/*", "*", "defaultName"); runTest(client, "", "contextRoot - / - null", "/*", "*", "contextRoot"); runTest(client, "yyyy.bop", "/ - /yyyy.bop - null", "/*", "*", "*.bop", "defaultName"); runTest(client, "a/yyyy.bop", "/a/* - /a - /yyyy.bop", "/*", "*", "*.bop", "/a/*"); runTest( client, "myservlet/myfilter/file.dat", "/myservlet/* - /myservlet - /myfilter/file.dat", "/*", "*", "/myservlet/myfilter/*"); runTest( client, "myservlet/myfilter/file.jsp", "/myservlet/* - /myservlet - /myfilter/file.jsp", "/*", "*", "/myservlet/myfilter/*"); runTest( client, "otherservlet/myfilter/file.jsp", "*.jsp - /otherservlet/myfilter/file.jsp - null", "/*", "*"); runTest( client, "myfilter/file.jsp", "*.jsp - /myfilter/file.jsp - null", "/*", "*", "/myfilter/*"); runTest( client, "helloworld/index.html", "/ - /helloworld/index.html - null", "/*", "*", "/helloworld/index.html", "defaultName"); } finally { client.getConnectionManager().shutdown(); } }