Search in sources :

Example 1 with ShutdownContext

use of io.quarkus.runtime.ShutdownContext in project quarkus-github-app by quarkiverse.

the class GitHubAppRecorder method replayUiHandler.

public Handler<RoutingContext> replayUiHandler(String replayUiFinalDestination, String replayUiPath, List<FileSystemStaticHandler.StaticWebRootConfiguration> webRootConfigurations, ShutdownContext shutdownContext) {
    WebJarStaticHandler handler = new WebJarStaticHandler(replayUiFinalDestination, replayUiPath, webRootConfigurations);
    shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(handler));
    return handler;
}
Also used : WebJarStaticHandler(io.quarkus.vertx.http.runtime.webjar.WebJarStaticHandler) ShutdownContext(io.quarkus.runtime.ShutdownContext)

Example 2 with ShutdownContext

use of io.quarkus.runtime.ShutdownContext in project quarkus by quarkusio.

the class SmallRyeHealthRecorder method uiHandler.

public Handler<RoutingContext> uiHandler(String healthUiFinalDestination, String healthUiPath, List<FileSystemStaticHandler.StaticWebRootConfiguration> webRootConfigurations, SmallRyeHealthRuntimeConfig runtimeConfig, ShutdownContext shutdownContext) {
    if (runtimeConfig.enable) {
        WebJarStaticHandler handler = new WebJarStaticHandler(healthUiFinalDestination, healthUiPath, webRootConfigurations);
        shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(handler));
        return handler;
    } else {
        return new WebJarNotFoundHandler();
    }
}
Also used : WebJarStaticHandler(io.quarkus.vertx.http.runtime.webjar.WebJarStaticHandler) ShutdownContext(io.quarkus.runtime.ShutdownContext) WebJarNotFoundHandler(io.quarkus.vertx.http.runtime.webjar.WebJarNotFoundHandler)

Example 3 with ShutdownContext

use of io.quarkus.runtime.ShutdownContext in project quarkus by quarkusio.

the class SwaggerUiRecorder method handler.

public Handler<RoutingContext> handler(String swaggerUiFinalDestination, String swaggerUiPath, List<FileSystemStaticHandler.StaticWebRootConfiguration> webRootConfigurations, SwaggerUiRuntimeConfig runtimeConfig, ShutdownContext shutdownContext) {
    if (runtimeConfig.enable) {
        WebJarStaticHandler handler = new WebJarStaticHandler(swaggerUiFinalDestination, swaggerUiPath, webRootConfigurations);
        shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(handler));
        return handler;
    } else {
        return new WebJarNotFoundHandler();
    }
}
Also used : WebJarStaticHandler(io.quarkus.vertx.http.runtime.webjar.WebJarStaticHandler) ShutdownContext(io.quarkus.runtime.ShutdownContext) WebJarNotFoundHandler(io.quarkus.vertx.http.runtime.webjar.WebJarNotFoundHandler)

Example 4 with ShutdownContext

use of io.quarkus.runtime.ShutdownContext in project quarkus by quarkusio.

the class ResteasyReactiveRecorder method createDeployment.

