List of usage examples for javax.servlet ServletContext setAttribute
public void setAttribute(String name, Object object);
From source file:org.josso.servlet.agent.GenericServletSSOAgentFilter.java
public void init(FilterConfig filterConfig) throws ServletException { // Validate and update our current component state ServletContext ctx = filterConfig.getServletContext(); ctx.setAttribute(KEY_SESSION_MAP, new HashMap()); if (_agent == null) { try {// www . ja v a 2s .com Lookup lookup = Lookup.getInstance(); lookup.init("josso-agent-config.xml"); // For spring compatibility ... // We need at least an abstract SSO Agent _agent = (HttpSSOAgent) lookup.lookupSSOAgent(); if (log.isDebugEnabled()) _agent.setDebug(1); _agent.start(); // Publish agent in servlet context filterConfig.getServletContext().setAttribute("org.josso.agent", _agent); } catch (Exception e) { throw new ServletException("Error starting SSO Agent : " + e.getMessage(), e); } } }
From source file:org.impalaframework.web.spring.loader.BaseImpalaContextLoader.java
protected ConfigurableApplicationContext initImpalaApplicationContext(ServletContext servletContext, final WebApplicationContext superContext) { ModuleManagementFacade facade = createModuleManagementFacade(servletContext, superContext); // load the parent context, which is web-independent ModuleDefinitionSource moduleDefinitionSource = getModuleDefinitionSource(servletContext, facade); // add items to servlet context servletContext.setAttribute(WebConstants.MODULE_DEFINITION_SOURCE_ATTRIBUTE, moduleDefinitionSource); servletContext.setAttribute(WebConstants.IMPALA_FACTORY_ATTRIBUTE, facade); ApplicationManager applicationManager = facade.getApplicationManager(); Application application = applicationManager.getCurrentApplication(); ModuleOperationInput input = new ModuleOperationInput(moduleDefinitionSource, null, null); ModuleOperation operation = facade.getModuleOperationRegistry() .getOperation(ModuleOperationConstants.UpdateRootModuleOperation); operation.execute(application, input); ConfigurableApplicationContext context = SpringModuleUtils .getRootSpringContext(application.getModuleStateHolder()); if (context == null) { logger.warn("Root module context is null: no modules loaded"); } else if (!(context instanceof WebApplicationContext)) { throw new InvalidStateException( "Application context " + context + " has class " + context.getClass().getName() + " which is not an instance of " + WebApplicationContext.class.getName()); }/*from w ww. ja v a 2 s .c o m*/ return context; }
From source file:org.josso.wls10.agent.WLSAgentServletFilter.java
public void init(FilterConfig filterConfig) throws ServletException { // Validate and update our current component state ServletContext ctx = filterConfig.getServletContext(); ctx.setAttribute(KEY_SESSION_MAP, new HashMap()); if (_agent == null) { try {//from w w w. j a v a 2s . co m Lookup lookup = Lookup.getInstance(); lookup.init("josso-agent-config.xml"); // For spring compatibility ... // We need at least an abstract SSO Agent _agent = (WLSSSOAgent) lookup.lookupSSOAgent(); if (log.isDebugEnabled()) _agent.setDebug(1); _agent.start(); // Publish agent in servlet context filterConfig.getServletContext().setAttribute("org.josso.agent", _agent); } catch (Exception e) { throw new ServletException("Error starting SSO Agent : " + e.getMessage(), e); } } }
From source file:org.josso.liferay6.agent.LiferaySSOAgentFilter.java
public void init(FilterConfig filterConfig) { super.init(filterConfig); // Validate and update our current component state ServletContext ctx = filterConfig.getServletContext(); ctx.setAttribute(KEY_SESSION_MAP, new HashMap()); if (_agent == null) { try {/*www . java 2 s . c om*/ Lookup lookup = Lookup.getInstance(); lookup.init("josso-agent-config.xml"); // For spring compatibility ... // We need at least an abstract SSO Agent _agent = (HttpSSOAgent) lookup.lookupSSOAgent(); if (log.isDebugEnabled()) _agent.setDebug(1); _agent.start(); // Publish agent in servlet context filterConfig.getServletContext().setAttribute("org.josso.agent", _agent); } catch (Exception e) { _log.error("Error starting SSO Agent", e); } } }
From source file:ubic.gemma.web.listener.StartupListener.java
@Override public void contextInitialized(ServletContextEvent event) { StartupListener.log.info("Initializing Gemma web context ..."); StopWatch sw = new StopWatch(); sw.start();//from w w w . j a va2 s. c om // call Spring's context ContextLoaderListener to initialize // all the context files specified in web.xml super.contextInitialized(event); ServletContext servletContext = event.getServletContext(); Map<String, Object> config = this.initializeConfiguration(servletContext); this.loadTheme(servletContext, config); this.loadVersionInformation(config); this.loadTrackerInformation(config); ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL); servletContext.setAttribute(Constants.CONFIG, config); this.initializeHomologene(ctx); this.configureScheduler(ctx); sw.stop(); double time = sw.getTime() / 1000.00; StartupListener.log.info("Initialization of Gemma Spring web context in " + time + " s "); }
From source file:ro.cs.logaudit.start.InitApplication.java
/** * Initializarea contextului. Aici se preiau nomenclatoarele ce se vor * pastra pe sesiune/*from w w w . j ava 2 s. co m*/ */ public void init(ServletConfig conf) throws ServletException { logger.info("Initializare aplicatie..."); try { ServletContext sc = conf.getServletContext(); logger.info("*******************************************************"); logger.info("* *"); logger.info("* INITIATING APPLICATION AUDIT-> *"); logger.info("* *"); logger.info("*******************************************************"); logger.info(IConstant.APP_VERSION.concat("/").concat(IConstant.APP_RELEASE_DATE)); sc.setAttribute("VERSION", IConstant.APP_VERSION); sc.setAttribute("RELEASE_DATE", IConstant.APP_RELEASE_DATE); sc.setAttribute("RELEASE_YEAR", IConstant.APP_RELEASE_YEAR); //Nomenclators ListLoader.getInstance().load_nom_resultsPerPage(); ListLoader.getInstance().load_nom_module(); ListLoader.getInstance().load_nom_om_audit_events(); ListLoader.getInstance().load_nom_dm_audit_events(); ListLoader.getInstance().load_nom_cm_audit_events(); ListLoader.getInstance().load_nom_ts_audit_events(); RoleVoter rv = (RoleVoter) AuditContext.getApplicationContext().getBean("roleVoter"); // put exceptionContant bean on servletContect sc.setAttribute(IConstant.EXCEPTION_CONSTANT, ExceptionConstant.getInstance()); sc.setAttribute(IConstant.PERMISSION_CONSTANT, PermissionConstant.getInstance()); sc.setAttribute(IConstant.AUDIT_REPORT_SERVLET, ConfigParametersProvider.getConfigString("audit.report.servlet.url")); logger.info("Role Prefix: \"" + rv.getRolePrefix() + "\""); logger.info("*******************************************************"); logger.info("* *"); logger.info("* INITIATING APPLICATION END AUDIT<- *"); logger.info("* *"); logger.info("*******************************************************"); } catch (Exception ex) { logger.info("*******************************************************"); logger.info("* *"); logger.info("* ERROR INITIATING APPLICATION!!! *"); logger.info("* *"); logger.info("*******************************************************"); logger.error("", ex); } logger.info("The application was initiated!"); }
From source file:edu.uci.ics.asterix.api.http.servlet.RESTAPIServlet.java
public void handleRequest(HttpServletRequest request, HttpServletResponse response, String query) throws IOException { SessionConfig sessionConfig = initResponse(request, response); AqlTranslator.ResultDelivery resultDelivery = whichResultDelivery(request); ServletContext context = getServletContext(); IHyracksClientConnection hcc;/*from w w w . jav a 2 s .c om*/ IHyracksDataset hds; try { synchronized (context) { hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR); hds = (IHyracksDataset) context.getAttribute(HYRACKS_DATASET_ATTR); if (hds == null) { hds = new HyracksDataset(hcc, ResultReader.FRAME_SIZE, ResultReader.NUM_READERS); context.setAttribute(HYRACKS_DATASET_ATTR, hds); } } AQLParser parser = new AQLParser(query); List<Statement> aqlStatements = parser.parse(); if (!containsForbiddenStatements(aqlStatements)) { MetadataManager.INSTANCE.init(); AqlTranslator aqlTranslator = new AqlTranslator(aqlStatements, sessionConfig); aqlTranslator.compileAndExecute(hcc, hds, resultDelivery); } } catch (ParseException | TokenMgrError | edu.uci.ics.asterix.aqlplus.parser.TokenMgrError pe) { GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe); String errorMessage = ResultUtils.buildParseExceptionMessage(pe, query); JSONObject errorResp = ResultUtils.getErrorResponse(2, errorMessage, "", ""); sessionConfig.out().write(errorResp.toString()); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (Exception e) { GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e); ResultUtils.apiErrorHandler(sessionConfig.out(), e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:org.jboss.web.tomcat.service.WebCtxLoader.java
/** * Set the appropriate context attribute for our class path. This * is required only because Jasper depends on it. *//*from w w w . j av a2 s. c om*/ private void setClassPath() { // Validate our current state information if (!(webContainer instanceof Context)) return; ServletContext servletContext = ((Context) webContainer).getServletContext(); if (servletContext == null) return; try { Method method = webContainer.getClass().getMethod("getCompilerClasspath", (Class[]) null); Object baseClasspath = method.invoke(webContainer, (Object[]) null); if (baseClasspath != null) { servletContext.setAttribute(Globals.CLASS_PATH_ATTR, baseClasspath.toString()); return; } } catch (Exception e) { // Ignore e.printStackTrace(); } StringBuffer classpath = new StringBuffer(); // Assemble the class path information from our repositories for (int i = 0; i < repositories.size(); i++) { String repository = repositories.get(i).toString(); if (repository.startsWith("file://")) repository = repository.substring(7); else if (repository.startsWith("file:")) repository = repository.substring(5); else if (repository.startsWith("jndi:")) repository = servletContext.getRealPath(repository.substring(5)); else continue; if (repository == null) continue; if (i > 0) classpath.append(File.pathSeparator); classpath.append(repository); } // Store the assembled class path as a servlet context attribute servletContext.setAttribute(Globals.CLASS_PATH_ATTR, classpath.toString()); }
From source file:org.intermine.web.logic.session.SessionMethods.java
/** * Return the ReportObjects Map from the session or create and return it if it doesn't exist. * * @param session the HttpSession to get the ReportObjects Map from * @return the (possibly new) ReportObjects Map *///from ww w . java 2s . c om public static ReportObjectFactory getReportObjects(HttpSession session) { ServletContext servletContext = session.getServletContext(); ReportObjectFactory reportObjects = (ReportObjectFactory) servletContext .getAttribute(Constants.REPORT_OBJECT_CACHE); // Build map from object id to ReportObject if (reportObjects == null) { InterMineAPI im = getInterMineAPI(session); WebConfig webConfig = getWebConfig(servletContext); Properties webProperties = getWebProperties(servletContext); reportObjects = new ReportObjectFactory(im, webConfig, webProperties); servletContext.setAttribute(Constants.REPORT_OBJECT_CACHE, reportObjects); } return reportObjects; }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.UserModelSetup.java
private void setupUserAccountModel(DataSource bds, ServletContext ctx, StartupStatus ss) { try {/*from ww w. jav a 2 s .com*/ Model userAccountsDbModel = makeDBModel(bds, JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC, ctx); OntModel userAccountsModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); // This is used in Selenium testing, when we load user accounts from a file. if (userAccountsDbModel.isEmpty()) { readOntologyFilesInPathSet(AUTHPATH, ctx, userAccountsDbModel); } userAccountsModel.add(userAccountsDbModel); userAccountsModel.getBaseModel().register(new ModelSynchronizer(userAccountsDbModel)); ctx.setAttribute("userAccountsOntModel", userAccountsModel); } catch (Throwable t) { log.error("Unable to load user accounts model from DB", t); ss.fatal(this, "Unable to load user accounts model from DB", t); } }