io.undertow.servlet.api.ServletInfo Java Examples

The following examples show how to use io.undertow.servlet.api.ServletInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServletContextListenerTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@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")
            .addServletContainerInitializer(new ServletContainerInitializerInfo(TestSci.class, Collections.<Class<?>>emptySet()))
            .addServlet(
                    new ServletInfo("servlet", MessageServlet.class)
                            .addMapping("/aa")
            )
            .addListener(new ListenerInfo(ServletContextTestListener.class));


    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #2
Source File: ServletAndResourceWelcomeFileTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    DeploymentInfo builder = new DeploymentInfo()
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(ServletPathMappingTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(ServletAndResourceWelcomeFileTestCase.class))
            .addWelcomePages("doesnotexist.html", "index.html", "default");

    builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class)
            .addMapping("*.html"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #3
Source File: ParameterEchoTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", ParameterEchoServlet.class)
            .addMapping("/aaa");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(ParameterEchoTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlet(s);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #4
Source File: DefaultAuthorizationManager.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isUserInRole(String role, Account account, ServletInfo servletInfo, HttpServletRequest request, Deployment deployment) {

    final Map<String, Set<String>> principalVersusRolesMap = deployment.getDeploymentInfo().getPrincipalVersusRolesMap();
    final Set<String> roles = principalVersusRolesMap.get(account.getPrincipal().getName());
    //TODO: a more efficient imple
    for (SecurityRoleRef ref : servletInfo.getSecurityRoleRefs()) {
        if (ref.getRole().equals(role)) {
            if (roles != null && roles.contains(ref.getLinkedRole())) {
                return true;
            }
            return account.getRoles().contains(ref.getLinkedRole());
        }
    }
    if (roles != null && roles.contains(role)) {
        return true;
    }
    return account.getRoles().contains(role);
}
 
Example #5
Source File: GetCookiesTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", ValidCookieEchoServlet.class)
            .addMapping("/aaa");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(GetCookiesTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlet(s);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #6
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final Class<? extends Servlet> servletClass){
    ensureNotProgramaticListener();
    ensureNotInitialized();
    ensureServletNameNotNull(servletName);
    if (deploymentInfo.getServlets().containsKey(servletName)) {
        return null;
    }
    try {
        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 (NoSuchMethodException e) {
        throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(servletClass.getName(),e);
    }
}
 
Example #7
Source File: TestHttpServer.java    From pnc with Apache License 2.0 6 votes vote down vote up
@Override
public void before() throws Exception {
    final ServletInfo si = Servlets.servlet("TEST", ExpectationServlet.class)
            .addMapping("*")
            .addMapping("/*")
            .setLoadOnStartup(1);

    si.setInstanceFactory(new ImmediateInstanceFactory<Servlet>(servlet));

    final DeploymentInfo di = new DeploymentInfo().addServlet(si)
            .setDeploymentName("TEST")
            .setContextPath("/")
            .setClassLoader(Thread.currentThread().getContextClassLoader());

    final DeploymentManager dm = Servlets.defaultContainer().addDeployment(di);
    dm.deploy();

    server = Undertow.builder().setHandler(dm.start()).addHttpListener(port, "127.0.0.1").build();

    server.start();
}
 
Example #8
Source File: ServletInputStreamEarlyCloseTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Test
public void testServletInputStreamEarlyClose() throws Exception {

    DeploymentUtils.setupServlet(
            new ServletInfo(SERVLET, EarlyCloseServlet.class)
                    .addMapping("/" + SERVLET));
    TestHttpClient client = new TestHttpClient();
    try {
        String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + SERVLET;
        HttpPost post = new HttpPost(uri);
        post.setEntity(new StringEntity("A non-empty request body"));
        HttpResponse result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);

        result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);

        result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);
    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
Example #9
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final Class<? extends Servlet> servletClass){
    ensureNotProgramaticListener();
    ensureNotInitialized();
    ensureServletNameNotNull(servletName);
    if (deploymentInfo.getServlets().containsKey(servletName)) {
        return null;
    }
    try {
        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 (NoSuchMethodException e) {
        throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(servletClass.getName(),e);
    }
}
 
Example #10
Source File: UndertowServletMapperTest.java    From hammock with Apache License 2.0 6 votes vote down vote up
@Test
public void testConversion() {
    Class<? extends HttpServlet> servletClass = DefaultServlet.class;
    String name = "name";
    String[] value = new String[]{"a"};
    String[] urlPatterns = new String[]{"/b"};
    int loadOnStartup = 2;
    WebInitParam[] initParams = new WebInitParam[]{new WebParam("name","value")};
    boolean asyncSupported = true;
    ServletDescriptor servletDescriptor = new ServletDescriptor(name, value, urlPatterns, loadOnStartup,
            initParams, asyncSupported, servletClass);
    ServletInfo servletInfo = mapper.apply(servletDescriptor);

    assertThat(servletInfo.getName()).isEqualTo(name);
    assertThat(servletInfo.getServletClass()).isEqualTo(servletClass);
    assertThat(servletInfo.getMappings()).isEqualTo(asList(urlPatterns));
    assertThat(servletInfo.getLoadOnStartup()).isEqualTo(loadOnStartup);
    assertThat(servletInfo.isAsyncSupported()).isEqualTo(asyncSupported);
    assertThat(servletInfo.getInitParams()).isEqualTo(singletonMap("name","value"));
}
 
Example #11
Source File: DefaultAuthorizationManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean isUserInRole(String role, Account account, ServletInfo servletInfo, HttpServletRequest request, Deployment deployment) {

    final Map<String, Set<String>> principalVersusRolesMap = deployment.getDeploymentInfo().getPrincipalVersusRolesMap();
    final Set<String> roles = principalVersusRolesMap.get(account.getPrincipal().getName());
    //TODO: a more efficient imple
    for (SecurityRoleRef ref : servletInfo.getSecurityRoleRefs()) {
        if (ref.getRole().equals(role)) {
            if (roles != null && roles.contains(ref.getLinkedRole())) {
                return true;
            }
            return account.getRoles().contains(ref.getLinkedRole());
        }
    }
    if (roles != null && roles.contains(role)) {
        return true;
    }
    return account.getRoles().contains(role);
}
 
Example #12
Source File: RealPathTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo realPathServlet = new ServletInfo("real path servlet", RealPathServlet.class)
            .addMapping("/path/*");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(RealPathTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(RealPathTestCase.class))
            .addServlets(realPathServlet);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);

}
 
Example #13
Source File: RewriteTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@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("/"));
}
 
Example #14
Source File: SessionIdHandlingTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {


    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlets(new ServletInfo("servlet", RequestedSessionIdServlet.class)
                    .addMapping("/session"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
}
 
Example #15
Source File: GetResourceTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    DeploymentInfo builder = new DeploymentInfo()
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(GetResourceTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(GetResourceTestCase.class));

    builder.addServlet(new ServletInfo("ReadFileServlet", ReadFileServlet.class)
            .addMapping("/file"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #16
Source File: ServletSessionTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {


    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addListener(new ListenerInfo(SessionCookieConfigListener.class))
            .addServlets(new ServletInfo("servlet", SessionServlet.class)
                    .addMapping("/aa/b"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
}
 
Example #17
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<ServletInfo> registerServlet(RuntimeValue<DeploymentInfo> deploymentInfo,
        String name,
        Class<?> servletClass,
        boolean asyncSupported,
        int loadOnStartup,
        BeanContainer beanContainer,
        InstanceFactory<? extends Servlet> instanceFactory) throws Exception {

    InstanceFactory<? extends Servlet> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(servletClass));
    ServletInfo servletInfo = new ServletInfo(name, (Class<? extends Servlet>) servletClass,
            factory);
    deploymentInfo.getValue().addServlet(servletInfo);
    servletInfo.setAsyncSupported(asyncSupported);
    if (loadOnStartup > 0) {
        servletInfo.setLoadOnStartup(loadOnStartup);
    }
    return new RuntimeValue<>(servletInfo);
}
 
Example #18
Source File: ChangeSessionIdTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", ChangeSessionIdServlet.class)
            .addMapping("/aa");
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addListener(new ListenerInfo(ChangeSessionIdListener.class))
            .addServlet(s);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(path);
}
 
Example #19
Source File: SimpleServletTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", MessageServlet.class)
            .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD)
            .addMapping("/aa");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlet(s);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #20
Source File: ServletSessionInvalidateWithListenerTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/listener")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("listener.war")
            .addListener(new ListenerInfo(SimpleSessionListener.class))
            .addServlet(new ServletInfo("servlet", SessionServlet.class)
                .addMapping("/test"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #21
Source File: DefaultServletCachingTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException, IOException {

    tmpDir = Files.createTempDirectory(DIR_NAME);

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    DeploymentInfo builder = new DeploymentInfo()
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(ServletPathMappingTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new CachingResourceManager(100, 10000, dataCache, new PathResourceManager(tmpDir, 10485760, false, false, false), METADATA_MAX_AGE));

    builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class)
            .addMapping("/path/default"))
            .addFilter(Servlets.filter("message", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "FILTER_TEXT "))
            .addFilterUrlMapping("message", "*.txt", DispatcherType.REQUEST);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #22
Source File: NestedListenerInvocationTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class)
            .setAsyncSupported(true)
            .addMapping("/async");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(NestedListenerInvocationTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlets(a)
            .addListener(new ListenerInfo(SimpleRequestListener.class));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #23
Source File: DeploymentUtils.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up a simple servlet deployment with the provided servlets.
 *
 * This is just a convenience method for simple deployments
 *
 * @param servlets The servlets to add
 */
public static Deployment setupServlet(final ServletExtension servletExtension, final ServletInfo... servlets) {

    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlets(servlets);
    if(servletExtension != null) {
        builder.addServletExtension(servletExtension);
    }
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);

    return manager.getDeployment();

}
 
Example #24
Source File: ServletPathMappingTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {
    DeploymentUtils.setupServlet(
            new ServletInfo("/a/*", PathMappingServlet.class)
                    .addMapping("/a/*"),
            new ServletInfo("/aa", PathMappingServlet.class)
                    .addMapping("/aa"),
            new ServletInfo("/aa/*", PathMappingServlet.class)
                    .addMapping("/aa/*"),
            new ServletInfo("/a/b/*", PathMappingServlet.class)
                    .addMapping("/a/b/*"),
            new ServletInfo("/", PathMappingServlet.class)
                    .addMapping("/"),
            new ServletInfo("*.jsp", PathMappingServlet.class)
                    .addMapping("*.jsp"),
            new ServletInfo("contextRoot", PathMappingServlet.class)
                    .addMapping(""),
            new ServletInfo("foo", PathMappingServlet.class)
                    .addMapping("foo.html"));

}
 
Example #25
Source File: DefaultServletTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    DeploymentInfo builder = new DeploymentInfo()
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(ServletPathMappingTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(DefaultServletTestCase.class));

    builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class)
            .addMapping("/path/default"));

    builder.addServlet(new ServletInfo("default", DefaultServlet.class)
            .addInitParam("directory-listing", "true")
            .addMapping("/*"));

    //see UNDERTOW-458
    builder.addFilter(new FilterInfo("date-header", GetDateFilter.class));
    builder.addFilterUrlMapping("date-header", "/*", DispatcherType.REQUEST);


    builder.addFilter(new FilterInfo("Filter", HelloFilter.class));
    builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #26
Source File: AbstractResponseWrapperTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    builder.setExceptionHandler(LoggingExceptionHandler.builder().add(IllegalArgumentException.class, "io.undertow", Logger.Level.DEBUG).build());

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    builder.addServlet(new ServletInfo("wrapperServlet", WrapperServlet.class)
            .addMapping("/*"));


    builder.addFilter(new FilterInfo("standard", StandardRequestWrappingFilter.class));
    builder.addFilterUrlMapping("standard", "/standard", DispatcherType.REQUEST);

    builder.addFilter(new FilterInfo("nonstandard", NonStandardRequestWrappingFilter.class));
    builder.addFilterUrlMapping("nonstandard", "/nonstandard", DispatcherType.REQUEST);

    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(AbstractResponseWrapperTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setAllowNonStandardWrappers(isNonStandardAllowed());

    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #27
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final Servlet servlet) {
    ensureNotProgramaticListener();
    ensureNotInitialized();
    ensureServletNameNotNull(servletName);
    if (deploymentInfo.getServlets().containsKey(servletName)) {
        return null;
    }
    ServletInfo s = new ServletInfo(servletName, servlet.getClass(), new ImmediateInstanceFactory<>(servlet));
    readServletAnnotations(s);
    deploymentInfo.addServlet(s);
    ServletHandler handler = deployment.getServlets().addServlet(s);
    return new ServletRegistrationImpl(s, handler.getManagedServlet(), deployment);
}
 
Example #28
Source File: LifecyleInterceptorInvocation.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, ServletInfo servletInfo, Servlet servlet) {
    this.list = list;
    this.servlet = servlet;
    this.servletInfo = servletInfo;
    this.filterInfo = null;
    this.servletConfig = null;
    this.filter = null;
    this.filterConfig = null;
    i = list.size();
}
 
Example #29
Source File: MetricsChainHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    ServletInfo servletInfo = context.getCurrentServlet().getManagedServlet().getServletInfo();
    MetricsHandler handler = servletHandlers.get(servletInfo.getName());
    if(handler != null) {
        handler.handleRequest(exchange);
    } else {
        next.handleRequest(exchange);
    }
}
 
Example #30
Source File: ManagedServlet.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ManagedServlet(final ServletInfo servletInfo, final ServletContextImpl servletContext) {
    this.servletInfo = servletInfo;
    this.servletContext = servletContext;
    if (SingleThreadModel.class.isAssignableFrom(servletInfo.getServletClass())) {
        instanceStrategy = new SingleThreadModelPoolStrategy(servletInfo.getInstanceFactory(), servletInfo, servletContext);
    } else {
        instanceStrategy = new DefaultInstanceStrategy(servletInfo.getInstanceFactory(), servletInfo, servletContext);
    }
    setupMultipart(servletContext);
}