public RuntimeValue<Deployment> createDeployment(DeploymentInfo info, BeanContainer beanContainer, ShutdownContext shutdownContext, HttpBuildTimeConfig vertxConfig, RequestContextFactory contextFactory, BeanFactory<ResteasyReactiveInitialiser> initClassFactory, LaunchMode launchMode, boolean resumeOn404) {
    if (resumeOn404) {
        info.setResumeOn404(true);
    }
    CurrentRequestManager.setCurrentRequestInstance(new QuarkusCurrentRequest(beanContainer.instance(CurrentVertxRequest.class)));
    BlockingOperationSupport.setIoThreadDetector(new BlockingOperationSupport.IOThreadDetector() {

        @Override
        public boolean isBlockingAllowed() {
            return BlockingOperationControl.isBlockingAllowed();
        }
    });
    Consumer<Closeable> closeTaskHandler = new Consumer<Closeable>() {

        @Override
        public void accept(Closeable closeable) {
            shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(closeable));
        }
    };
    CurrentIdentityAssociation currentIdentityAssociation = Arc.container().instance(CurrentIdentityAssociation.class).get();
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    if (contextFactory == null) {
        contextFactory = new RequestContextFactory() {

            @Override
            public ResteasyReactiveRequestContext createContext(Deployment deployment, ProvidersImpl providers, Object context, ThreadSetupAction requestContext, ServerRestHandler[] handlerChain, ServerRestHandler[] abortHandlerChain) {
                return new QuarkusResteasyReactiveRequestContext(deployment, providers, (RoutingContext) context, requestContext, handlerChain, abortHandlerChain, launchMode == LaunchMode.DEVELOPMENT ? tccl : null, currentIdentityAssociation);
            }
        };
    }
    RuntimeDeploymentManager runtimeDeploymentManager = new RuntimeDeploymentManager(info, EXECUTOR_SUPPLIER, closeTaskHandler, contextFactory, new ArcThreadSetupAction(beanContainer.requestContext()), vertxConfig.rootPath);
    Deployment deployment = runtimeDeploymentManager.deploy();
    initClassFactory.createInstance().getInstance().init(deployment);
    currentDeployment = deployment;
    if (LaunchMode.current() == LaunchMode.DEVELOPMENT) {
        classMappers = deployment.getClassMappers();
        RuntimeResourceVisitor.visitRuntimeResources(classMappers, ScoreSystem.ScoreVisitor);
    }
    return new RuntimeValue<>(deployment);
}
Also used : Closeable(java.io.Closeable) RuntimeDeploymentManager(org.jboss.resteasy.reactive.server.core.startup.RuntimeDeploymentManager) Deployment(org.jboss.resteasy.reactive.server.core.Deployment) ArcThreadSetupAction(io.quarkus.resteasy.reactive.common.runtime.ArcThreadSetupAction) ProvidersImpl(org.jboss.resteasy.reactive.server.jaxrs.ProvidersImpl) ArcThreadSetupAction(io.quarkus.resteasy.reactive.common.runtime.ArcThreadSetupAction) ThreadSetupAction(org.jboss.resteasy.reactive.spi.ThreadSetupAction) ServerRestHandler(org.jboss.resteasy.reactive.server.spi.ServerRestHandler) RoutingContext(io.vertx.ext.web.RoutingContext) Consumer(java.util.function.Consumer) BlockingOperationSupport(org.jboss.resteasy.reactive.server.core.BlockingOperationSupport) ShutdownContext(io.quarkus.runtime.ShutdownContext) RequestContextFactory(org.jboss.resteasy.reactive.server.core.RequestContextFactory) ResteasyReactiveRequestContext(org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext) CurrentIdentityAssociation(io.quarkus.security.identity.CurrentIdentityAssociation) RuntimeValue(io.quarkus.runtime.RuntimeValue)

Example 5 with ShutdownContext

use of io.quarkus.runtime.ShutdownContext in project quarkus by quarkusio.

the class UndertowDeploymentRecorder method createDeployment.

