io.undertow.servlet.spec.ServletContextImpl Java Examples
The following examples show how to use
io.undertow.servlet.spec.ServletContextImpl.
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: ChangeSessionId.java From keycloak with Apache License 2.0 | 6 votes |
public static String changeSessionId(HttpServerExchange exchange, boolean create) { final ServletRequestContext sc = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletContextImpl currentServletContext = sc.getCurrentServletContext(); HttpSessionImpl session = currentServletContext.getSession(exchange, create); if (session == null) { return null; } Session underlyingSession; if(System.getSecurityManager() == null) { underlyingSession = session.getSession(); } else { underlyingSession = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session)); } return underlyingSession.changeSessionId(exchange, currentServletContext.getSessionConfig()); }
Example #2
Source File: DeploymentManagerImpl.java From quarkus-http with Apache License 2.0 | 6 votes |
public void handleDeploymentSessionConfig(DeploymentInfo deploymentInfo, ServletContextImpl servletContext) { SessionCookieConfigImpl sessionCookieConfig = servletContext.getSessionCookieConfig(); ServletSessionConfig sc = deploymentInfo.getServletSessionConfig(); if (sc != null) { sessionCookieConfig.setName(sc.getName()); sessionCookieConfig.setComment(sc.getComment()); sessionCookieConfig.setDomain(sc.getDomain()); sessionCookieConfig.setHttpOnly(sc.isHttpOnly()); sessionCookieConfig.setMaxAge(sc.getMaxAge()); if(sc.getPath() != null) { sessionCookieConfig.setPath(sc.getPath()); } else { sessionCookieConfig.setPath(deploymentInfo.getContextPath()); } sessionCookieConfig.setSecure(sc.isSecure()); if (sc.getSessionTrackingModes() != null) { servletContext.setDefaultSessionTrackingModes(new HashSet<>(sc.getSessionTrackingModes())); } } }
Example #3
Source File: ServletContextListenerTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@Test public void testServletContextAttributeListener() throws IOException { ServletContextImpl sc = manager.getDeployment().getServletContext(); sc.setAttribute("test", "1"); Assert.assertNotNull(ServletContextTestListener.servletContextAttributeEvent); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getName(), "test"); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getValue(), "1"); sc.setAttribute("test", "2"); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getName(), "test"); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getValue(), "1"); sc.setAttribute("test", "3"); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getName(), "test"); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getValue(), "2"); sc.removeAttribute("test"); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getName(), "test"); Assert.assertEquals(ServletContextTestListener.servletContextAttributeEvent.getValue(), "3"); }
Example #4
Source File: CamelWebSocketJSR356Recorder.java From camel-quarkus with Apache License 2.0 | 6 votes |
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 #5
Source File: ServletInitialHandler.java From lams with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: ServletInitialHandler.java From quarkus-http with Apache License 2.0 | 6 votes |
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 #7
Source File: DeploymentManagerImpl.java From lams with GNU General Public License v2.0 | 6 votes |
public void handleDeploymentSessionConfig(DeploymentInfo deploymentInfo, ServletContextImpl servletContext) { SessionCookieConfigImpl sessionCookieConfig = servletContext.getSessionCookieConfig(); ServletSessionConfig sc = deploymentInfo.getServletSessionConfig(); if (sc != null) { sessionCookieConfig.setName(sc.getName()); sessionCookieConfig.setComment(sc.getComment()); sessionCookieConfig.setDomain(sc.getDomain()); sessionCookieConfig.setHttpOnly(sc.isHttpOnly()); sessionCookieConfig.setMaxAge(sc.getMaxAge()); if(sc.getPath() != null) { sessionCookieConfig.setPath(sc.getPath()); } else { sessionCookieConfig.setPath(deploymentInfo.getContextPath()); } sessionCookieConfig.setSecure(sc.isSecure()); if (sc.getSessionTrackingModes() != null) { servletContext.setDefaultSessionTrackingModes(new HashSet<>(sc.getSessionTrackingModes())); } } }
Example #8
Source File: AtmosphereWebSocketUndertowDestination.java From cxf with Apache License 2.0 | 6 votes |
public void handleNormalRequest(HttpServerExchange undertowExchange) throws Exception { HttpServletResponseImpl response = new HttpServletResponseImpl(undertowExchange, (ServletContextImpl)servletContext); HttpServletRequestImpl request = new HttpServletRequestImpl(undertowExchange, (ServletContextImpl)servletContext); ServletRequestContext servletRequestContext = new ServletRequestContext(((ServletContextImpl)servletContext) .getDeployment(), request, response, null); undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext); try { framework.doCometSupport(AtmosphereRequestImpl.wrap(request), AtmosphereResponseImpl.wrap(response)); } catch (ServletException e) { throw new IOException(e); } }
Example #9
Source File: DeploymentManagerImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private HttpHandler handleDevelopmentModePersistentSessions(HttpHandler next, final DeploymentInfo deploymentInfo, final SessionManager sessionManager, final ServletContextImpl servletContext) { final SessionPersistenceManager sessionPersistenceManager = deploymentInfo.getSessionPersistenceManager(); if (sessionPersistenceManager != null) { SessionRestoringHandler handler = new SessionRestoringHandler(deployment.getDeploymentInfo().getDeploymentName(), sessionManager, servletContext, next, sessionPersistenceManager); deployment.addLifecycleObjects(handler); return handler; } return next; }
Example #10
Source File: DeploymentManagerImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private void initializeTempDir(final ServletContextImpl servletContext, final DeploymentInfo deploymentInfo) { if (deploymentInfo.getTempDir() != null) { servletContext.setAttribute(ServletContext.TEMPDIR, deploymentInfo.getTempDir()); } else { servletContext.setAttribute(ServletContext.TEMPDIR, new File(SecurityActions.getSystemProperty("java.io.tmpdir"))); } }
Example #11
Source File: ManagedServlet.java From lams with GNU General Public License v2.0 | 5 votes |
public ManagedServlet(final ServletInfo servletInfo, final ServletContextImpl servletContext) { this.servletInfo = servletInfo; this.servletContext = servletContext; if (SingleThreadModel.class.isAssignableFrom(servletInfo.getServletClass())) { instanceStrategy = new SingleThreadModelPoolStrategy(servletInfo.getInstanceFactory(), servletInfo, servletContext); } else { instanceStrategy = new DefaultInstanceStrategy(servletInfo.getInstanceFactory(), servletInfo, servletContext); } setupMultipart(servletContext); }
Example #12
Source File: SecurityActions.java From lams with GNU General Public License v2.0 | 5 votes |
static ServletInitialHandler createServletInitialHandler(final ServletPathMatches paths, final HttpHandler next, final Deployment deployment, final ServletContextImpl servletContext) { if (System.getSecurityManager() == null) { return new ServletInitialHandler(paths, next, deployment, servletContext); } else { return AccessController.doPrivileged(new PrivilegedAction<ServletInitialHandler>() { @Override public ServletInitialHandler run() { return new ServletInitialHandler(paths, next, deployment, servletContext); } }); } }
Example #13
Source File: SessionRestoringHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SessionRestoringHandler(String deploymentName, SessionManager sessionManager, ServletContextImpl servletContext, HttpHandler next, SessionPersistenceManager sessionPersistenceManager) { this.deploymentName = deploymentName; this.sessionManager = sessionManager; this.servletContext = servletContext; this.next = next; this.sessionPersistenceManager = sessionPersistenceManager; this.data = new ConcurrentHashMap<>(); }
Example #14
Source File: Bootstrap.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void contextInitialized(ServletContextEvent sce) { container = (ServerWebSocketContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName()); FilterRegistration.Dynamic filter = sce.getServletContext().addFilter(FILTER_NAME, JsrWebSocketFilter.class); sce.getServletContext().addListener(JsrWebSocketFilter.LogoutListener.class); filter.setAsyncSupported(true); if(!container.getConfiguredServerEndpoints().isEmpty()){ filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); } else { container.setContextToAddFilter((ServletContextImpl) sce.getServletContext()); } }
Example #15
Source File: UndertowWebSocketDestination.java From cxf with Apache License 2.0 | 5 votes |
public void handleNormalRequest(HttpServerExchange undertowExchange) throws Exception { HttpServletResponseImpl response = new HttpServletResponseImpl(undertowExchange, (ServletContextImpl)servletContext); HttpServletRequestImpl request = new HttpServletRequestImpl(undertowExchange, (ServletContextImpl)servletContext); ServletRequestContext servletRequestContext = new ServletRequestContext(((ServletContextImpl)servletContext) .getDeployment(), request, response, null); undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext); doService(request, response); }
Example #16
Source File: SecurityActions.java From quarkus-http with Apache License 2.0 | 5 votes |
static ServletInitialHandler createServletInitialHandler(final ServletPathMatches paths, final HttpHandler next, final Deployment deployment, final ServletContextImpl servletContext) { if (System.getSecurityManager() == null) { return new ServletInitialHandler(paths, next, deployment, servletContext); } else { return AccessController.doPrivileged(new PrivilegedAction<ServletInitialHandler>() { @Override public ServletInitialHandler run() { return new ServletInitialHandler(paths, next, deployment, servletContext); } }); } }
Example #17
Source File: UndertowHTTPTestHandler.java From cxf with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange undertowExchange) throws Exception { try { HttpServletResponseImpl response = new HttpServletResponseImpl(undertowExchange, (ServletContextImpl)servletContext); HttpServletRequestImpl request = new HttpServletRequestImpl(undertowExchange, (ServletContextImpl)servletContext); ServletRequestContext servletRequestContext = new ServletRequestContext(((ServletContextImpl)servletContext) .getDeployment(), request, response, null); undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext); request.setAttribute("HTTP_HANDLER", this); request.setAttribute("UNDERTOW_DESTINATION", undertowHTTPDestination); // just return the response for testing response.getOutputStream().write(responseStr.getBytes()); response.flushBuffer(); } catch (Throwable t) { t.printStackTrace(); if (undertowExchange.isResponseChannelAvailable()) { undertowExchange.setStatusCode(500); final String errorPage = "<html><head><title>Error</title>" + "</head><body>Internal Error 500" + t.getMessage() + "</body></html>"; undertowExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, Integer.toString(errorPage.length())); undertowExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); Sender sender = undertowExchange.getResponseSender(); sender.send(errorPage); } } }
Example #18
Source File: DeploymentManagerImpl.java From quarkus-http with Apache License 2.0 | 5 votes |
private void initializeTempDir(final ServletContextImpl servletContext, final DeploymentInfo deploymentInfo) { if (deploymentInfo.getTempDir() != null) { servletContext.setAttribute(ServletContext.TEMPDIR, deploymentInfo.getTempDir()); } else { servletContext.setAttribute(ServletContext.TEMPDIR, new File(SecurityActions.getSystemProperty("java.io.tmpdir"))); } }
Example #19
Source File: SessionRestoringHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SessionRestoringHandler(String deploymentName, SessionManager sessionManager, ServletContextImpl servletContext, HttpHandler next, SessionPersistenceManager sessionPersistenceManager) { this.deploymentName = deploymentName; this.sessionManager = sessionManager; this.servletContext = servletContext; this.next = next; this.sessionPersistenceManager = sessionPersistenceManager; this.data = new ConcurrentHashMap<>(); }
Example #20
Source File: ManagedServlet.java From quarkus-http with Apache License 2.0 | 5 votes |
public ManagedServlet(final ServletInfo servletInfo, final ServletContextImpl servletContext) { this.servletInfo = servletInfo; this.servletContext = servletContext; if (SingleThreadModel.class.isAssignableFrom(servletInfo.getServletClass())) { instanceStrategy = new SingleThreadModelPoolStrategy(servletInfo.getInstanceFactory(), servletInfo, servletContext); } else { instanceStrategy = new DefaultInstanceStrategy(servletInfo.getInstanceFactory(), servletInfo, servletContext); } setupMultipart(servletContext); }
Example #21
Source File: DeploymentManagerImpl.java From quarkus-http with Apache License 2.0 | 5 votes |
private HttpHandler handleDevelopmentModePersistentSessions(HttpHandler next, final DeploymentInfo deploymentInfo, final SessionManager sessionManager, final ServletContextImpl servletContext) { final SessionPersistenceManager sessionPersistenceManager = deploymentInfo.getSessionPersistenceManager(); if (sessionPersistenceManager != null) { SessionRestoringHandler handler = new SessionRestoringHandler(deployment.getDeploymentInfo().getDeploymentName(), sessionManager, servletContext, next, sessionPersistenceManager); deployment.addLifecycleObjects(handler); return handler; } return next; }
Example #22
Source File: DeploymentImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public ServletContextImpl getServletContext() { return servletContext; }
Example #23
Source File: UndertowHTTPHandler.java From cxf with Apache License 2.0 | 4 votes |
@Override public void handleRequest(HttpServerExchange undertowExchange) throws Exception { try { // perform blocking operation on exchange if (undertowExchange.isInIoThread()) { undertowExchange.dispatch(this); return; } HttpServletResponseImpl response = new HttpServletResponseImpl(undertowExchange, (ServletContextImpl)servletContext); HttpServletRequestImpl request = new HttpServletRequestImpl(undertowExchange, (ServletContextImpl)servletContext); if (request.getMethod().equals(METHOD_TRACE)) { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; } ServletRequestContext servletRequestContext = new ServletRequestContext(((ServletContextImpl)servletContext) .getDeployment(), request, response, null); undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext); request.setAttribute("HTTP_HANDLER", this); request.setAttribute("UNDERTOW_DESTINATION", undertowHTTPDestination); SSLSessionInfo ssl = undertowExchange.getConnection().getSslSessionInfo(); if (ssl != null) { request.setAttribute(SSL_CIPHER_SUITE_ATTRIBUTE, ssl.getCipherSuite()); try { request.setAttribute(SSL_PEER_CERT_CHAIN_ATTRIBUTE, ssl.getPeerCertificates()); } catch (Exception e) { // for some case won't have the peer certification // do nothing } } undertowHTTPDestination.doService(servletContext, request, response); } catch (Throwable t) { t.printStackTrace(); if (undertowExchange.isResponseChannelAvailable()) { undertowExchange.setStatusCode(500); final String errorPage = "<html><head><title>Error</title>" + "</head><body>Internal Error 500" + t.getMessage() + "</body></html>"; undertowExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, Integer.toString(errorPage.length())); undertowExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); Sender sender = undertowExchange.getResponseSender(); sender.send(errorPage); } } }
Example #24
Source File: CachedAuthenticatedSessionHandler.java From quarkus-http with Apache License 2.0 | 4 votes |
public CachedAuthenticatedSessionHandler(final HttpHandler next, final ServletContextImpl servletContext) { this.next = next; this.servletContext = servletContext; }
Example #25
Source File: ServletRequestContext.java From quarkus-http with Apache License 2.0 | 4 votes |
public ServletContextImpl getCurrentServletContext() { return currentServletContext; }
Example #26
Source File: ServletRequestContext.java From quarkus-http with Apache License 2.0 | 4 votes |
public void setCurrentServletContext(ServletContextImpl currentServletContext) { this.currentServletContext = currentServletContext; }
Example #27
Source File: ManagedFilter.java From quarkus-http with Apache License 2.0 | 4 votes |
public ManagedFilter(final FilterInfo filterInfo, final ServletContextImpl servletContext) { this.filterInfo = filterInfo; this.servletContext = servletContext; }
Example #28
Source File: DeploymentImpl.java From quarkus-http with Apache License 2.0 | 4 votes |
void setServletContext(final ServletContextImpl servletContext) { this.servletContext = servletContext; }
Example #29
Source File: ManagedServlet.java From lams with GNU General Public License v2.0 | 4 votes |
private SingleThreadModelPoolStrategy(final InstanceFactory<? extends Servlet> factory, final ServletInfo servletInfo, final ServletContextImpl servletContext) { this.factory = factory; this.servletInfo = servletInfo; this.servletContext = servletContext; }
Example #30
Source File: ManagedServlet.java From lams with GNU General Public License v2.0 | 4 votes |
DefaultInstanceStrategy(final InstanceFactory<? extends Servlet> factory, final ServletInfo servletInfo, final ServletContextImpl servletContext) { this.factory = factory; this.servletInfo = servletInfo; this.servletContext = servletContext; }