Java Code Examples for javax.servlet.ServletContext#getAttributeNames()
The following examples show how to use
javax.servlet.ServletContext#getAttributeNames() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainServlet.java From Project with Apache License 2.0 | 6 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //从ServletContext对象中获取到Session信息 ServletContext servletContext = this.getServletContext(); //获取ServletContext域中所有的属性名 Enumeration<String> names = servletContext.getAttributeNames(); HttpSession session = req.getSession(false); String sessionName = "sessionID" + session.getId(); if (session != null) { while (names.hasMoreElements()) { String name = names.nextElement(); //System.out.println(name); if (name.equals(sessionName)) { HttpSession temp = (HttpSession) servletContext.getAttribute(name); System.out.println(temp.getAttribute("user")); } } } }
Example 2
Source File: SakaiContextLoaderListener.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check */ private static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { log.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
Example 3
Source File: ModelManagerListener.java From oryx with Apache License 2.0 | 6 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { log.info("ModelManagerListener destroying"); // Slightly paranoid; remove objects from app scope manually ServletContext context = sce.getServletContext(); for (Enumeration<String> names = context.getAttributeNames(); names.hasMoreElements();) { context.removeAttribute(names.nextElement()); } close(); // Hacky, but prevents Tomcat from complaining that ZK's cleanup thread 'leaked' since // it has a short sleep at its end try { Thread.sleep(1000); } catch (InterruptedException ie) { // continue } }
Example 4
Source File: SakaiContextLoaderListener.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check */ private static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { log.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
Example 5
Source File: JSR356WebsocketInitializer.java From flow with Apache License 2.0 | 6 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { // Destroy any AtmosphereFramework instance we have initialized. // This must be done here to ensure that we cleanup Atmosphere instances // related to servlets which are never initialized ServletContext servletContext = sce.getServletContext(); Enumeration<String> attributeNames = servletContext.getAttributeNames(); while (attributeNames.hasMoreElements()) { String attributeName = attributeNames.nextElement(); if (isAtmosphereFrameworkAttribute(attributeName)) { Object value = servletContext.getAttribute(attributeName); if (value instanceof AtmosphereFramework) { // This might result in calling destroy() twice, once from // here and once from PushRequestHandler but // AtmosphereFramework.destroy() deals with that ((AtmosphereFramework) value).destroy(); } } } }
Example 6
Source File: WebAppContext.java From mdw with Apache License 2.0 | 6 votes |
public static SysInfoCategory getContainerInfo(ServletContext context) { List<SysInfo> containerInfos = new ArrayList<SysInfo>(); containerInfos.add(new SysInfo("Root path", context.getRealPath("/"))); containerInfos.add(new SysInfo("Servlet container", context.getServerInfo())); containerInfos.add(new SysInfo("Servlet version", context.getMajorVersion() + "." + context.getMinorVersion())); containerInfos.add(new SysInfo("Servlet context", context.getServletContextName())); SysInfo attrInfo = new SysInfo("Attributes"); Enumeration<?> attrNames = context.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String)attrNames.nextElement(); if (!"org.apache.tomcat.util.scan.MergedWebXml".equals(attrName) && !"org.apache.catalina.jsp_classpath".equals(attrName)) attrInfo.addSysInfo(new SysInfo(attrName, String.valueOf(context.getAttribute(attrName)))); } containerInfos.add(attrInfo); return new SysInfoCategory("Container Details", containerInfos); }
Example 7
Source File: ContextCleanupListener.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check */ static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
Example 8
Source File: MqConsumerController.java From RocketMqCurrencyBoot with Apache License 2.0 | 6 votes |
/** * 获取servletContext 中存放的 所有 消费者对象 唯一标识 * * @return 返回 说有消费者唯一标识 * */ @RequestMapping(method = RequestMethod.GET) public List<AttributeNames> queryMqConsumerList() { ServletContext servletContext = request.getServletContext(); List<AttributeNames> list = new ArrayList<AttributeNames>(); Enumeration<String> attributeNames = servletContext.getAttributeNames(); while (attributeNames.hasMoreElements()) { String nameString = (String) attributeNames.nextElement(); if (nameString.contains("@")) { AttributeNames attri = new AttributeNames(); attri.setKid(nameString); list.add(attri); } } return list; }
Example 9
Source File: MqConsumerController.java From RocketMqCurrencyBoot with Apache License 2.0 | 6 votes |
/** * 销毁一个消费端 * * 该方法 会通过传递的 ConsumerID 从 servletContext 查询 是否有 该对象 * 然后调用 其销毁方法 * * @param ConsumerID 消费者唯一标识 * @return */ @RequestMapping(method = RequestMethod.DELETE) public ResponseEntity<String> destroyMqConsumer(@RequestParam("Consumer") String Consumer) { ServletContext servletContext = request.getServletContext(); Enumeration<String> attributeNames = servletContext.getAttributeNames(); List<String> outList = new ArrayList<String>(); Object AttributeConsumer = servletContext.getAttribute(Consumer); if (AttributeConsumer != null) { MqConsumer mqConsumer = (MqConsumer) AttributeConsumer; mqConsumer.destroy(); servletContext.setAttribute(Consumer, null); return ResponseEntity.status(HttpStatus.OK).body(Consumer + " 消费者销毁成功"); } return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Consumer + " 未找到 该消费者 "); }
Example 10
Source File: ContextCleanupListener.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check */ static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
Example 11
Source File: ContextCleanupListener.java From java-technology-stack with MIT License | 6 votes |
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check */ static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
Example 12
Source File: ContextCleanupListener.java From spring-analysis-note with MIT License | 6 votes |
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check */ static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
Example 13
Source File: InfoServlet.java From cumulusrdf with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { String accept = request.getHeader(Headers.ACCEPT) == null ? "text/plain" : request.getHeader(Headers.ACCEPT); if (accept.contains("html")) { request.setAttribute("page", "Overview"); forwardTo(request, response, "info.vm"); } else { PrintWriter out = response.getWriter(); response.setContentType(MimeTypes.TEXT_PLAIN); ServletContext ctx = getServletContext(); Store crdf = (Store) getServletContext().getAttribute(ConfigParams.STORE); out.println("Status: " + crdf.getStatus()); for (Enumeration<String> e = ctx.getAttributeNames(); e.hasMoreElements();) { String attr = e.nextElement(); out.println("Setting: attribute = " + attr + " @ value = " + ctx.getAttribute(attr)); } out.close(); } }
Example 14
Source File: BootstrapUtil.java From ldp4j with Apache License 2.0 | 5 votes |
private static void addAttributeMessages(ServletContext context,Map<String, Object> messages) { Enumeration<String> attributeNames = context.getAttributeNames(); if(attributeNames==null || !attributeNames.hasMoreElements()) { return; } StringBuilder builder=new StringBuilder(); while(attributeNames.hasMoreElements()) { String name = attributeNames.nextElement(); buildAttributeMessage(builder,name,context.getAttribute(name)); } addMessage(messages,"Attributes",builder.toString()); }
Example 15
Source File: ResteasyContextParams.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
public static Set<String> init(final ServletContext context, final Set<String> existing) { if(existing != null) { return existing; } final Set<String> ret = new HashSet<String>(); Enumeration names = context.getAttributeNames(); while (names.hasMoreElements()) { ret.add((String) names.nextElement()); } return ret; }
Example 16
Source File: RefreshDispatchersCommand.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
/** * Clear any resteasy stuff from the context * * @param servletContext */ private void clearContext(final ServletContext servletContext, final Set<String> doNotClear) { final Enumeration names = servletContext.getAttributeNames(); while (names.hasMoreElements()) { final String name = names.nextElement().toString(); if (name.startsWith("org.jboss.resteasy") && !doNotClear.contains(name)) { servletContext.removeAttribute(name); } } }
Example 17
Source File: MonitorFilter.java From netbeans with Apache License 2.0 | 4 votes |
/** * Creates a Param[] of attributes from a Context */ private Param[] recordContextAttributes(ServletContext context) { if(debug) log("recordContextAttributes"); //NOI18N Vector v = new Vector(); Enumeration e = context.getAttributeNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); if(debug) log(" name: " + name); //NOI18N Object value = context.getAttribute(name); String valueRep = null; try { if(value == null) { valueRep = ResourceBundle.getBundle("org.netbeans.modules.web.monitor.server.Bundle").getString("MON_Warning_attributes"); //NOI18N } else if (value.getClass().isArray()) { Object[] valueItems = (Object[])value; StringBuffer sb = new StringBuffer(valueItems.length * 16); if (valueItems.length > 0) sb.append(valueItems[0]); for(int i=1; i < valueItems.length; i++) { sb.append(", "); // NOI18N sb.append(valueItems[i]); } valueRep = sb.toString(); } else { valueRep = value.toString(); if (valueRep == null) { valueRep = ResourceBundle.getBundle("org.netbeans.modules.web.monitor.server.Bundle").getString("MON_Warning_toString_null"); //NOI18N } } } catch (Throwable t) { // Ensure that the monitor can continue to run even if there is a // serious problem in the application code that it is monitoring valueRep = ResourceBundle.getBundle("org.netbeans.modules.web.monitor.server.Bundle").getString("MON_Warning_toString_exception"); //NOI18N } Param p = new Param(); p.setAttributeValue("name", name); //NOI18N p.setAttributeValue("value", valueRep); //NOI18N v.add(p); } int size = v.size(); Param[] params = new Param[size]; for(int i=0; i< size; ++i) params[i] = (Param)v.elementAt(i); return params; }
Example 18
Source File: ServletAttrContainer.java From scipio-erp with Apache License 2.0 | votes |
public static Enumeration<String> getAttributeNames(ServletContext container) { return (container != null) ? container.getAttributeNames() : null; }