use of io.undertow.servlet.api.ServletInfo in project undertow by undertow-io.
the class RewriteTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
DeploymentUtils.setupServlet(new ServletExtension() {
@Override
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
deploymentInfo.addOuterHandlerChainWrapper(new HandlerWrapper() {
@Override
public HttpHandler wrap(HttpHandler handler) {
byte[] data = "RewriteRule /foo1 /bar1".getBytes(StandardCharsets.UTF_8);
RewriteConfig config = RewriteConfigFactory.build(new ByteArrayInputStream(data));
return new RewriteHandler(config, handler);
}
});
}
}, new ServletInfo("servlet", PathTestServlet.class).addMapping("/"));
}
use of io.undertow.servlet.api.ServletInfo 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.servlet.api.ServletInfo 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.servlet.api.ServletInfo in project undertow by undertow-io.
the class ServletContextImpl method addServlet.
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final String className) {
ensureNotProgramaticListener();
ensureNotInitialized();
try {
if (deploymentInfo.getServlets().containsKey(servletName)) {
return null;
}
Class<? extends Servlet> servletClass = (Class<? extends Servlet>) deploymentInfo.getClassLoader().loadClass(className);
ServletInfo servlet = new ServletInfo(servletName, servletClass, deploymentInfo.getClassIntrospecter().createInstanceFactory(servletClass));
readServletAnnotations(servlet);
deploymentInfo.addServlet(servlet);
ServletHandler handler = deployment.getServlets().addServlet(servlet);
return new ServletRegistrationImpl(servlet, handler.getManagedServlet(), deployment);
} catch (ClassNotFoundException e) {
throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e);
} catch (NoSuchMethodException e) {
throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(className, e);
}
}
use of io.undertow.servlet.api.ServletInfo 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.getWorker()).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(new WebSocketDeploymentInfo.ContainerReadyListener() {
@Override
public void ready(ServerWebSocketContainer container) {
deployment = container;
}
})).addServlet(new ServletInfo("redirect", RedirectServlet.class).addMapping("/redirect")).setDeploymentName("servletContext.war");
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start()));
}
Aggregations