io.undertow.servlet.api.ThreadSetupHandler Java Examples

The following examples show how to use io.undertow.servlet.api.ThreadSetupHandler. 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: DeploymentManagerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void undeploy() {
    try {
        deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, Object>() {
            @Override
            public Void call(HttpServerExchange exchange, Object ignore) throws ServletException {
                for(ServletContextListener listener : deployment.getDeploymentInfo().getDeploymentCompleteListeners()) {
                    try {
                        listener.contextDestroyed(new ServletContextEvent(deployment.getServletContext()));
                    } catch (Throwable t) {
                        UndertowServletLogger.REQUEST_LOGGER.failedToDestroy(listener, t);
                    }
                }
                deployment.destroy();
                deployment = null;
                state = State.UNDEPLOYED;
                return null;
            }
        }).call(null, null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
Example #2
Source File: ServletInitialHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
public ServletInitialHandler(final ServletPathMatches paths, final HttpHandler next, final Deployment deployment, final ServletContextImpl servletContext) {
    this.next = next;
    this.servletContext = servletContext;
    this.paths = paths;
    this.listeners = servletContext.getDeployment().getApplicationListeners();
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        //handle request can use doPrivilidged
        //we need to make sure this is not abused
        sm.checkPermission(PERMISSION);
    }
    ExceptionHandler handler = servletContext.getDeployment().getDeploymentInfo().getExceptionHandler();
    if (handler != null) {
        this.exceptionHandler = handler;
    } else {
        this.exceptionHandler = LoggingExceptionHandler.DEFAULT;
    }
    this.firstRequestHandler = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Object, ServletRequestContext>() {
        @Override
        public Object call(HttpServerExchange exchange, ServletRequestContext context) throws Exception {
            handleFirstRequest(exchange, context);
            return null;
        }
    });
}
 
Example #3
Source File: ServletInitialHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public ServletInitialHandler(final ServletPathMatches paths, final HttpHandler next, final Deployment deployment, final ServletContextImpl servletContext) {
    this.next = next;
    this.servletContext = servletContext;
    this.paths = paths;
    this.listeners = servletContext.getDeployment().getApplicationListeners();
    SecurityManager sm = System.getSecurityManager();
    if(sm != null) {
        //handle request can use doPrivilidged
        //we need to make sure this is not abused
        sm.checkPermission(PERMISSION);
    }
    ExceptionHandler handler = servletContext.getDeployment().getDeploymentInfo().getExceptionHandler();
    if(handler != null) {
         this.exceptionHandler = handler;
    } else {
        this.exceptionHandler = LoggingExceptionHandler.DEFAULT;
    }
    this.firstRequestHandler = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Object, ServletRequestContext>() {
        @Override
        public Object call(HttpServerExchange exchange, ServletRequestContext context) throws Exception {
            handleFirstRequest(exchange, context);
            return null;
        }
    });
}
 
Example #4
Source File: DeploymentManagerImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void undeploy() {
    try {
        deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, Object>() {
            @Override
            public Void call(HttpServerExchange exchange, Object ignore) throws ServletException {
                for(ServletContextListener listener : deployment.getDeploymentInfo().getDeploymentCompleteListeners()) {
                    try {
                        listener.contextDestroyed(new ServletContextEvent(deployment.getServletContext()));
                    } catch (Throwable t) {
                        UndertowServletLogger.REQUEST_LOGGER.failedToDestroy(listener, t);
                    }
                }
                deployment.destroy();
                deployment = null;
                state = State.UNDEPLOYED;
                return null;
            }
        }).call(null, null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
Example #5
Source File: RequestDispatcherImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private void forwardImplSetup(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }

    ThreadSetupAction.Handle handle = null;
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {

        try {
            //cross context request, we need to run the thread setup actions
            oldServletContext = servletRequestContext.getCurrentServletContext();
            oldSession = servletRequestContext.getSession();
            servletRequestContext.setSession(null);
            servletRequestContext.setCurrentServletContext(this.servletContext);
            this.servletContext.invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    forwardImpl(request, response, servletRequestContext);
                    return null;
                }
            });

        } finally {
            servletRequestContext.setSession(oldSession);
            servletRequestContext.setCurrentServletContext(oldServletContext);
            // update time in old context and run the requestDone for the session
            servletRequestContext.getCurrentServletContext().updateSessionAccessTime(servletRequestContext.getExchange());
        }
    } else {
        forwardImpl(request, response, servletRequestContext);
    }

}
 
