List of usage examples for javax.servlet ServletContext getAttribute
public Object getAttribute(String name);
null
if there is no attribute by that name. From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java
/** * testInitResources06()/*w w w . ja v a 2 s.c o m*/ * <br><br> * * (??n) * <br> * _?FA * <br><br> * l?F(?) servlet:not null<br> * (?) config:W?[(?)="/test2"<br> * (?) this.resourcePath:"ResetterPlugInTest-reset.xml"<br> * (?) digesterRules:"ResetterPlugInTest-reset-rules.xml"<br> * (?) ServletContext#getResource():?|<br> * * <br> * l?F(?) RESETTER_RESOURCES:T?[ubgReLXg"RESETTER_RESOURCES/test2"L?[ResetterResourcesCX^Xi[?B<br> * (?) digesterRules:?|<br> * (?) O:?|<br> * (?) ?O:?|<br> * * <br> * W?[O?AT?[ubgReLXgo^L?[?AW?[mF?B * <br> * * @throws Exception ?\bh?O */ public void testInitResources06() throws Exception { // W?[?? ModuleConfig conf = new ModuleConfigImpl("/test2"); // reset.xmlpX? UTUtil.setPrivateField(plugin, "resourcesPath", RESET_FILE_NAME); // reset-rules.xmlpX? UTUtil.setPrivateField(plugin, "digesterRules", RESET_RULES_FILE_NAME); // ANVT?[ubg?? ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01(); // eXg?s plugin.initResources(servlet, conf); // mF // T?[ubgReLXg ServletContext ctx = servlet.getServletContext(); assertEquals("jp.terasoluna.fw.web.struts.reset.ResetterResources", ((ResetterResources) ctx.getAttribute("RESETTER_RESOURCES/test2")).getClass().getName()); }
From source file:com.tremolosecurity.proxy.auth.SAML2Auth.java
@Override public void init(ServletContext ctx, HashMap<String, Attribute> init) { this.cfgMgr = (ConfigManager) ctx.getAttribute(ProxyConstants.TREMOLO_CONFIG); try {//from w w w. jav a 2s . c o m InitializationService.initialize(); } catch (InitializationException e1) { logger.warn("Could not initialize opensaml", e1); } try { this.random = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { logger.error("could not load secure random"); } this.defaultRelayStates = new HashMap<String, String>(); if (init.containsKey("defaultRelayStates")) { for (String map : init.get("defaultRelayStates").getValues()) { String referer = map.substring(0, map.indexOf('|')); String relaystate = map.substring(map.indexOf('|') + 1); logger.info("Default Relay State - '" + referer + "' --> '" + relaystate + "'"); this.defaultRelayStates.put(referer, relaystate); } } }
From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java
/** * testInitResetter04()/* w ww . j a va 2s. c o m*/ * <br><br> * * (??n) * <br> * _?FA * <br><br> * l?F(?) servlet:not null<br> * (?) config:W?[(?)=""<br> * (?) this.resetter:ResetterPlugIn_ResetterStub01?i?NX?j<br> * * <br> * l?F(?) RESETTER:T?[ubgReLXg"RESETTER"L?[ResetterPlugIn_ResetterStub01CX^Xi[?B<br> * (?) O:?|<br> * (?) ?O:?|<br> * * <br> * this.resetter?NX?A??resetterT?[ubgReLXgmF?B * <br> * * @throws Exception ?\bh?O */ public void testInitResetter04() throws Exception { // W?[?? ModuleConfig conf = new ModuleConfigImpl(""); // Zb^?[NXS?C?NX? UTUtil.setPrivateField(plugin, "resetter", "jp.terasoluna.fw.web.struts.plugins." + "ResetterPlugIn_ResetterStub01"); // ANVT?[ubg?? ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01(); // eXg?s plugin.initResetter(servlet, conf); // mF // T?[ubgReLXg ServletContext ctx = servlet.getServletContext(); assertEquals("jp.terasoluna.fw.web.struts.plugins.ResetterPlugIn_ResetterStub01", ((ResetterImpl) ctx.getAttribute("RESETTER")).getClass().getName()); }
From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java
/** * testInitResetter05()/*from w ww .ja v a 2 s. com*/ * <br><br> * * (??n) * <br> * _?FA * <br><br> * l?F(?) servlet:not null<br> * (?) config:W?[(?)="test1"<br> * (?) this.resetter:ResetterPlugIn_ResetterStub01?i?NX?j<br> * * <br> * l?F(?) RESETTER:T?[ubgReLXg"RESETTER/test1"L?[ResetterPlugIn_ResetterStub01CX^Xi[?B<br> * (?) O:?|<br> * (?) ?O:?|<br> * * <br> * W?[O?AT?[ubgReLXgo^L?[?AW?[mF?B * <br> * * @throws Exception ?\bh?O */ public void testInitResetter05() throws Exception { // W?[?? ModuleConfig conf = new ModuleConfigImpl("/test1"); // Zb^?[NXS?C?NX? UTUtil.setPrivateField(plugin, "resetter", "jp.terasoluna.fw.web.struts.plugins." + "ResetterPlugIn_ResetterStub01"); // ANVT?[ubg?? ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01(); // eXg?s plugin.initResetter(servlet, conf); // mF // T?[ubgReLXg ServletContext ctx = servlet.getServletContext(); assertEquals("jp.terasoluna.fw.web.struts.plugins.ResetterPlugIn_ResetterStub01", ((ResetterImpl) ctx.getAttribute("RESETTER/test1")).getClass().getName()); }
From source file:com.concursive.connect.config.ApplicationPrefs.java
/** * Description of the Method//from ww w . j a va2s . co m * * @param context Description of the Parameter */ public void configureWorkflowManager(ServletContext context) { // Load the defaults ObjectHookManager hookManager = (ObjectHookManager) context.getAttribute(Constants.OBJECT_HOOK_MANAGER); if (hookManager != null) { // Configure a few settings hookManager.setFileLibraryPath(this.get(FILE_LIBRARY_PATH)); hookManager.setApplicationPrefs(this.getPrefs()); if (ApplicationPrefs.getFreemarkerConfiguration(context) == null) { LOG.error("Free marker configuration is null"); } hookManager.setFreemarkerConfiguration(ApplicationPrefs.getFreemarkerConfiguration(context)); hookManager.setKey((Key) context.getAttribute(TEAM_KEY)); Scheduler scheduler = (Scheduler) context.getAttribute(Constants.SCHEDULER); hookManager.setScheduler(scheduler); try { // Configure a separate connection pool ConnectionPool commonCP = (ConnectionPool) context.getAttribute(Constants.CONNECTION_POOL); if (commonCP != null) { if (!this.has(CONNECTION_POOL_MAX_WORKFLOW_CONNECTIONS)) { hookManager.setConnectionPool( (ConnectionPool) context.getAttribute(Constants.CONNECTION_POOL)); } else { ConnectionPool workflowCP = new ConnectionPool(); workflowCP.setDebug(commonCP.getDebug()); workflowCP.setTestConnections(commonCP.getTestConnections()); workflowCP.setAllowShrinking(commonCP.getAllowShrinking()); workflowCP.setMaxConnections(this.get(CONNECTION_POOL_MAX_WORKFLOW_CONNECTIONS)); workflowCP.setMaxIdleTime(commonCP.getMaxIdleTime()); workflowCP.setMaxDeadTime(commonCP.getMaxDeadTime()); hookManager.setConnectionPool(workflowCP); } } ConnectionElement ce = new ConnectionElement(); ce.setDriver(this.get(CONNECTION_DRIVER)); ce.setUrl(this.get(CONNECTION_URL)); ce.setUsername(this.get(CONNECTION_USER)); ce.setPassword(this.get(CONNECTION_PASSWORD)); hookManager.setConnectionElement(ce); WorkflowUtils.addWorkflow(hookManager, context); } catch (Exception e) { e.printStackTrace(System.out); LOG.error("Workflow Error: " + e.getMessage(), e); } } }
From source file:jp.terasoluna.fw.web.struts.plugins.ResetterPlugInTest.java
/** * testInit01()//from ww w. j a v a 2s .c o m * <br><br> * * (??n) * <br> * _?FA * <br><br> * l?F(?) servlet:not null<br> * (?) config:W?[(?)=""<br> * (?) this.resetter:ResetterPlugIn_ResetterStub01?i?NX?j<br> * (?) this.resourcePath:"ResetterPlugInTest-reset.xml"?i?t@C?j<br> * * <br> * l?F(?) RESETTER_RESOURCES:T?[ubgReLXg"RESETTER_RESOURCES"L?[ResetterResourcesCX^Xi[?B<br> * (?) RESETTER:T?[ubgReLXg"RESETTER"L?[ResetterPlugIn_ResetterStub01CX^Xi[?B<br> * * <br> * ??????smF?B * <br> * * @throws Exception ?\bh?O */ public void testInit01() throws Exception { // W?[?? ModuleConfig conf = new ModuleConfigImpl(""); // Zb^?[NXS?C?NX? UTUtil.setPrivateField(plugin, "resetter", "jp.terasoluna.fw.web.struts.plugins." + "ResetterPlugIn_ResetterStub01"); // Zb^?[NXS?C?NX? UTUtil.setPrivateField(plugin, "resourcesPath", RESET_FILE_NAME); // ANVT?[ubg?? ResetterPlugIn_ActionServletStub01 servlet = new ResetterPlugIn_ActionServletStub01(); // Zbg?[w UTUtil.setPrivateField(plugin, "digesterRules", RESET_RULES_FILE_NAME); // eXg?s plugin.init(servlet, conf); // mF // T?[ubgReLXg ServletContext ctx = servlet.getServletContext(); assertEquals("jp.terasoluna.fw.web.struts.plugins.ResetterPlugIn_ResetterStub01", ((ResetterImpl) ctx.getAttribute("RESETTER")).getClass().getName()); assertEquals("jp.terasoluna.fw.web.struts.reset.ResetterResources", ((ResetterResources) ctx.getAttribute("RESETTER_RESOURCES")).getClass().getName()); }
From source file:org.apache.velocity.tools.view.UiDependencyTool.java
public void configure(Map params) { ServletContext app = (ServletContext) params.get(ViewContext.SERVLET_CONTEXT_KEY); LOG = (Log) params.get(ToolContext.LOG_KEY); HttpServletRequest request = (HttpServletRequest) params.get(ViewContext.REQUEST); context = request.getContextPath();//from w w w . jav a2s.com String file = (String) params.get(SOURCE_FILE_KEY); if (file == null) { file = DEFAULT_SOURCE_FILE; } else { debug("Loading file: %s", file); } synchronized (app) { // first, see if we've already read this file groups = (Map<String, Group>) app.getAttribute(GROUPS_KEY_SPACE + file); if (groups == null) { groups = new LinkedHashMap<String, Group>(); // only require file presence, if one is specified read(file, (file != DEFAULT_SOURCE_FILE)); app.setAttribute(GROUPS_KEY_SPACE + file, groups); if (types != DEFAULT_TYPES) { app.setAttribute(TYPES_KEY_SPACE + file, types); } } else { // load any custom types too List<Type> alt = (List<Type>) app.getAttribute(TYPES_KEY_SPACE + file); if (alt != null) { types = alt; } } } }
From source file:com.tremolosecurity.proxy.SessionManagerImpl.java
private HttpSession locateSession(UrlHolder holder, HttpServletRequest request, ServletContext ctx, String cookieName, HttpServletResponse resp) throws Exception { Cookie sessionCookie = null;// w w w . j a va2 s .c om Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equalsIgnoreCase(cookieName)) { sessionCookie = cookie; break; } } } ConfigManager cfg = (ConfigManager) ctx.getAttribute(ProxyConstants.TREMOLO_CONFIG); ApplicationType app; if (holder != null) { app = holder.getApp(); } else { app = null; String appName = null; if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals("autoIdmAppName")) { appName = URLDecoder.decode(cookies[i].getValue(), "UTF-8"); break; } } } if (appName == null) { // TODO create open session if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName() .equals(cfg.getCfg().getApplications().getOpenSessionCookieName())) { String sessionID = cookies[i].getValue(); TremoloHttpSession tsession = this.sessions.get(sessionID); // TODO add timeouts if (tsession == null) { return this.createOpenSession(request, resp, ctx); } else { return tsession; } } } } return createOpenSession(request, resp, ctx); } else { app = cfg.getApp(appName); if (app == null) { throw new Exception("No application named '" + appName + "' found"); } } } SecretKey encKey = cfg.getSecretKey(app.getCookieConfig().getKeyAlias()); // TremoloHttpSession tsession = (TremoloHttpSession) // request.getSession().getAttribute(app.getCookieConfig().getSessionCookieName()); if (sessionCookie == null) { // if (tsession != null) tsession.invalidate(); return createSession(app, request, resp, ctx, encKey); } else { HttpSession session = null; try { try { TremoloHttpSession tsession = findSessionFromCookie(sessionCookie, encKey, this); if (tsession == null) { return createSession(app, request, resp, ctx, encKey); } String fromSessionID = (String) tsession.getAttribute(OpenUnisonConstants.TREMOLO_SESSION_ID); if (app.getCookieConfig().getTimeout() > 0) { DateTime lastAccessed = (DateTime) tsession .getAttribute(SessionManagerImpl.TREMOLO_SESSION_LAST_ACCESSED); DateTime now = new DateTime(); if (now.minusSeconds(app.getCookieConfig().getTimeout()).isAfter(lastAccessed)) { tsession.invalidate(); return createSession(app, request, resp, ctx, encKey); } else { tsession.setAttribute(SessionManagerImpl.TREMOLO_SESSION_LAST_ACCESSED, now); session = tsession; } } else { session = tsession; } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Exception loading session", e); } return createSession(app, request, resp, ctx, encKey); } // this.sessions.put(session.getSessionID(), key); // } } catch (Exception e) { logger.error("Error generating session", e); } if (session == null) { // session.invalidate(); return createSession(app, request, resp, ctx, encKey); } // session.resetAccess(); return session; } }
From source file:com.ecyrd.jspwiki.WikiEngine.java
/** * Gets a WikiEngine related to the servlet. Works just like getInstance( ServletConfig ) * * @param context The ServletContext of the webapp servlet/JSP calling this method. * @param props A set of properties, or null, if we are to load JSPWiki's default * jspwiki.properties (this is the usual case). * * @return One fully functional, properly behaving WikiEngine. * @throws InternalWikiException If the WikiEngine instantiation fails. *//*from w ww . ja v a2 s . c om*/ // FIXME: Potential make-things-easier thingy here: no need to fetch the wikiengine anymore // Wiki.jsp.jspInit() [really old code]; it's probably even faster to fetch it // using this method every time than go to pageContext.getAttribute(). public static synchronized WikiEngine getInstance(ServletContext context, Properties props) throws InternalWikiException { WikiEngine engine = (WikiEngine) context.getAttribute(ATTR_WIKIENGINE); if (engine == null) { String appid = Integer.toString(context.hashCode()); //FIXME: Kludge, use real type. context.log(" Assigning new engine to " + appid); try { if (props == null) { props = PropertyReader.loadWebAppProps(context); } engine = new WikiEngine(context, appid, props); context.setAttribute(ATTR_WIKIENGINE, engine); } catch (Exception e) { context.log("ERROR: Failed to create a Wiki engine: " + e.getMessage()); throw new InternalWikiException("No wiki engine, check logs."); } } return engine; }
From source file:com.aurel.track.ApplicationStarter.java
private ApplicationBean initApplicationBeanStep1(ServletContext servletContext) { ApplicationBean applicationBean = ApplicationBean.getInstance(); setVersionFromVersionProperties(servletContext); applicationBean.setServletContext(servletContext); applicationBean.setExecutor(executor); actualizePercentComplete(0, ""); if (servletContext.getAttribute("INTEST") != null && (Boolean) servletContext.getAttribute("INTEST")) { applicationBean.setInTestMode(true); }//from w w w .j a va2s . com return applicationBean; }