Search in sources :

Example 51 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project cxf by apache.

the class UndertowHTTPServerEngine method buildServletContext.

private ServletContext buildServletContext(String contextName) throws ServletException {
    ServletContainer servletContainer = new ServletContainerImpl();
    DeploymentInfo deploymentInfo = new DeploymentInfo();
    deploymentInfo.setClassLoader(Thread.currentThread().getContextClassLoader());
    deploymentInfo.setDeploymentName("cxf-undertow");
    deploymentInfo.setContextPath(contextName);
    ServletInfo asyncServlet = new ServletInfo(ServletPathMatches.DEFAULT_SERVLET_NAME, CxfUndertowServlet.class);
    deploymentInfo.addServlet(asyncServlet);
    servletContainer.addDeployment(deploymentInfo);
    DeploymentManager deploymentManager = servletContainer.getDeployment(deploymentInfo.getDeploymentName());
    deploymentManager.deploy();
    deploymentManager.start();
    return deploymentManager.getDeployment().getServletContext();
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) ServletContainerImpl(io.undertow.servlet.core.ServletContainerImpl) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 52 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project openremote by openremote.

the class AbstractHttpServerProtocol method undeploy.

protected void undeploy(AssetAttribute protocolConfiguration) {
    Pair<DeploymentInfo, HttpHandler> deploymentInfoHttpHandlerPair = deployments.get(protocolConfiguration.getReferenceOrThrow());
    if (deploymentInfoHttpHandlerPair == null) {
        LOG.info("Deployment doesn't exist for protocol configuration: " + protocolConfiguration);
        return;
    }
    DeploymentInfo deploymentInfo = deploymentInfoHttpHandlerPair.key;
    try {
        LOG.info("Un-registering HTTP Server Protocol request handler '" + this.getClass().getSimpleName() + "' for request path: " + deploymentInfo.getContextPath());
        webService.getRequestPathHandler().removePrefixPath(deploymentInfo.getContextPath());
        DeploymentManager manager = Servlets.defaultContainer().getDeployment(deploymentInfo.getDeploymentName());
        manager.stop();
        manager.undeploy();
        Servlets.defaultContainer().removeDeployment(deploymentInfo);
        deployments.remove(protocolConfiguration.getReferenceOrThrow());
    } catch (Exception ex) {
        LOG.log(Level.WARNING, "An exception occurred whilst un-deploying protocolConfiguration: " + protocolConfiguration.getReferenceOrThrow(), ex);
        throw new RuntimeException(ex);
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) DeploymentManager(io.undertow.servlet.api.DeploymentManager) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletException(javax.servlet.ServletException)

Example 53 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project openremote by openremote.

the class WebService method removeServletDeployment.

public void removeServletDeployment(DeploymentInfo deploymentInfo) {
    try {
        DeploymentManager manager = Servlets.defaultContainer().getDeployment(deploymentInfo.getDeploymentName());
        manager.stop();
        manager.undeploy();
        Servlets.defaultContainer().removeDeployment(deploymentInfo);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 54 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project undertow by undertow-io.

the class DeploymentUtils method setupServlet.

/**
     * 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();
}
Also used : ServletException(javax.servlet.ServletException) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase)

Example 55 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project undertow by undertow-io.

the class AbstractResponseWrapperTestCase method setup.

@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);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) Before(org.junit.Before)

Aggregations

DeploymentManager (io.undertow.servlet.api.DeploymentManager)84 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)75 ServletContainer (io.undertow.servlet.api.ServletContainer)69 PathHandler (io.undertow.server.handlers.PathHandler)58 BeforeClass (org.junit.BeforeClass)53 ServletInfo (io.undertow.servlet.api.ServletInfo)51 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 FilterInfo (io.undertow.servlet.api.FilterInfo)16 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)16 ServletException (javax.servlet.ServletException)14 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)13 LoginConfig (io.undertow.servlet.api.LoginConfig)12 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)10 ListenerInfo (io.undertow.servlet.api.ListenerInfo)8 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)8 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)8 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)8 Test (org.junit.Test)8 TestHttpClient (io.undertow.testutils.TestHttpClient)7 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)5