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:org.intermine.web.logic.session.SessionMethods.java
/** * @param context a ServletContext/*from w w w. j av a 2 s . c o m*/ * @return WebConfig */ public static WebConfig getWebConfig(ServletContext context) { WebConfig wc = (WebConfig) context.getAttribute(Constants.WEBCONFIG); if (wc == null) { throw new RuntimeException("WebConfig not present in web session."); } return wc; }
From source file:br.com.argonavis.jaspictut.service.FacebookConnectService.java
@Override public void init(ServletContext ctx) { Properties authconfig = (Properties) ctx.getAttribute("authconfig"); facebookAppID = authconfig.getProperty("facebookAppID"); facebookAppSecret = authconfig.getProperty("facebookAppSecret"); }
From source file:com.cimait.invoicec.portal.util.servlet.SBServletInitializer.java
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { ApplicationContext parent = null;// w w w .j a v a 2 s .c o 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:cn.vlabs.umt.ui.UMTStartupListener.java
public void contextDestroyed(ServletContextEvent event) { ServletContext context = event.getServletContext(); FileSystemXmlApplicationContext factory = (FileSystemXmlApplicationContext) context .getAttribute(Attributes.APPLICATION_CONTEXT_KEY); if (factory != null) { context.removeAttribute(Attributes.APPLICATION_CONTEXT_KEY); factory.close();/*from ww w. j a va2s . co m*/ factory = null; } }
From source file:org.apache.hadoop.hdfs.server.namenode.CancelDelegationTokenServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final UserGroupInformation ugi; final ServletContext context = getServletContext(); final Configuration conf = (Configuration) context.getAttribute(JspHelper.CURRENT_CONF); try {//from www.j a va2s . c om ugi = getUGI(req, conf); } catch (IOException ioe) { LOG.info("Request for token received with no authentication from " + req.getRemoteAddr(), ioe); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Unable to identify or authenticate user"); return; } final NameNode nn = (NameNode) context.getAttribute("name.node"); String tokenString = req.getParameter(TOKEN); if (tokenString == null) { resp.sendError(HttpServletResponse.SC_MULTIPLE_CHOICES, "Token to renew not specified"); } final Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(); token.decodeFromUrlString(tokenString); try { ugi.doAs(new PrivilegedExceptionAction<Void>() { public Void run() throws Exception { nn.cancelDelegationToken(token); return null; } }); } catch (Exception e) { LOG.info("Exception while cancelling token. Re-throwing. ", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
From source file:org.intermine.web.logic.session.SessionMethods.java
/** * Returns the Map of aspects./*ww w .j a v a 2s .co m*/ * * @param servletContext a ServletContext object * @return a Map */ public static Map<String, Aspect> getAspects(ServletContext servletContext) { return (Map<String, Aspect>) servletContext.getAttribute(Constants.ASPECTS); }
From source file:org.red5.server.tomcat.TomcatApplicationContext.java
public void stop() { log.debug("stop"); try {//from w w w . j ava 2 s .c o m ServletContext servlet = context.getServletContext(); Object o = servlet.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (o != null) { log.debug("Spring context for {} was found", context.getName()); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) o; //close the red5 app if (appCtx.isRunning()) { log.debug("Context was running, attempting to stop"); appCtx.stop(); } if (appCtx.isActive()) { log.debug("Context is active, attempting to close"); appCtx.close(); } } else { log.warn("Spring context for {} was not found", context.getName()); } } catch (Exception e) { log.error("Could not stop spring context", e); } context.getParent().removeChild(context); if (context instanceof StandardContext) { StandardContext ctx = (StandardContext) context; try { //stop the tomcat context ctx.stop(); } catch (Exception e) { log.error("Could not stop context", e); } finally { try { ctx.destroy(); } catch (Exception e) { log.error("Could not destroy context", e); } } } }
From source file:com.concursive.connect.config.ApplicationPrefs.java
public static Configuration getFreemarkerConfiguration(ServletContext context) { return (Configuration) context.getAttribute(Constants.FREEMARKER_CONFIGURATION); }
From source file:com.concursive.connect.config.ApplicationPrefs.java
public static ApplicationPrefs getApplicationPrefs(ServletContext context) { return (ApplicationPrefs) context.getAttribute(Constants.APPLICATION_PREFS); }
From source file:org.apache.hadoop.hdfs.server.namenode.DelegationTokenServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final UserGroupInformation ugi; try {/* w w w . j av a 2 s . c o m*/ ugi = getUGI(req, new Configuration()); } catch (IOException ioe) { LOG.info("Request for token received with no authentication from " + req.getRemoteAddr(), ioe); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Unable to identify or authenticate user"); return; } LOG.info("Sending token: {" + ugi.getUserName() + "," + req.getRemoteAddr() + "}"); final ServletContext context = getServletContext(); final NameNode nn = (NameNode) context.getAttribute("name.node"); DataOutputStream dos = null; try { dos = new DataOutputStream(resp.getOutputStream()); final DataOutputStream dosFinal = dos; // for doAs block ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { Token<DelegationTokenIdentifier> token = nn .getDelegationToken(new Text(req.getUserPrincipal().getName())); String s = nn.rpcAddress.getAddress().getHostAddress() + ":" + nn.rpcAddress.getPort(); token.setService(new Text(s)); TokenStorage ts = new TokenStorage(); ts.addToken(new Text(ugi.getShortUserName()), token); ts.write(dosFinal); dosFinal.close(); return null; } }); } catch (Exception e) { LOG.info("Exception while sending token. Re-throwing. ", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { if (dos != null) dos.close(); } }