Example #6
Source File: SessionListenerBridge.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SessionListenerBridge(final Deployment deployment, final ApplicationListeners applicationListeners, final ServletContext servletContext) {
    this.applicationListeners = applicationListeners;
    this.servletContext = servletContext;
    this.destroyedAction = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, Session>() {
        @Override
        public Void call(HttpServerExchange exchange, Session session) throws ServletException {
            doDestroy(session);
            return null;
        }
    });
}
 
Example #7
Source File: DeploymentImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public <C, T> ThreadSetupHandler.Action<C, T> createThreadSetupAction(ThreadSetupHandler.Action<C, T> target) {
    ThreadSetupHandler.Action<C, T> ret = target;
    for(ThreadSetupHandler wrapper : threadSetupActions) {
        ret = wrapper.create(ret);
    }
    return ret;
}
 
Example #8
Source File: RequestDispatcherImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void setupIncludeImpl(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }
    final HttpServletRequestImpl requestImpl = servletRequestContext.getOriginalRequest();
    final HttpServletResponseImpl responseImpl = servletRequestContext.getOriginalResponse();
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {
        //cross context request, we need to run the thread setup actions
        oldServletContext = servletRequestContext.getCurrentServletContext();
        oldSession = servletRequestContext.getSession();
        servletRequestContext.setSession(null);
        servletRequestContext.setCurrentServletContext(this.servletContext);
        try {
            servletRequestContext.getCurrentServletContext().invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
                    return null;
                }
            });
        } finally {
            servletRequestContext.setSession(oldSession);
            servletRequestContext.setCurrentServletContext(oldServletContext);
        }
    } else {
        includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
    }
}
 
Example #9
Source File: RequestDispatcherImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void forwardImplSetup(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }

    ThreadSetupAction.Handle handle = null;
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {

        try {
            //cross context request, we need to run the thread setup actions
            oldServletContext = servletRequestContext.getCurrentServletContext();
            oldSession = servletRequestContext.getSession();
            servletRequestContext.setSession(null);
            servletRequestContext.setCurrentServletContext(this.servletContext);
            this.servletContext.invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    forwardImpl(request, response, servletRequestContext);
                    return null;
                }
            });

        } finally {
                servletRequestContext.setSession(oldSession);
                servletRequestContext.setCurrentServletContext(oldServletContext);
        }
    } else {
        forwardImpl(request, response, servletRequestContext);
    }

}
 
Example #10
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
void invokeAction(HttpServerExchange exchange, ThreadSetupHandler.Action<Void, Object> listener) {
    try {
        this.invokeActionTask.call(exchange, listener);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #11
Source File: ServerWebSocketContainer.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public ServerWebSocketContainer(final ClassIntrospecter classIntrospecter, final ClassLoader classLoader, Supplier<EventLoopGroup> eventLoopSupplier, List<ThreadSetupHandler> threadSetupHandlers, boolean dispatchToWorker, InetSocketAddress clientBindAddress, WebSocketReconnectHandler reconnectHandler, Supplier<Executor> executorSupplier, List<Extension> installedExtensions, int maxFrameSize) {
    this.classIntrospecter = classIntrospecter;
    this.eventLoopSupplier = eventLoopSupplier;
    this.dispatchToWorker = dispatchToWorker;
    this.clientBindAddress = clientBindAddress;
    this.executorSupplier = executorSupplier;
    this.installedExtensions = new ArrayList<>(installedExtensions);
    this.webSocketReconnectHandler = reconnectHandler;
    this.maxFrameSize = maxFrameSize;
    ThreadSetupHandler.Action<Void, Runnable> task = new ThreadSetupHandler.Action<Void, Runnable>() {
        @Override
        public Void call(HttpServerExchange exchange, Runnable context) throws Exception {
            context.run();
            return null;
        }
    };
    List<WebsocketClientSslProvider> clientSslProviders = new ArrayList<>();
    for (WebsocketClientSslProvider provider : ServiceLoader.load(WebsocketClientSslProvider.class, classLoader)) {
        clientSslProviders.add(provider);
    }

    this.clientSslProviders = Collections.unmodifiableList(clientSslProviders);
    for (ThreadSetupHandler handler : threadSetupHandlers) {
        task = handler.create(task);
    }
    this.invokeEndpointTask = task;
}
 
Example #12
Source File: SessionListenerBridge.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public SessionListenerBridge(final Deployment deployment, final ApplicationListeners applicationListeners, final ServletContext servletContext) {
    this.applicationListeners = applicationListeners;
    this.servletContext = servletContext;
    this.destroyedAction = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, Session>() {
        @Override
        public Void call(HttpServerExchange exchange, Session session) throws ServletException {
            doDestroy(session);
            return null;
        }
    });
}
 
Example #13
Source File: DeploymentImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public <C, T> ThreadSetupHandler.Action<C, T> createThreadSetupAction(ThreadSetupHandler.Action<C, T> target) {
    ThreadSetupHandler.Action<C, T> ret = target;
    for(ThreadSetupHandler wrapper : threadSetupActions) {
        ret = wrapper.create(ret);
    }
    return ret;
}
 
Example #14
Source File: RequestDispatcherImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private void setupIncludeImpl(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
    final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
    if(servletRequestContext == null) {
        UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
        mock(request, response);
        return;
    }
    final HttpServletRequestImpl requestImpl = servletRequestContext.getOriginalRequest();
    final HttpServletResponseImpl responseImpl = servletRequestContext.getOriginalResponse();
    ServletContextImpl oldServletContext = null;
    HttpSessionImpl oldSession = null;
    if (servletRequestContext.getCurrentServletContext() != this.servletContext) {
        //cross context request, we need to run the thread setup actions
        oldServletContext = servletRequestContext.getCurrentServletContext();
        oldSession = servletRequestContext.getSession();
        servletRequestContext.setSession(null);
        servletRequestContext.setCurrentServletContext(this.servletContext);
        try {
            servletRequestContext.getCurrentServletContext().invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
                @Override
                public Void call(HttpServerExchange exchange, Object context) throws Exception {
                    includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
                    return null;
                }
            });
        } finally {
            // update time in new context and run the requestDone for the session
            servletRequestContext.getCurrentServletContext().updateSessionAccessTime(servletRequestContext.getExchange());
            servletRequestContext.setSession(oldSession);
            servletRequestContext.setCurrentServletContext(oldServletContext);
        }
    } else {
        includeImpl(request, response, servletRequestContext, requestImpl, responseImpl);
    }
}
 
