Search in sources :

Example 81 with DeploymentManager

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

the class ServletContainerImpl method removeDeployment.

@Override
public void removeDeployment(final DeploymentInfo deploymentInfo) {
    final DeploymentManager deploymentManager = deployments.get(deploymentInfo.getDeploymentName());
    if (deploymentManager.getState() != DeploymentManager.State.UNDEPLOYED) {
        throw UndertowServletMessages.MESSAGES.canOnlyRemoveDeploymentsWhenUndeployed(deploymentManager.getState());
    }
    deployments.remove(deploymentInfo.getDeploymentName());
    deploymentsByPath.remove(deploymentInfo.getContextPath());
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager)

Example 82 with DeploymentManager

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

the class WebService method addServletDeployment.

/**
 * Adds a deployment to the default servlet container and returns the started handler.
 *
 * @param identityService Must not be null if secure deployment is used
 * @param deploymentInfo  The deployment to add to the default container
 * @param secure          If authentication/authorization should be enabled for this deployment
 */
public HttpHandler addServletDeployment(IdentityService identityService, DeploymentInfo deploymentInfo, boolean secure) {
    try {
        if (secure) {
            if (identityService == null)
                throw new IllegalStateException("No identity service found, make sure " + IdentityService.class.getName() + " is added before this service");
            identityService.secureDeployment(deploymentInfo);
        } else {
            LOG.info("Deploying insecure web context: " + deploymentInfo.getContextPath());
        }
        // This will catch anything not handled by Resteasy/Servlets, such as IOExceptions "at the wrong time"
        deploymentInfo.setExceptionHandler(new WebServiceExceptions.ServletUndertowExceptionHandler(devMode));
        DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo);
        manager.deploy();
        return manager.start();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 83 with DeploymentManager

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

the class AbstractHttpServerProtocol method deploy.

protected void deploy(DeploymentInfo deploymentInfo, AssetAttribute protocolConfiguration) {
    LOG.info("Deploying JAX-RS deployment for: " + protocolConfiguration.getReferenceOrThrow());
    DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo);
    manager.deploy();
    HttpHandler httpHandler;
    try {
        httpHandler = manager.start();
        deployments.put(protocolConfiguration.getReferenceOrThrow(), new Pair<>(deploymentInfo, httpHandler));
        LOG.info("Registering HTTP Server Protocol request handler '" + this.getClass().getSimpleName() + "' for request path: " + deploymentInfo.getContextPath());
        webService.getRequestPathHandler().addPrefixPath(deploymentInfo.getContextPath(), httpHandler);
    } catch (ServletException e) {
        LOG.severe("Failed to deploy deployment: " + deploymentInfo.getDeploymentName());
    }
}
Also used : ServletException(javax.servlet.ServletException) HttpHandler(io.undertow.server.HttpHandler) DeploymentManager(io.undertow.servlet.api.DeploymentManager)

Example 84 with DeploymentManager

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

the class AbstractUndertowServer method run.

protected void run() {
    try {
        final DeploymentInfo servletBuilder = deployment().setClassLoader(AbstractUndertowServer.class.getClassLoader()).setContextPath(contextPath).setDeploymentName("sse-test").addServlets(servlet("MessageServlet", CXFNonSpringJaxrsServlet.class).addInitParam(CXFNonSpringJaxrsServlet.TRANSPORT_ID, SseHttpTransportFactory.TRANSPORT_ID).addInitParam("jaxrs.providers", JacksonJsonProvider.class.getName()).addInitParam("jaxrs.serviceClasses", BookStore.class.getName()).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/rest/*"));
        final DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
        manager.deploy();
        PathHandler path = Handlers.path(Handlers.redirect("/")).addPrefixPath("/", manager.start());
        server = Undertow.builder().addHttpListener(port, "localhost").setHandler(path).build();
        server.start();
    } catch (final Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.sse.BookStore) DeploymentManager(io.undertow.servlet.api.DeploymentManager) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) CXFNonSpringJaxrsServlet(org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet)

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