List of usage examples for javax.servlet ServletContext setAttribute
public void setAttribute(String name, Object object);
From source file:org.apache.struts2.views.freemarker.FreemarkerManager.java
public final synchronized freemarker.template.Configuration getConfiguration(ServletContext servletContext) throws TemplateException { freemarker.template.Configuration config = (freemarker.template.Configuration) servletContext .getAttribute(CONFIG_SERVLET_CONTEXT_KEY); if (config == null) { config = createConfiguration(servletContext); // store this configuration in the servlet context servletContext.setAttribute(CONFIG_SERVLET_CONTEXT_KEY, config); }/* www .j ava2 s . c om*/ config.setWhitespaceStripping(true); return config; }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderListener.java
@Override public void contextInitialized(ServletContextEvent sce) { final ServletContext servletContext = sce.getServletContext(); if (servletContext.getAttribute( PortletApplicationContextUtils2.ROOT_PORTLET_APPLICATION_CONTEXT_LOADER_ATTRIBUTE) != null) { throw new IllegalStateException( "Cannot initialize root portlet ContextLoader context because there is already a root PortletContextLoader present - " + "check whether you have multiple PortletContextLoaderListener definitions in your web.xml!"); }/*from ww w. j av a2s . c o m*/ //Register the portlet context loader with the servlet context contextLoader = new PortletContextLoader(servletContext); servletContext.setAttribute( PortletApplicationContextUtils2.ROOT_PORTLET_APPLICATION_CONTEXT_LOADER_ATTRIBUTE, contextLoader); }
From source file:ro.cs.ts.start.InitApplication.java
/** * Initializarea contextului. Aici se preiau nomenclatoarele ce se vor * pastra pe sesiune//from w w w . j av a 2s .c o 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 TIME SHEET-> *"); 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 // RESULTS PER PAGE ListLoader.getInstance().load_nom_resultsPerPage(); // PROJECT ListLoader.getInstance().load_nom_projectStatus(); //BILLABLE ListLoader.getInstance().load_nom_billable(); // TIME UNIT ListLoader.getInstance().load_nom_timeUnit(); //SUPPORTED LANGUAGES ListLoader.getInstance().load_nom_supportedLanguages(); //REPORT SUBTOTAL INTERVAL ListLoader.getInstance().load_nom_reportSubtotalInterval(); //REPORT SUBTOTAL INTERVAL ListLoader.getInstance().load_nom_pricesComputeType(); //REPORT PARAMS MAP TSContext.storeOnContext(IConstant.REPORT_PARAM_MAP, new HashMap<String, ReportParams>()); RoleVoter rv = (RoleVoter) TSContext.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.BACK_CONSTANT, BackConstant.getInstance()); logger.info("Role Prefix: \"" + rv.getRolePrefix() + "\""); logger.info("*******************************************************"); logger.info("* *"); logger.info("* INITIATING APPLICATION END TIME SHEET<- *"); 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:net.naijatek.myalumni.modules.common.presentation.action.SecurityAction.java
/** * Performs the logging out of users// w ww . j a v a 2 s.c o m * * @param mapping ActionMapping * @param form ActionForm * @param request HttpServletRequest * @param response HttpServletResponse * @throws Exception * @return ActionForward */ public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(true); int sessionTimeout = setupSessionTimeout(session); MemberVO token = getCurrentLoggedInUser(request); if (token != null) { OnlineUserManager manager = OnlineUserManager.getInstance(); manager.removeOnlineUser(token.getMemberUserName()); ServletContext sCtx = request.getSession().getServletContext(); sCtx.setAttribute("onlineusers", manager.getOnlineUsers(sessionTimeout)); } if (session != null) { session.removeAttribute(BaseConstants.USER_CONTAINER); logger.info("User successfully logged out..."); session.invalidate(); } return (mapping.findForward(BaseConstants.FWD_SUCCESS)); }
From source file:org.wso2.carbon.ui.internal.CarbonUIServiceComponent.java
public void start(BundleContext context) throws Exception { this.bundleContext = context; ServerConfigurationService serverConfig = getServerConfiguration(); boolean isLocalTransportMode = checkForLocalTransportMode(serverConfig); //TODO set a system property ConfigurationContext clientConfigContext = getConfigurationContextService().getClientConfigContext(); //This is applicable only when the FE and BE runs in the same JVM. ConfigurationContext serverConfigContext = getConfigurationContextService().getServerConfigContext(); CarbonUIDefinitions carbonUIDefinitions = new CarbonUIDefinitions(); context.registerService(CarbonUIDefinitions.class.getName(), carbonUIDefinitions, null); // create a CustomUIDefinitions object and set it as a osgi service. UIBundleDeployer can access this // service and populate it with custom UI definitions of the deployed UI bundle, if available. CustomUIDefenitions customUIDefenitions = new CustomUIDefenitions(); context.registerService(CustomUIDefenitions.class.getName(), customUIDefenitions, null); Hashtable<String, String[]> properties1 = new Hashtable<String, String[]>(); properties1.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] { "carbon" }); context.registerService(URLStreamHandlerService.class.getName(), new CarbonProtocol(context), properties1); Hashtable<String, String[]> properties3 = new Hashtable<String, String[]>(); properties3.put(URLConstants.URL_CONTENT_MIMETYPE, new String[] { "text/javascript" }); context.registerService(ContentHandler.class.getName(), new TextJavascriptHandler(), properties3); final HttpService httpService = getHttpService(); Dictionary<String, String> initparams = new Hashtable<String, String>(); initparams.put("servlet-name", "TilesServlet"); initparams.put("definitions-config", "/WEB-INF/tiles/main_defs.xml"); initparams.put("org.apache.tiles.context.TilesContextFactory", "org.apache.tiles.context.enhanced.EnhancedContextFactory"); initparams.put("org.apache.tiles.factory.TilesContainerFactory.MUTABLE", "true"); initparams.put("org.apache.tiles.definition.DefinitionsFactory", "org.wso2.carbon.tiles.CarbonUrlDefinitionsFactory"); String webContext = "carbon"; // The subcontext for the Carbon Mgt Console String serverURL = CarbonUIUtil.getServerURL(serverConfig); String indexPageURL = CarbonUIUtil.getIndexPageURL(serverConfig); if (indexPageURL == null) { indexPageURL = "/carbon/admin/index.jsp"; }//from w w w. j ava2 s. c om RegistryService registryService = getRegistryService(); Registry registry = registryService.getLocalRepository(); UIBundleDeployer uiBundleDeployer = new UIBundleDeployer(); UIResourceRegistry uiResourceRegistry = new UIResourceRegistry(); uiResourceRegistry.initialize(bundleContext); uiResourceRegistry.setDefaultUIResourceProvider(uiBundleDeployer.getBundleBasedUIResourcePrvider()); // BundleResourcePathRegistry resourcePathRegistry = uiBundleDeployer.getBundleResourcePathRegistry(); HttpContext commonContext = new CarbonSecuredHttpContext(context.getBundle(), "/web", uiResourceRegistry, registry); //Registering filedownload servlet Servlet fileDownloadServlet = new ContextPathServletAdaptor( new FileDownloadServlet(context, getConfigurationContextService()), "/filedownload"); httpService.registerServlet("/filedownload", fileDownloadServlet, null, commonContext); fileDownloadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.SERVER_URL, serverURL); fileDownloadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.INDEX_PAGE_URL, indexPageURL); //Registering fileupload servlet Servlet fileUploadServlet; if (isLocalTransportMode) { fileUploadServlet = new ContextPathServletAdaptor( new FileUploadServlet(context, serverConfigContext, webContext), "/fileupload"); } else { fileUploadServlet = new ContextPathServletAdaptor( new FileUploadServlet(context, clientConfigContext, webContext), "/fileupload"); } httpService.registerServlet("/fileupload", fileUploadServlet, null, commonContext); fileUploadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.SERVER_URL, serverURL); fileUploadServlet.getServletConfig().getServletContext().setAttribute(CarbonConstants.INDEX_PAGE_URL, indexPageURL); uiBundleDeployer.deploy(bundleContext, commonContext); context.addBundleListener(uiBundleDeployer); httpService.registerServlet("/", new org.apache.tiles.web.startup.TilesServlet(), initparams, commonContext); httpService.registerResources("/" + webContext, "/", commonContext); adaptedJspServlet = new ContextPathServletAdaptor( new TilesJspServlet(context.getBundle(), uiResourceRegistry), "/" + webContext); httpService.registerServlet("/" + webContext + "/*.jsp", adaptedJspServlet, null, commonContext); ServletContext jspServletContext = adaptedJspServlet.getServletConfig().getServletContext(); jspServletContext.setAttribute("registry", registryService); jspServletContext.setAttribute(CarbonConstants.SERVER_CONFIGURATION, serverConfig); jspServletContext.setAttribute(CarbonConstants.CLIENT_CONFIGURATION_CONTEXT, clientConfigContext); //If the UI is running on local transport mode, then we use the server-side config context. if (isLocalTransportMode) { jspServletContext.setAttribute(CarbonConstants.CONFIGURATION_CONTEXT, serverConfigContext); } else { jspServletContext.setAttribute(CarbonConstants.CONFIGURATION_CONTEXT, clientConfigContext); } jspServletContext.setAttribute(CarbonConstants.BUNDLE_CLASS_LOADER, this.getClass().getClassLoader()); jspServletContext.setAttribute(CarbonConstants.SERVER_URL, serverURL); jspServletContext.setAttribute(CarbonConstants.INDEX_PAGE_URL, indexPageURL); jspServletContext.setAttribute(CarbonConstants.UI_BUNDLE_CONTEXT, bundleContext); // set the CustomUIDefinitions object as an attribute of servlet context, so that the Registry UI bundle // can access the custom UI details within JSPs. jspServletContext.setAttribute(CustomUIDefenitions.CUSTOM_UI_DEFENITIONS, customUIDefenitions); // Registering jspServletContext as a service so that UI components can use it bundleContext.registerService(ServletContext.class.getName(), jspServletContext, null); //saving bundle context for future reference within CarbonUI Generation CarbonUIUtil.setBundleContext(context); UIAnnouncementDeployer.deployNotificationSources(); if (log.isDebugEnabled()) { log.debug("Starting web console using context : " + webContext); } //read product.xml readProductXML(jspServletContext, uiBundleDeployer); }
From source file:org.mule.config.builders.MuleXmlBuilderContextListener.java
public void initialize(ServletContext context) { String config = context.getInitParameter(INIT_PARAMETER_MULE_CONFIG); if (config == null) { config = getDefaultConfigResource(); if (logger.isDebugEnabled()) { logger.debug("No Mule config file(s) specified, using default: " + config); }/*from ww w . j a v a2 s .co m*/ } else { if (logger.isDebugEnabled()) { logger.debug("Mule config file(s): " + config); } } try { muleContext = createMuleContext(config, context); context.setAttribute(MuleProperties.MULE_CONTEXT_PROPERTY, muleContext); muleContext.start(); } catch (MuleException ex) { context.log(ex.getMessage(), ex); // Logging is not configured OOTB for Tomcat, so we'd better make a // start-up failure plain to see. ex.printStackTrace(); } catch (Error error) { // WSAD doesn't always report the java.lang.Error, log it context.log(error.getMessage(), error); // Logging is not configured OOTB for Tomcat, so we'd better make a // start-up failure plain to see. error.printStackTrace(); throw error; } }
From source file:br.com.caelum.vraptor.ioc.spring.DefaultSpringLocator.java
public ConfigurableWebApplicationContext getApplicationContext(ServletContext servletContext) { ConfigurableWebApplicationContext context = (ConfigurableWebApplicationContext) WebApplicationContextUtils .getWebApplicationContext(servletContext); if (context != null) { logger.info("Using a web application context: {}", context); return context; }/*from ww w .jav a 2 s .c o m*/ if (DefaultSpringLocator.class.getResource("/applicationContext.xml") != null) { logger.info("Using an XmlWebApplicationContext, searching for applicationContext.xml"); XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocation("classpath:applicationContext.xml"); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); return ctx; } logger.info("No application context found"); ConfigurableWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setId("VRaptor"); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); return ctx; }
From source file:org.apache.asterix.api.http.servlet.RESTAPIServlet.java
public void handleRequest(HttpServletRequest request, HttpServletResponse response, String query) throws IOException { // enable cross-origin resource sharing response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); SessionConfig sessionConfig = initResponse(request, response); QueryTranslator.ResultDelivery resultDelivery = whichResultDelivery(request); ServletContext context = getServletContext(); IHyracksClientConnection hcc;//from w w w .j ava2 s . c o m 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); } } IParser parser = parserFactory.createParser(query); List<Statement> aqlStatements = parser.parse(); if (!containsForbiddenStatements(aqlStatements)) { MetadataManager.INSTANCE.init(); IStatementExecutor translator = statementExecutorFactory.create(aqlStatements, sessionConfig, compilationProvider); translator.compileAndExecute(hcc, hds, resultDelivery); } } catch (AsterixException | TokenMgrError | org.apache.asterix.aqlplus.parser.TokenMgrError pe) { GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe); String errorMessage = ResultUtil.buildParseExceptionMessage(pe, query); JSONObject errorResp = ResultUtil.getErrorResponse(2, errorMessage, "", ResultUtil.extractFullStackTrace(pe)); sessionConfig.out().write(errorResp.toString()); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (Exception e) { GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e); ResultUtil.apiErrorHandler(sessionConfig.out(), e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.openkm.servlet.admin.DbRepositoryViewServlet.java
private void list(String uuid, String path, HttpServletRequest request, HttpServletResponse response) throws RepositoryException, PathNotFoundException, DatabaseException, ServletException, IOException, ParseException {/*from w ww . j ava 2 s. com*/ log.debug("list({}, {})", new Object[] { request, response }); String stats = WebUtils.getString(request, "stats"); ContentInfo ci = null; if (uuid == null || uuid.isEmpty()) { path = "/" + Repository.ROOT; uuid = NodeBaseDAO.getInstance().getUuidFromPath(path); } // Respository stats calculation if (!stats.equals("")) { if (stats.equals("0")) { request.getSession().removeAttribute("stats"); } else { request.getSession().setAttribute("stats", true); } } /* * if (request.getSession().getAttribute("stats") != null && node.isNodeType(Folder.TYPE)) { * try { * ci = OKMFolder.getInstance().getContentInfo(null, path); * } catch (AccessDeniedException e) { * log.warn(e.getMessage(), e); * } catch (com.openkm.core.RepositoryException e) { * log.warn(e.getMessage(), e); * } catch (PathNotFoundException e) { * log.warn(e.getMessage(), e); * } catch (DatabaseException e) { * log.warn(e.getMessage(), e); * } * } */ // Activity log UserActivity.log(PrincipalUtils.getUser(), "ADMIN_REPOSITORY_LIST", uuid, path, null); ServletContext sc = getServletContext(); if (!Config.ROOT_NODE_UUID.equals(uuid)) { NodeBase node = NodeBaseDAO.getInstance().findByPk(uuid); sc.setAttribute("node", node); sc.setAttribute("nodeType", getNodeType(node)); sc.setAttribute("properties", getProperties(uuid)); sc.setAttribute("contentInfo", ci); sc.setAttribute("depth", PathUtils.getDepth(path)); if (node instanceof NodeDocument) { sc.setAttribute("locked", ((NodeDocument) node).isLocked()); sc.setAttribute("history", NodeDocumentVersionDAO.getInstance().findByParent(uuid)); sc.setAttribute("text", ((NodeDocument) node).getText()); sc.setAttribute("textExtracted", ((NodeDocument) node).isTextExtracted()); sc.setAttribute("mimeType", ((NodeDocument) node).getMimeType()); } } else { sc.setAttribute("depth", 0); } sc.setAttribute("breadcrumb", createBreadcrumb(path)); sc.setAttribute("children", getChildren(uuid)); sc.getRequestDispatcher("/admin/db_repository_list.jsp").forward(request, response); log.debug("list: void"); }
From source file:ume.pareva.it.servlets.TerminateBulkIT.java
private boolean isStopSpecial() { ServletContext application = getServletConfig().getServletContext(); int countingStop = 0; int numberOfSpecial = 3; String ipxCountingStopName = "ipxCountingStopBulk"; Integer countingStopped = (Integer) application.getAttribute(ipxCountingStopName); if (countingStopped == null) { countingStopped = 0;//from w ww .j a v a2 s .c om } else { countingStopped++; } application.setAttribute(ipxCountingStopName, countingStopped); countingStop = countingStopped; if (countingStop >= numberOfSpecial && (countingStop % numberOfSpecial) == 0) { return true; } else { return false; } }