private static ServletContextHandler setWebHttpApiHandler () { ConfigureAdaptor conf = ConfigureManager.getConfigure(); String providerPackages = "scouterx.webapp"; if (conf.isNetHttpApiSwaggerEnabled()) { providerPackages += ",io.swagger.jaxrs.listing"; } final ServletHolder jerseyHolder = new ServletHolder(ServletContainer.class); jerseyHolder.setInitParameter("javax.ws.rs.Application", "scouterx.webapp.main.WebAppMain"); jerseyHolder.setInitParameter("jersey.config.server.provider.packages", providerPackages); jerseyHolder.setInitOrder(1); final ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setSessionHandler(new SessionHandler()); servletContextHandler.getSessionHandler().setMaxInactiveInterval(conf.getNetHttpApiSessionTimeout()); servletContextHandler.setContextPath("/"); servletContextHandler.addServlet(jerseyHolder, "/scouter/*"); servletContextHandler.addServlet(setStaticContentHandler(), "/*"); servletContextHandler.addServlet(setExtWebStaticContentHandler(), "/extweb/*"); servletContextHandler.addServlet(setSwaggerBootstrapHandler(), "/swagger"); addFilter(servletContextHandler); return servletContextHandler; }
public WebServer(Config config) { initServer(config); ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); int sessionTimeout = config.getInteger("web.sessionTimeout"); if (sessionTimeout > 0) { servletHandler.getSessionHandler().setMaxInactiveInterval(sessionTimeout); } initApi(config, servletHandler); if (config.getBoolean("web.console")) { servletHandler.addServlet(new ServletHolder(new ConsoleServlet()), "/console/*"); } initWebApp(config, servletHandler); servletHandler.setErrorHandler(new ErrorHandler() { @Override protected void handleErrorPage( HttpServletRequest request, Writer writer, int code, String message) throws IOException { writer.write("<!DOCTYPE<html><head><title>Error</title></head><html><body>" + code + " - " + HttpStatus.getMessage(code) + "</body></html>"); } }); HandlerList handlers = new HandlerList(); initClientProxy(config, handlers); handlers.addHandler(servletHandler); server.setHandler(handlers); }
public EmbeddedWebServer(String host, int port) { server = new Server(); final AccumuloConfiguration conf = Monitor.getContext().getConfiguration(); connector = new ServerConnector(server, getConnectionFactories(conf)); connector.setHost(host); connector.setPort(port); handler = new ServletContextHandler( ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY); handler.getSessionHandler().getSessionCookieConfig().setHttpOnly(true); handler.setContextPath("/"); }
private SessionIdManager findSessionManager(HandlerCollection handlerList) { for (Handler h : handlerList.getHandlers()) { if (h instanceof ServletContextHandler) { return ((ServletContextHandler) h).getSessionHandler().getSessionIdManager(); } } throw new IllegalStateException("Could not find SessionManager"); }
private SessionManager findSessionManager(HandlerList handlerList) { for (Handler h : handlerList.getHandlers()) { if (h instanceof ServletContextHandler) { return ((ServletContextHandler) h).getSessionHandler().getSessionManager(); } } throw new IllegalStateException("Could not find SessionManager"); }
@Override public HttpSession getHttpSession(String sessId) { return contextHandler.getSessionHandler().getSessionManager().getHttpSession(sessId); }
protected final void configureNewHandler(SessionIdManager sessionManager, String contextPath, ServletContextHandler handler) { handler.setContextPath(contextPath); handler.getSessionHandler().setSessionIdManager(sessionManager); handler.setServer(webServer.getJetty()); }
private void enableSessionSupport(Server server, String connectorKey) throws Exception { ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class); if (context.getSessionHandler() == null) { SessionHandler sessionHandler = new SessionHandler(); if (context.isStarted()) { throw new IllegalStateException("Server has already been started. Cannot enabled sessionSupport on " + connectorKey); } else { context.setSessionHandler(sessionHandler); } } }
/** * Gets the new servlet context handler. * * @param configuration * the configuration * @return the new servlet context handler */ public static ServletContextHandler getNewServletContextHandler( final ServletContextHandlerConfiguration configuration) { final ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS); context.setContextPath(configuration.getContextPath()); context.setResourceBase(configuration.getWebapp().getAbsolutePath()); context.getSessionHandler().setMaxInactiveInterval(configuration.getMaxInactiveInterval()); initializeFilterHolder(configuration, context); initializeServletHolder(configuration, context); for (final Entry<String, String> initParameter : configuration.getInitParameters() .entrySet()) { context.setInitParameter(initParameter.getKey(), initParameter.getValue()); } return context; }
protected ServletContextHandler createGraphAwareHandler(SessionManager sessionManager, ApplicationContext rootContext) { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(getContextPath(config)); context.getSessionHandler().setSessionManager(sessionManager); context.addLifeCycleListener(new JettyStartingListener(new WebAppInitializer(rootContext, getPackagesToScan(config)), context.getServletContext())); context.addFilter(new FilterHolder(txFilter), "/*", EnumSet.allOf(DispatcherType.class)); addDefaultFilters(context); return context; }
servletContextHandler.addFilter(DisableTraceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); servletContextHandler.getSessionHandler().getSessionManager().setSessionIdPathParameterName(null);
private static ServletContextHandler setWebHttpApiHandler () { ConfigureAdaptor conf = ConfigureManager.getConfigure(); String providerPackages = "scouterx.webapp"; if (conf.isNetHttpApiSwaggerEnabled()) { providerPackages += ",io.swagger.jaxrs.listing"; } final ServletHolder jerseyHolder = new ServletHolder(ServletContainer.class); jerseyHolder.setInitParameter("javax.ws.rs.Application", "scouterx.webapp.main.WebAppMain"); jerseyHolder.setInitParameter("jersey.config.server.provider.packages", providerPackages); jerseyHolder.setInitOrder(1); final ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setSessionHandler(new SessionHandler()); servletContextHandler.getSessionHandler().setMaxInactiveInterval(conf.getNetHttpApiSessionTimeout()); servletContextHandler.setContextPath("/"); servletContextHandler.addServlet(jerseyHolder, "/scouter/*"); servletContextHandler.addServlet(setStaticContentHandler(), "/*"); servletContextHandler.addServlet(setExtWebStaticContentHandler(), "/extweb/*"); servletContextHandler.addServlet(setSwaggerBootstrapHandler(), "/swagger"); addFilter(servletContextHandler); return servletContextHandler; }
context.addServlet(DefaultServlet.class, configuration.getFilterPath()); context.getSessionHandler().setMaxInactiveInterval(configuration.getMaxInactiveInterval()); return context;
handler.getSessionHandler().getSessionManager().getSessionCookieConfig().setHttpOnly(true);
@Override protected void onInitialize() throws UnifyException { try { logInfo("Initializing HTTP server on port {0}; using context path {1} and servlet path {2}...", Integer.toString(getHttpPort()), getContextPath(), getServletPath()); httpServer = new Server(getHttpPort()); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(getContextPath()); context.getSessionHandler().getSessionManager().setMaxInactiveInterval( getContainerSetting(int.class, UnifyCorePropertyConstants.APPLICATION_SESSION_TIMEOUT, UnifyContainer.DEFAULT_APPLICATION_SESSION_TIMEOUT)); httpServer.setHandler(context); ServletHolder mainHolder = new ServletHolder(createHttpServlet()); mainHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(getMultipartLocation(), getMultipartMaxFileSize(), getMultipartMaxRequestSize(), getMultipartFileSizeThreshold())); context.addServlet(mainHolder, getServletPath()); httpServer.start(); logInfo("HTTP server initialization completed."); } catch (Exception e) { throw new UnifyException(e, UnifyCoreErrorConstants.COMPONENT_INITIALIZATION_ERROR, getName()); } }
private void configureSessionManager(final ServletContextHandler context) throws Exception { final SessionHandler sessionHandler = context.getSessionHandler(); sessionHandler.setMaxInactiveInterval(this.config.getSessionTimeout() * 60); sessionHandler.setSessionIdPathParameterName(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_ID_PATH_PARAMETER_NAME, SessionHandler.__DefaultSessionIdPathParameterName)); sessionHandler.setCheckingRemoteSessionIdEncoding(this.config.getBooleanProperty(JettyConfig.FELIX_JETTY_SERVLET_CHECK_REMOTE_SESSION_ENCODING, true)); sessionHandler.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE)); final SessionCookieConfig cookieConfig = sessionHandler.getSessionCookieConfig(); cookieConfig.setName(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_COOKIE_NAME, SessionHandler.__DefaultSessionCookie)); cookieConfig.setDomain(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_DOMAIN, SessionHandler.__DefaultSessionDomain)); cookieConfig.setPath(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_PATH, context.getContextPath())); cookieConfig.setMaxAge(this.config.getIntProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_MAX_AGE, -1)); cookieConfig.setHttpOnly(this.config.getBooleanProperty(JettyConfig.FELIX_JETTY_SESSION_COOKIE_HTTP_ONLY, true)); cookieConfig.setSecure(this.config.getBooleanProperty(JettyConfig.FELIX_JETTY_SESSION_COOKIE_SECURE, false)); }
if (getSessionHandler()!=null)
TestHttpSessionListener listener = new TestHttpSessionListener(true); context.getSessionHandler().addEventListener(listener);