use of io.undertow.server.handlers.PathHandler in project undertow by undertow-io.
the class DispatcherForwardTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DispatcherForwardTestCase.class)).addServlet(new ServletInfo("forward", MessageServlet.class).addInitParam(MessageServlet.MESSAGE, "forwarded").addMapping("/forward")).addServlet(new ServletInfo("dispatcher", ForwardServlet.class).addMapping("/dispatch")).addServlet(new ServletInfo("pathTest", PathTestServlet.class).addMapping("/path")).addFilter(new FilterInfo("notforwarded", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Not forwarded")).addFilter(new FilterInfo("inc", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Path!")).addFilter(new FilterInfo("nameFilter", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Name!")).addFilterUrlMapping("notforwarded", "/forward", DispatcherType.REQUEST).addFilterUrlMapping("inc", "/forward", DispatcherType.FORWARD).addFilterServletNameMapping("nameFilter", "forward", DispatcherType.FORWARD);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(new AccessLogHandler(root, RECEIVER, "%r %U %R", AccessLogFileTestCase.class.getClassLoader()));
}
use of io.undertow.server.handlers.PathHandler in project undertow by undertow-io.
the class DispatcherIncludeTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DispatcherIncludeTestCase.class)).addServlet(new ServletInfo("include", MessageServlet.class).addInitParam(MessageServlet.MESSAGE, "included").addMapping("/include")).addServlet(new ServletInfo("dispatcher", IncludeServlet.class).addMapping("/dispatch")).addServlet(new ServletInfo("pathTest", PathTestServlet.class).addMapping("/path")).addFilter(new FilterInfo("notIncluded", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Not Included")).addFilter(new FilterInfo("inc", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Path!")).addFilter(new FilterInfo("nameFilter", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Name!")).addFilterUrlMapping("notIncluded", "/include", DispatcherType.REQUEST).addFilterUrlMapping("inc", "/include", DispatcherType.INCLUDE).addFilterServletNameMapping("nameFilter", "include", DispatcherType.INCLUDE);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.server.handlers.PathHandler 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(new WebSocketDeploymentInfo.ContainerReadyListener() {
@Override
public void ready(ServerWebSocketContainer container) {
deployment = container;
}
}));
builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role1").setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
path.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(path);
}
use of io.undertow.server.handlers.PathHandler in project undertow by undertow-io.
the class JsrWebSocketServer07Test method deployServlet.
private ServletContext 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.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
return manager.getDeployment().getServletContext();
}
use of io.undertow.server.handlers.PathHandler in project undertow by undertow-io.
the class PathTestCase method testBasicPathHanding.
@Test
public void testBasicPathHanding() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
final PathHandler handler = new PathHandler();
handler.addPrefixPath("a", new RemainingPathHandler("/a"));
handler.addPrefixPath("/aa", new RemainingPathHandler("/aa"));
handler.addExactPath("/aa", new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseSender().send("Exact /aa match:" + exchange.getRelativePath() + ":" + exchange.getResolvedPath());
}
});
handler.addPrefixPath("/aa/anotherSubPath", new RemainingPathHandler("/aa/anotherSubPath"));
final PathHandler sub = new PathHandler();
handler.addPrefixPath("/path", sub);
sub.addPrefixPath("/subpath", new RemainingPathHandler("/subpath"));
sub.addPrefixPath("/", new RemainingPathHandler("/path"));
DefaultServer.setRootHandler(handler);
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/");
result = client.execute(get);
Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
runPathTest(client, "/path", "/path", "");
runPathTest(client, "/path/a", "/path", "/a");
runPathTest(client, "/path/subpath", "/subpath", "");
runPathTest(client, "/path/subpath/", "/subpath", "/");
runPathTest(client, "/path/subpath/foo", "/subpath", "/foo");
runPathTest(client, "/a", "/a", "");
runPathTest(client, "/aa/anotherSubPath", "/aa/anotherSubPath", "");
runPathTest(client, "/aa/anotherSubPath/bob", "/aa/anotherSubPath", "/bob");
runPathTest(client, "/aa/b?a=b", "/aa", "/b", Collections.singletonMap("a", "b"));
runPathTest(client, "/path/:bar/baz", "/path", "/:bar/baz");
//now test the exact path match
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/aa");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("Exact /aa match::/aa", HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations