io.undertow.servlet.api.DeploymentManager Java Examples

The following examples show how to use io.undertow.servlet.api.DeploymentManager. 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: 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 #2
Source File: EagerServletLifecycleTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Test
public void testServletLifecycle() throws Exception {


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

    FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(EagerServletLifecycleTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setEagerFilterInit(true)
            .addFilter(f)
            .addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST);

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

    DefaultServer.setRootHandler(root);

    Assert.assertTrue(LifecycleFilter.initCalled);
}
 
Example #3
Source File: JsrWebSocketServerTest.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
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();
    }
 
Example #4
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 #5
Source File: UndertowWebServer.java    From oxygen with Apache License 2.0 6 votes vote down vote up
@Override
public void listen(int port) {
  this.port = port;
  this.contextPath = WebConfigKeys.SERVER_CONTEXT_PATH.getValue();
  undertowConf = ConfigFactory.load(UndertowConf.class);
  DeploymentManager manager = deployment();
  manager.deploy();
  Undertow.Builder builder = Undertow.builder();
  configServer(builder);
  try {
    undertow = builder.setHandler(configHttp(manager.start())).build();
  } catch (ServletException e) {
    throw Exceptions.wrap(e);
  }
  undertow.start();
}
 
Example #6
Source File: UndertowLauncher.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
private void undeploy() throws Exception {
    if (deploymentManager != null) {
        try {
            if (deploymentManager.getState() == DeploymentManager.State.STARTED) {
                deploymentManager.stop();
            }
            if (deploymentManager.getState() == DeploymentManager.State.DEPLOYED) {
                deploymentManager.undeploy();
            }
        } catch (ServletException | RuntimeException e) {
            throw unwrapUndertowException(e);
        } finally {
            httpHandler = null;
            deploymentManager = null;
        }
    }
}
 
Example #7
Source File: ServletContainerImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public DeploymentManager getDeploymentByPath(final String path) {

    DeploymentManager exact = deploymentsByPath.get(path.isEmpty() ? "/" : path);
    if (exact != null) {
        return exact;
    }
    int length = path.length();
    int pos = length;

    while (pos > 1) {
        --pos;
        if (path.charAt(pos) == '/') {
            String part = path.substring(0, pos);
            DeploymentManager deployment = deploymentsByPath.get(part);
            if (deployment != null) {
                return deployment;
            }
        }
    }
    return deploymentsByPath.get("/");
}
 
Example #8
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 #9
Source File: HttpServerBenchmarks.java    From brave with Apache License 2.0 6 votes vote down vote up
protected int initServer() throws Exception {
  DeploymentInfo servletBuilder = Servlets.deployment()
    .setClassLoader(getClass().getClassLoader())
    .setContextPath("/")
    .setDeploymentName("test.war");

  init(servletBuilder);

  DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
  manager.deploy();
  server = Undertow.builder()
    .addHttpListener(0, "127.0.0.1")
    .setHandler(manager.start()).build();
  server.start();
  return ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort();
}
 
Example #10
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 #11
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 #12
Source File: ManagedServlet.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void forceInit() throws ServletException {
    if (!started) {
        if(servletContext.getDeployment().getDeploymentState() != DeploymentManager.State.STARTED) {
            throw UndertowServletMessages.MESSAGES.deploymentStopped(servletContext.getDeployment().getDeploymentInfo().getDeploymentName());
        }
        synchronized (this) {
            if (!started) {
                try {
                    instanceStrategy.start();
                } catch (UnavailableException e) {
                    handleUnavailableException(e);
                }
                started = true;
            }
        }
    }
}
 
Example #13
Source File: ContentTypeFilesTestCase.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(ContentTypeFilesTestCase.class.getClassLoader())
            .setContextPath("/app")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(ContentTypeServlet.class))
            .setDefaultServletConfig(new DefaultServletConfig(true))
            .addMimeMapping(new MimeMapping("jnlp", "application/x-java-jnlp-file"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
 
Example #14
Source File: CamelEndpointDeployerService.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private void undeploy(DeploymentManager deploymentManager) {
    final Deployment deployment = deploymentManager.getDeployment();
    CamelLogger.LOGGER.debug("Undeploying endpoint {}", deployment.getDeploymentInfo().getDeploymentName());

    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(deployment.getDeploymentInfo().getClassLoader());
    try {
        try {
            hostSupplier.getValue().unregisterDeployment(deployment);
            deploymentManager.stop();
        } catch (ServletException e) {
            throw new RuntimeException(e);
        }
        deploymentManager.undeploy();
        servletContainerServiceSupplier.getValue().getServletContainer().removeDeployment(deployment.getDeploymentInfo());
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }

}
 
Example #15
Source File: CamelWebSocketJSR356Recorder.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
public void registerServerContainer(DeploymentManager deploymentManager) {
    ServletContextImpl servletContext = deploymentManager.getDeployment().getServletContext();
    ServerContainer container = (ServerContainer) servletContext.getAttribute(ServerContainer.class.getName());

    JSR356WebSocketComponent.registerServer(servletContext.getContextPath(), container);

    WebSocketDeploymentInfo deploymentInfo = (WebSocketDeploymentInfo) servletContext
            .getAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME);
    for (ServerEndpointConfig config : deploymentInfo.getProgramaticEndpoints()) {
        try {
            CamelServerEndpoint endpoint = config.getConfigurator().getEndpointInstance(CamelServerEndpoint.class);
            JSR356WebSocketComponent.ContextBag context = JSR356WebSocketComponent
                    .getContext(servletContext.getContextPath());
            context.getEndpoints().put(config.getPath(), endpoint);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example #16
Source File: ServletSessionListenerOrderingTestCase.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(FirstListener.class))
            .addListener(new ListenerInfo(SecondListener.class))
            .addServlet(new ServletInfo("message", EmptyServlet.class)
                    .addMapping("/*"));

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

    DefaultServer.setRootHandler(path);
}
 
Example #17
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 #18
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 #19
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 #20
Source File: TransferTestCase.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")
            .addServlet(
                    new ServletInfo("servlet", TXServlet.class)
                            .addMapping("/")
            );

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

    DefaultServer.setRootHandler(root);
}
 
Example #21
Source File: ResponseWriterTestCase.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(ResponseWriterTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .addServlet(Servlets.servlet("resp", ResponseWriterServlet.class)
                    .addMapping("/resp"))
            .addServlet(Servlets.servlet("respLArget", LargeResponseWriterServlet.class)
                    .addMapping("/large"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
 
Example #22
Source File: RedirectTestCase.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(
                    servlet("request", RequestPathServlet.class)
                            .addMapping("/"),
                    servlet("redirect", RedirectServlet.class)
                            .addMapping("/redirect/*"));
    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 #23
Source File: MockRequestTestCase.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", 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);
}
 
Example #24
Source File: AnnotatedAutobahnServer.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public void run() {


        try {
            final ServletContainer container = ServletContainer.Factory.newInstance();

            DeploymentInfo builder = new DeploymentInfo()
                    .setClassLoader(AnnotatedAutobahnServer.class.getClassLoader())
                    .setContextPath("/")
                    .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                    .setDeploymentName("servletContext.war")
                    .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME,
                            new WebSocketDeploymentInfo()
                                    .addEndpoint(AutobahnAnnotatedEndpoint.class)
                                    .setDispatchToWorkerThread(true)
                    )
                    .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class))
                    .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST);

            DeploymentManager manager = container.addDeployment(builder);
            manager.deploy();

            Undertow.builder().addHttpListener(port, "localhost")
                    .setHandler(manager.start())
                    .build();

        } catch (Exception e) {
            log.error("failed to start server", e);
        }
    }
 
