List of usage examples for javax.servlet ServletContext getAttributeNames
public Enumeration<String> getAttributeNames();
Enumeration
containing the attribute names available within this ServletContext. From source file:org.debux.webmotion.server.render.RenderException.java
protected Map<String, Object> getServletContextAttributes(ServletContext servletContext) { Map<String, Object> result = new HashMap<String, Object>(); for (Enumeration<String> names = servletContext.getAttributeNames(); names.hasMoreElements();) { String name = names.nextElement(); Object value = servletContext.getAttribute(name); result.put(name, value);/*from w w w .j a v a 2 s . c o m*/ } return result; }
From source file:com.mtgi.analytics.servlet.BehaviorTrackingListener.java
private synchronized void checkInit(ServletRequestEvent event) { if (!initialized) { ServletContext context = event.getServletContext(); boolean hasFilter = BehaviorTrackingFilter.isFiltered(context); ArrayList<ServletRequestBehaviorTrackingAdapter> beans = new ArrayList<ServletRequestBehaviorTrackingAdapter>(); //find registered request adapters in all mvc servlet contexts. for (Enumeration<?> atts = context.getAttributeNames(); atts.hasMoreElements();) { String name = (String) atts.nextElement(); if (name.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) { Object value = context.getAttribute(name); if (value instanceof ListableBeanFactory) addRequestAdapters(beans, (ListableBeanFactory) value, hasFilter); }//w ww . j a v a2 s . c o m } //look for shared application context, loaded by ContextLoaderListener. ListableBeanFactory parent = WebApplicationContextUtils.getWebApplicationContext(context); if (parent != null) addRequestAdapters(beans, parent, hasFilter); if (!beans.isEmpty()) { adapters = beans.toArray(new ServletRequestBehaviorTrackingAdapter[beans.size()]); log.info("BehaviorTracking for HTTP servlet requests started"); } initialized = true; } }
From source file:com.adito.boot.Util.java
/** * Dump all servlet context attributes to {@link System#err}. * //from ww w . j a va 2 s .c o m * @param context context to get attributes from */ public static void dumpServletContextAttributes(ServletContext context) { System.err.println("Servlet context attributes for"); for (Enumeration e = context.getAttributeNames(); e.hasMoreElements();) { String n = (String) e.nextElement(); System.err.println(" " + n + " = " + context.getAttribute(n)); } }
From source file:ServerSnoop.java
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); ServletContext context = getServletContext(); out.println("req.getServerName(): " + req.getServerName()); out.println("req.getServerPort(): " + req.getServerPort()); out.println("context.getServerInfo(): " + context.getServerInfo()); out.println("getServerInfo() name: " + getServerInfoName(context.getServerInfo())); out.println("getServerInfo() version: " + getServerInfoVersion(context.getServerInfo())); out.println("context.getAttributeNames():"); Enumeration e = context.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(" context.getAttribute(\"" + name + "\"): " + context.getAttribute(name)); }//w w w . j a va2 s.c o m }
From source file:org.apache.ofbiz.base.util.UtilHttp.java
/** * Create a map from a ServletContext object * @return The resulting Map//from w w w .ja v a 2 s. c o m */ public static Map<String, Object> getServletContextMap(HttpServletRequest request, Set<? extends String> namesToSkip) { Map<String, Object> servletCtxMap = new HashMap<String, Object>(); // look at all servlet context attributes ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); Enumeration<String> applicationAttrNames = UtilGenerics.cast(servletContext.getAttributeNames()); while (applicationAttrNames.hasMoreElements()) { String attrName = applicationAttrNames.nextElement(); if (namesToSkip != null && namesToSkip.contains(attrName)) continue; Object attrValue = servletContext.getAttribute(attrName); servletCtxMap.put(attrName, attrValue); } if (Debug.verboseOn()) { Debug.logVerbose("Made ServletContext Attribute Map with [" + servletCtxMap.size() + "] Entries", module); Debug.logVerbose("ServletContext Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(servletCtxMap), module); } return servletCtxMap; }
From source file:org.sindice.core.analytics.commons.webapps.SparqledContextListener.java
private void configureLogging(ServletContext context, final File configFolder) { final InputStream in = openLoggingConfig(configFolder); if (in == null) { throw new RuntimeException("Missing " + configFolder); }/*from w ww .j av a 2 s . c o m*/ try { final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); try { final Enumeration<String> attributeNames = context.getAttributeNames(); while (attributeNames.hasMoreElements()) { String key = attributeNames.nextElement(); Object value = context.getAttribute(key); if (value != null) { configurator.getContext().putProperty(key, value.toString()); } } configurator.doConfigure(in); } catch (JoranException e) { throw new RuntimeException("logging configuration failed", e); } StatusPrinter.printInCaseOfErrorsOrWarnings(lc); } finally { try { in.close(); } catch (IOException e) { logger.warn("problem closing stream", e); } } }
From source file:org.hdiv.config.multipart.SpringMVCMultipartConfig.java
/** * Obtain MultipartResolver instance for this application. * /* w w w.j av a 2 s .c o m*/ * @param servletContext * app ServletContext * @return MultipartResolver instance */ @SuppressWarnings("rawtypes") protected MultipartResolver lookupMultipartResolver(ServletContext servletContext) { MultipartResolver resolver = null; if (this.webApplicationContext == null) { this.webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); } try { resolver = this.webApplicationContext.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class); if (resolver != null) { return resolver; } } catch (NoSuchBeanDefinitionException ex) { // No MultipartResolver in this context. } if (resolver == null) { Enumeration e = servletContext.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if (name.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) { this.webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext, name); break; } } } if (this.webApplicationContext != null) { try { resolver = this.webApplicationContext.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class); } catch (NoSuchBeanDefinitionException ex) { // No MultipartResolver in this context. } } if (log.isDebugEnabled() && resolver == null) { log.debug("Cant find MultipartResolver on any context."); } return resolver; }
From source file:org.sindice.analytics.servlet.ServletConfigurationContextListener.java
private void configureLogging(ServletContext context, final File configFolder) { InputStream in = openLoggingConfig(configFolder); if (in == null) { setDefaultLogging();/*from w w w . j av a 2 s . co m*/ return; } try { final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); try { Enumeration<String> attributeNames = context.getAttributeNames(); while (attributeNames.hasMoreElements()) { String key = attributeNames.nextElement(); Object value = context.getAttribute(key); if (value != null) { configurator.getContext().putProperty(key, value.toString()); } } configurator.doConfigure(in); } catch (JoranException e) { lc.reset(); setDefaultLogging(); logger.error("logging configuration failed", e); logger.warn("using servlet container logging configuration"); } StatusPrinter.printInCaseOfErrorsOrWarnings(lc); } finally { try { in.close(); } catch (IOException e) { logger.warn("problem closing stream", e); } } }
From source file:org.getobjects.servlets.WOServletAdaptor.java
@Override public void init(final ServletConfig _cfg) throws ServletException { // Jetty: org.mortbay.jetty.servlet.ServletHolder$Config@114024 super.init(_cfg); String an = this.valueFromServletConfig(_cfg, "WOAppName"); String ac = this.valueFromServletConfig(_cfg, "WOAppClass"); if (ac == null) ac = an;/*from w w w.j ava 2 s . c om*/ if (an == null && ac != null) { /* if only the class is set, we use the shortname of the class */ int dotidx = ac.lastIndexOf('.'); an = dotidx < 1 ? ac : ac.substring(dotidx + 1); } if (an == null) { log.warn("no WOAppName specified in servlet context: " + _cfg); an = WOApplication.class.getName(); } /* Construct properties for the volatile "domain" from servlet init * parameters and context init parameters and attributes. * It's probably best to have a real UserDefaults concept, but for the * time being this is better than nothing. */ final Properties properties = new Properties(); Enumeration parameterNamesEnum = _cfg.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); final String value = _cfg.getInitParameter(name); if (name != null && value != null) properties.put(name, value); else if (value == null) log.error("Got no value for init parameter: " + name); } /* The ServletContext may override the previous init parameters. * ServletContext init parameters will be overridden by attributes. */ final ServletContext sctx = _cfg.getServletContext(); if (sctx != null) { parameterNamesEnum = sctx.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); properties.put(name, sctx.getInitParameter(name)); } final Enumeration attributeNamesEnum = sctx.getAttributeNames(); while (attributeNamesEnum.hasMoreElements()) { final String name = (String) attributeNamesEnum.nextElement(); properties.put(name, sctx.getAttribute(name)); } } this.initApplicationWithName(an, ac, properties); }
From source file:org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext.java
public GenericWebAppContext(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, SessionProvider sessionProvider, ManageableRepository repository) { initialize(servletContext, request, response); this.sessionProvider = sessionProvider; this.repository = repository; // log.info("WEb context ---------------"); // initialize context with all props Enumeration en = servletContext.getInitParameterNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); put(name, servletContext.getInitParameter(name)); LOG.debug("ServletContext init param: " + name + "=" + servletContext.getInitParameter(name)); }/*from w w w.j av a 2 s .c o m*/ en = servletContext.getAttributeNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); put(name, servletContext.getAttribute(name)); LOG.debug("ServletContext: " + name + "=" + servletContext.getAttribute(name)); } HttpSession session = request.getSession(false); if (session != null) { en = session.getAttributeNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); put(name, session.getAttribute(name)); LOG.debug("Session: " + name + "=" + session.getAttribute(name)); } } en = request.getAttributeNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); put(name, request.getAttribute(name)); } en = request.getParameterNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); put(name, request.getParameter(name)); LOG.debug("Request: " + name + "=" + request.getParameter(name)); } }