List of usage examples for javax.servlet ServletContext setAttribute
public void setAttribute(String name, Object object);
From source file:no.kantega.publishing.spring.OpenAksessContextLoaderListener.java
@Override protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext wac) { Configuration.setApplicationDirectory(dataDirectory); // Make dataDir available as Servlet Context attribute servletContext.setAttribute(APPLICATION_DIRECTORY, dataDirectory); // Set up @Autowired support ApplicationContextUtils.addAutowiredSupport(wac); final Configuration configuration = new Configuration(properties); if (configuration.getBoolean("caching.enabled", true)) { wac.getEnvironment().setActiveProfiles("useCaching"); }/*w w w . j a va2 s .co m*/ Aksess.setContextPath(servletContext.getContextPath()); // Set and load configuration on these classes since they are not DI-based (hackish..) Aksess.setConfiguration(configuration); Aksess.loadConfiguration(); // Add ${appDir} property for the Spring Context ApplicationContextUtils.addAppDirPropertySupport(wac); dbConnectionFactory.setServletContext(servletContext); dbConnectionFactory.setConfiguration(configuration); dbConnectionFactory.loadConfiguration(); // Add the Configuration and the ConfigurationLoader as Spring beans addConfigurationAndLoaderAsSingletonsInContext(wac, configuration, configurationLoader); // Replace ${} properties in Spring with config properties addConfigurationPropertyReplacer(wac, properties); RootContext.setInstance(wac); }
From source file:br.gov.jfrj.siga.libs.webwork.SigaAnonimoActionSupport.java
public void setSharedContextAttribute(String name, Object attr) { ServletContext sigaContext = getContext().getContext("/siga"); if (sigaContext == null) return;/* w ww .ja v a 2s.co m*/ String sessionId = getRequest().getSession().getId(); sigaContext.setAttribute(sessionId + "-" + name, attr); }
From source file:com.ikon.servlet.admin.ReportServlet.java
/** * Show report parameters, previous step to execution *///w w w.j a v a 2 s .c om private void getParams(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, ParseException { log.debug("getParams({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); int rpId = WebUtils.getInt(request, "rp_id"); List<FormElement> params = ReportUtils.getReportParameters(rpId); sc.setAttribute("rp_id", rpId); sc.setAttribute("params", params); sc.setAttribute("ReportUtil", new ReportUtils()); sc.getRequestDispatcher("/admin/report_get_params.jsp").forward(request, response); log.debug("getParams: void"); }
From source file:com.sonicle.webtop.core.app.ContextLoader.java
public void initApp(ServletContext servletContext) throws IllegalStateException { String webappName = ContextUtils.getWebappFullName(servletContext, false); servletContext.setAttribute(WEBAPPNAME_ATTRIBUTE_KEY, webappName); if (servletContext.getAttribute(WEBTOPAPP_ATTRIBUTE_KEY) != null) { throw new IllegalStateException( "There is already a WebTop application associated with the current ServletContext."); }//from w w w .ja v a2 s. co m try { WebTopApp wta = new WebTopApp(servletContext); wta.boot(); servletContext.setAttribute(WEBTOPAPP_ATTRIBUTE_KEY, wta); servletContext.setAttribute(JWTSignatureVerifier.SECRET_CONTEXT_ATTRIBUTE, wta.getDocumentServerSecretIn()); Dynamic atmosphereServlet = servletContext.addServlet("AtmosphereServlet", com.sonicle.webtop.core.app.atmosphere.AtmosphereServlet.class); atmosphereServlet.setInitParameter("org.atmosphere.cpr.AtmosphereFramework.analytics", "false"); atmosphereServlet.setInitParameter("org.atmosphere.cpr.broadcasterCacheClass", "com.sonicle.webtop.core.app.atmosphere.UUIDBroadcasterCache"); atmosphereServlet.setInitParameter("org.atmosphere.cpr.broadcasterLifeCyclePolicy", "BroadcasterLifeCyclePolicy.EMPTY"); atmosphereServlet.setInitParameter("org.atmosphere.cpr.asyncSupport", "org.atmosphere.container.JSR356AsyncSupport"); //atmosphereServlet.setInitParameter("org.atmosphere.cpr.asyncSupport", "org.atmosphere.container.Tomcat7CometSupport"); atmosphereServlet.setInitParameter("org.atmosphere.cpr.sessionSupport", "true"); atmosphereServlet.setInitParameter("org.atmosphere.cpr.sessionCreate", "false"); atmosphereServlet.setInitParameter("org.atmosphere.cpr.broadcaster.shareableThreadPool", "true"); atmosphereServlet.setInitParameter("org.atmosphere.cpr.AtmosphereInterceptor", "org.atmosphere.interceptor.ShiroInterceptor"); atmosphereServlet.setLoadOnStartup(1); atmosphereServlet.setAsyncSupported(true); atmosphereServlet.addMapping(com.sonicle.webtop.core.app.atmosphere.AtmosphereServlet.URL + "/*"); Dynamic resourcesServlet = servletContext.addServlet("ResourcesServlet", com.sonicle.webtop.core.app.servlet.ResourceRequest.class); resourcesServlet.setLoadOnStartup(1); resourcesServlet.addMapping(com.sonicle.webtop.core.app.servlet.ResourceRequest.URL + "/*"); Dynamic loginServlet = servletContext.addServlet("LoginServlet", com.sonicle.webtop.core.app.servlet.Login.class); loginServlet.setLoadOnStartup(1); loginServlet.addMapping(com.sonicle.webtop.core.app.servlet.Login.URL + "/*"); Dynamic logoutServlet = servletContext.addServlet("LogoutServlet", com.sonicle.webtop.core.app.servlet.Logout.class); logoutServlet.setLoadOnStartup(1); logoutServlet.addMapping(com.sonicle.webtop.core.app.servlet.Logout.URL + "/*"); Dynamic otpServlet = servletContext.addServlet("OtpServlet", com.sonicle.webtop.core.app.servlet.Otp.class); otpServlet.setLoadOnStartup(1); otpServlet.addMapping(com.sonicle.webtop.core.app.servlet.Otp.URL + "/*"); Dynamic uiPrivateServlet = servletContext.addServlet("UIPrivateServlet", com.sonicle.webtop.core.app.servlet.UIPrivate.class); uiPrivateServlet.setLoadOnStartup(1); uiPrivateServlet.addMapping(com.sonicle.webtop.core.app.servlet.UIPrivate.URL + "/*"); Dynamic privateRequestServlet = servletContext.addServlet("PrivateRequestServlet", com.sonicle.webtop.core.app.servlet.PrivateRequest.class); privateRequestServlet.setLoadOnStartup(1); privateRequestServlet.addMapping(com.sonicle.webtop.core.app.servlet.PrivateRequest.URL + "/*"); privateRequestServlet.addMapping(com.sonicle.webtop.core.app.servlet.PrivateRequest.URL_LEGACY + "/*"); Dynamic publicRequestServlet = servletContext.addServlet("PublicRequestServlet", com.sonicle.webtop.core.app.servlet.PublicRequest.class); publicRequestServlet.setLoadOnStartup(1); publicRequestServlet.addMapping(com.sonicle.webtop.core.app.servlet.PublicRequest.URL + "/*"); Dynamic docEditorServlet = servletContext.addServlet("DocEditorServlet", com.sonicle.webtop.core.app.servlet.DocEditor.class); docEditorServlet.setLoadOnStartup(1); docEditorServlet.addMapping(com.sonicle.webtop.core.app.servlet.DocEditor.URL + "/*"); // Adds RestApiServlets dynamically ServiceManager svcMgr = wta.getServiceManager(); for (String serviceId : svcMgr.listRegisteredServices()) { ServiceDescriptor desc = svcMgr.getDescriptor(serviceId); if (desc.hasOpenApiDefinitions() || desc.hasRestApiEndpoints()) { addRestApiServlet(servletContext, desc); } } } catch (Throwable t) { servletContext.removeAttribute(WEBTOPAPP_ATTRIBUTE_KEY); logger.error("Error initializing WTA [{}]", webappName, t); } }
From source file:io.neba.core.logviewer.LogfileViewerConsolePlugin.java
/** * The {@link #DECORATED_OBJECT_FACTORY} is a dependency for using websockets and may not be registered, * depending on the jetty runtime setup. If it is not registered, this method loads and registers it. */// w w w . ja va 2s.co m private void injectDecoratorObjectFactoryIntoServletContext() throws ClassNotFoundException, IllegalAccessException, InstantiationException { ServletContext servletContext = getServletContext(); if (servletContext.getAttribute(DECORATED_OBJECT_FACTORY) != null || !isDecoratedObjectFactoryAvailable()) { return; } servletContext.setAttribute(DECORATED_OBJECT_FACTORY, forName(DECORATED_OBJECT_FACTORY).newInstance()); this.isManagingDecoratedObjectFactory = true; }
From source file:com.cimait.invoicec.portal.util.servlet.SBServletInitializer.java
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { ApplicationContext parent = null;/*www. j a v a 2 s . co m*/ Object object = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (object instanceof ApplicationContext) { this.logger.info("Root context already created (using as parent)."); parent = (ApplicationContext) object; servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null); } SpringApplicationBuilder application = new SpringApplicationBuilder(); if (parent != null) { application.initializers(new ParentContextApplicationContextInitializer(parent)); } application.initializers(new ServletContextApplicationContextInitializer(servletContext)); application.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); application = configure(application); // Ensure error pages are registered //application.sources(ErrorPageFilter.class); return (WebApplicationContext) application.run(); }
From source file:be.fedict.eid.idp.webapp.IdentityProviderServletContextListener.java
private void initIdentityProviderConfiguration(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); servletContext.setAttribute( IdentityProviderConfigurationFactory.IDENTITY_PROVIDER_CONFIGURATION_CONTEXT_ATTRIBUTE, this.identityService); }
From source file:org.apache.myfaces.shared_ext202patch.util.StateUtils.java
/** * Does nothing if the user has disabled the SecretKey cache. This is * useful when dealing with a JCA provider whose SecretKey * implementation is not thread safe.//from w ww .ja va2 s .c o m * * Instantiates a SecretKey instance based upon what the user has * specified in the deployment descriptor. The SecretKey is then * stored in application scope where it can be used for all requests. */ public static void initSecret(ServletContext ctx) { if (ctx == null) throw new NullPointerException("ServletContext ctx"); if (log.isLoggable(Level.FINE)) log.fine("Storing SecretKey @ " + INIT_SECRET_KEY_CACHE); // Create and store SecretKey on application scope String cache = ctx.getInitParameter(INIT_SECRET_KEY_CACHE); if (cache == null) { cache = ctx.getInitParameter(INIT_SECRET_KEY_CACHE.toLowerCase()); } if (!"false".equals(cache)) { String algorithm = findAlgorithm(ctx); // you want to create this as few times as possible ctx.setAttribute(INIT_SECRET_KEY_CACHE, new SecretKeySpec(findSecret(ctx, algorithm), algorithm)); } if (log.isLoggable(Level.FINE)) log.fine("Storing SecretKey @ " + INIT_MAC_SECRET_KEY_CACHE); String macCache = ctx.getInitParameter(INIT_MAC_SECRET_KEY_CACHE); if (macCache == null) { macCache = ctx.getInitParameter(INIT_MAC_SECRET_KEY_CACHE.toLowerCase()); } if (!"false".equals(macCache)) { String macAlgorithm = findMacAlgorithm(ctx); // init mac secret and algorithm ctx.setAttribute(INIT_MAC_SECRET_KEY_CACHE, new SecretKeySpec(findMacSecret(ctx, macAlgorithm), macAlgorithm)); } }
From source file:org.springframework.boot.web.SpringBootServletInitializer.java
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { ApplicationContext parent = null;/*from w ww. ja va2s .co m*/ Object object = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (object instanceof ApplicationContext) { this.logger.info("Root context already created (using as parent)."); parent = (ApplicationContext) object; servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null); } SpringApplicationBuilder application = new SpringApplicationBuilder(); if (parent != null) { application.initializers(new ParentContextApplicationContextInitializer(parent)); } application.initializers(new ServletContextApplicationContextInitializer(servletContext)); application.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); application = configure(application); return (WebApplicationContext) application.run(); }
From source file:com.ikon.servlet.admin.OmrServlet.java
/** * results//w w w .j a va2 s . co m */ private void results(String userId, HttpServletRequest request, HttpServletResponse response, String action, Map<String, String> results, long omId) throws DatabaseException, ServletException, IOException { ServletContext sc = getServletContext(); sc.setAttribute("action", action); sc.setAttribute("om", OmrDAO.getInstance().findByPk(omId)); sc.setAttribute("results", results); sc.getRequestDispatcher("/admin/omr_check.jsp").forward(request, response); log.debug("check: void"); }