public RuntimeValue<DeploymentInfo> createDeployment(String name, Set<String> knownFile, Set<String> knownDirectories, LaunchMode launchMode, ShutdownContext context, String mountPoint, String defaultCharset, String requestCharacterEncoding, String responseCharacterEncoding, boolean proactiveAuth, List<String> welcomeFiles) {
    DeploymentInfo d = new DeploymentInfo();
    d.setDefaultRequestEncoding(requestCharacterEncoding);
    d.setDefaultResponseEncoding(responseCharacterEncoding);
    d.setDefaultEncoding(defaultCharset);
    d.setSessionIdGenerator(new QuarkusSessionIdGenerator());
    d.setClassLoader(getClass().getClassLoader());
    d.setDeploymentName(name);
    d.setContextPath(mountPoint);
    d.setEagerFilterInit(true);
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (cl == null) {
        cl = new ClassLoader() {
        };
    }
    d.setClassLoader(cl);
    // TODO: we need better handling of static resources
    ResourceManager resourceManager;
    if (hotDeploymentResourcePaths == null) {
        resourceManager = new KnownPathResourceManager(knownFile, knownDirectories, new ClassPathResourceManager(d.getClassLoader(), "META-INF/resources"));
    } else {
        List<ResourceManager> managers = new ArrayList<>();
        for (Path i : hotDeploymentResourcePaths) {
            managers.add(new PathResourceManager(i));
        }
        managers.add(new ClassPathResourceManager(d.getClassLoader(), "META-INF/resources"));
        resourceManager = new DelegatingResourceManager(managers.toArray(new ResourceManager[0]));
    }
    if (launchMode == LaunchMode.NORMAL) {
        // todo: cache configuration
        resourceManager = new CachingResourceManager(1000, 0, null, resourceManager, 2000);
    }
    d.setResourceManager(resourceManager);
    if (welcomeFiles != null) {
        // if available, use welcome-files from web.xml
        d.addWelcomePages(welcomeFiles);
    } else {
        d.addWelcomePages("index.html", "index.htm");
    }
    d.addServlet(new ServletInfo(ServletPathMatches.DEFAULT_SERVLET_NAME, DefaultServlet.class).setAsyncSupported(true));
    for (HandlerWrapper i : hotDeploymentWrappers) {
        d.addOuterHandlerChainWrapper(i);
    }
    d.addAuthenticationMechanism("QUARKUS", new ImmediateAuthenticationMechanismFactory(QuarkusAuthMechanism.INSTANCE));
    d.setLoginConfig(new LoginConfig("QUARKUS", "QUARKUS"));
    context.addShutdownTask(new ShutdownContext.CloseRunnable(d.getResourceManager()));
    d.addNotificationReceiver(new NotificationReceiver() {

        @Override
        public void handleNotification(SecurityNotification notification) {
            if (notification.getEventType() == SecurityNotification.EventType.AUTHENTICATED) {
                QuarkusUndertowAccount account = (QuarkusUndertowAccount) notification.getAccount();
                Instance<CurrentIdentityAssociation> instance = CDI.current().select(CurrentIdentityAssociation.class);
                if (instance.isResolvable())
                    instance.get().setIdentity(account.getSecurityIdentity());
            }
        }
    });
    if (proactiveAuth) {
        d.setAuthenticationMode(AuthenticationMode.PRO_ACTIVE);
    } else {
        d.setAuthenticationMode(AuthenticationMode.CONSTRAINT_DRIVEN);
    }
    return new RuntimeValue<>(d);
}
Also used : Instance(javax.enterprise.inject.Instance) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HandlerWrapper(io.undertow.server.HandlerWrapper) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager) SecurityNotification(io.undertow.security.api.SecurityNotification) ServletInfo(io.undertow.servlet.api.ServletInfo) ShutdownContext(io.quarkus.runtime.ShutdownContext) LoginConfig(io.undertow.servlet.api.LoginConfig) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Path(java.nio.file.Path) ImmediateAuthenticationMechanismFactory(io.undertow.util.ImmediateAuthenticationMechanismFactory) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager) ResourceManager(io.undertow.server.handlers.resource.ResourceManager) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) NotificationReceiver(io.undertow.security.api.NotificationReceiver) CurrentIdentityAssociation(io.quarkus.security.identity.CurrentIdentityAssociation) RuntimeValue(io.quarkus.runtime.RuntimeValue) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager)

Aggregations

ShutdownContext (io.quarkus.runtime.ShutdownContext)6 WebJarStaticHandler (io.quarkus.vertx.http.runtime.webjar.WebJarStaticHandler)4 WebJarNotFoundHandler (io.quarkus.vertx.http.runtime.webjar.WebJarNotFoundHandler)3 RuntimeValue (io.quarkus.runtime.RuntimeValue)2 CurrentIdentityAssociation (io.quarkus.security.identity.CurrentIdentityAssociation)2 ArcThreadSetupAction (io.quarkus.resteasy.reactive.common.runtime.ArcThreadSetupAction)1 NotificationReceiver (io.undertow.security.api.NotificationReceiver)1 SecurityNotification (io.undertow.security.api.SecurityNotification)1 HandlerWrapper (io.undertow.server.HandlerWrapper)1 CachingResourceManager (io.undertow.server.handlers.resource.CachingResourceManager)1 ClassPathResourceManager (io.undertow.server.handlers.resource.ClassPathResourceManager)1 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)1 ResourceManager (io.undertow.server.handlers.resource.ResourceManager)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 LoginConfig (io.undertow.servlet.api.LoginConfig)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1 ImmediateAuthenticationMechanismFactory (io.undertow.util.ImmediateAuthenticationMechanismFactory)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 Closeable (java.io.Closeable)1 Path (java.nio.file.Path)1