Example #15
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
void invokeAction(HttpServerExchange exchange, ThreadSetupHandler.Action<Void, Object> listener) {
    try {
        this.invokeActionTask.call(exchange, listener);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #16
Source File: ServerWebSocketContainer.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public ServerWebSocketContainer(final ClassIntrospecter classIntrospecter, final ClassLoader classLoader, Supplier<EventLoopGroup> eventLoopSupplier, List<ThreadSetupHandler> threadSetupHandlers, boolean dispatchToWorker, InetSocketAddress clientBindAddress, WebSocketReconnectHandler reconnectHandler, Supplier<Executor> executorSupplier, List<Extension> installedExtensions) {
    this(classIntrospecter, classLoader, eventLoopSupplier, threadSetupHandlers, dispatchToWorker, clientBindAddress, reconnectHandler, executorSupplier, installedExtensions, DEFAULT_MAX_FRAME_SIZE);
}
 
Example #17
Source File: ServerWebSocketContainer.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public ServerWebSocketContainer(final ClassIntrospecter classIntrospecter, final ClassLoader classLoader, Supplier<EventLoopGroup> eventLoopSupplier, List<ThreadSetupHandler> threadSetupHandlers, boolean dispatchToWorker, InetSocketAddress clientBindAddress, WebSocketReconnectHandler reconnectHandler) {
    this(classIntrospecter, classLoader, eventLoopSupplier, threadSetupHandlers, dispatchToWorker, clientBindAddress, reconnectHandler, null, Collections.emptyList());
}
 
Example #18
Source File: ServerWebSocketContainer.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public ServerWebSocketContainer(final ClassIntrospecter classIntrospecter, final ClassLoader classLoader, Supplier<EventLoopGroup> eventLoopSupplier, List<ThreadSetupHandler> threadSetupHandlers, boolean dispatchToWorker, Supplier<Executor> executorSupplier) {
    this(classIntrospecter, classLoader, eventLoopSupplier, threadSetupHandlers, dispatchToWorker, null, null, executorSupplier, Collections.emptyList());
}
 
Example #19
Source File: ServerWebSocketContainer.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public ServerWebSocketContainer(final ClassIntrospecter classIntrospecter, final Supplier<EventLoopGroup> eventLoopSupplier, List<ThreadSetupHandler> threadSetupHandlers, boolean dispatchToWorker, boolean clientMode) {
    this(classIntrospecter, ServerWebSocketContainer.class.getClassLoader(), eventLoopSupplier, threadSetupHandlers, dispatchToWorker, null, null);
}
 
Example #20
Source File: DeploymentImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
void setThreadSetupActions(List<ThreadSetupHandler> threadSetupActions) {
    this.threadSetupActions = threadSetupActions;
}
 
Example #21
Source File: DeploymentImpl.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
void setThreadSetupActions(List<ThreadSetupHandler> threadSetupActions) {
    this.threadSetupActions = threadSetupActions;
}