Example #25
Source File: SuspendResumeTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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()
                            .addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {
                                @Override
                                public void ready(ServerWebSocketContainer c) {
                                    serverContainer = c;
                                }
                            })
                            .addEndpoint(SuspendResumeEndpoint.class)
            )
            .setDeploymentName("servletContext.war");


    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();


    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", manager.start()));
}
 
Example #26
Source File: ManagedFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if(servletContext.getDeployment().getDeploymentState() != DeploymentManager.State.STARTED) {
        throw UndertowServletMessages.MESSAGES.deploymentStopped(servletContext.getDeployment().getDeploymentInfo().getDeploymentName());
    }
    if (!started) {
        start();
    }
    getFilter().doFilter(request, response, chain);
}
 
Example #27
Source File: UndertowStartFilter.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(ApplicationExchange application, LauncherFilterChain filterChain) {

    int port = application.getServerPort();

    ClassLoader classLoader = new LaunchedURLClassLoader(application.getClassPathUrls(), deduceParentClassLoader());

    DeploymentInfo servletBuilder = Servlets.deployment()
                   .setClassLoader(classLoader)
                   .setContextPath(application.getContextPath())
                   .setDeploymentName(application.getApplication().getPath());

    DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
 
    manager.deploy();

    Undertow server = null;
    try {
        server = Undertow.builder()
                .addHttpListener(port, "localhost")
                .setHandler(manager.start()).build();
        server.start();
    } catch (ServletException e) {
        e.printStackTrace();
    }

    return false;
}
 
Example #28
Source File: AsyncListenerExceptionTest.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();

    ServletInfo runtime = new ServletInfo("runtime", RuntimeExceptionServlet.class)
            .addMapping("/runtime")
            .setAsyncSupported(true);
    ServletInfo io = new ServletInfo("io", IOExceptionServlet.class)
            .addMapping("/io")
            .setAsyncSupported(true);
    ServletInfo error = new ServletInfo("error", ErrorServlet.class)
            .addMapping("/error")
            .setAsyncSupported(true);

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(AsyncListenerExceptionTest.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlets(runtime, io, error);

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

    DefaultServer.setRootHandler(root);
}
 
Example #29
Source File: UndertowWebServer.java    From oxygen with Apache License 2.0 5 votes vote down vote up
private DeploymentManager deployment() {
  Set<Class<?>> handlesTypes = new HashSet<>(2);
  return Servlets.defaultContainer().addDeployment(
      Servlets.deployment().setClassLoader(ClassUtils.getDefaultClassLoader())
          .setContextPath(contextPath).setDeploymentName("oxygen")
          .addServletContainerInitializer(
              new ServletContainerInitializerInfo(ServletWebInitializer.class, handlesTypes)));
}
 
Example #30
Source File: CrossContextServletSessionTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static void createDeployment(final String name, final ServletContainer container,  final PathHandler path) throws ServletException {

        ServletInfo s = new ServletInfo("servlet", SessionServlet.class)
                .addMapping("/servlet");
        ServletInfo forward = new ServletInfo("forward", ForwardServlet.class)
                .addMapping("/forward");
        ServletInfo include = new ServletInfo("include", IncludeServlet.class)
                .addMapping("/include");

        ServletInfo includeAdd = new ServletInfo("includeadd", IncludeAddServlet.class)
                .addMapping("/includeadd");
        ServletInfo forwardAdd = new ServletInfo("forwardadd", ForwardAddServlet.class)
                .addMapping("/forwardadd");

        ServletInfo accessTimeServlet = new ServletInfo("accesstimeservlet", LastAccessTimeSessionServlet.class)
                .addMapping("/accesstimeservlet");

        DeploymentInfo builder = new DeploymentInfo()
                .setClassLoader(SimpleServletTestCase.class.getClassLoader())
                .setContextPath("/" + name)
                .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                .setDeploymentName( name + ".war")
                .setServletSessionConfig(new ServletSessionConfig().setPath("/"))
                .addServlets(s, forward, include, forwardAdd, includeAdd, accessTimeServlet);

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