List of usage examples for javax.servlet.http HttpServletRequest getAttributeNames
public Enumeration<String> getAttributeNames();
Enumeration
containing the names of the attributes available to this request. From source file:org.springframework.web.servlet.LogDispatcherServlet.java
/** * Restore the request attributes after an include. * @param request current HTTP request/*from w w w. j av a 2 s .c o m*/ * @param attributesSnapshot the snapshot of the request attributes before the include */ @SuppressWarnings("unchecked") private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?, ?> attributesSnapshot) { // Need to copy into separate Collection here, to avoid side effects // on the Enumeration when removing attributes. Set<String> attrsToCheck = new HashSet<String>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) { attrsToCheck.add(attrName); } } // Add attributes that may have been removed attrsToCheck.addAll((Set<String>) attributesSnapshot.keySet()); // Iterate over the attributes to check, restoring the original value // or removing the attribute, respectively, if appropriate. for (String attrName : attrsToCheck) { Object attrValue = attributesSnapshot.get(attrName); if (attrValue == null) { request.removeAttribute(attrName); } else if (attrValue != request.getAttribute(attrName)) { request.setAttribute(attrName, attrValue); } } }
From source file:org.springframework.web.servlet.MyDispatcherServlet.java
/** * Restore the request attributes after an include. * @param request current HTTP request//from w w w . j ava2 s . c o m * @param attributesSnapshot the snapshot of the request attributes before the include */ private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?, ?> attributesSnapshot) { logger.debug("Restoring snapshot of request attributes after include"); // Need to copy into separate Collection here, to avoid side effects // on the Enumeration when removing attributes. Set<String> attrsToCheck = new HashSet<String>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) { attrsToCheck.add(attrName); } } // Iterate over the attributes to check, restoring the original value // or removing the attribute, respectively, if appropriate. for (String attrName : attrsToCheck) { Object attrValue = attributesSnapshot.get(attrName); if (attrValue == null) { if (logger.isDebugEnabled()) { logger.debug("Removing attribute [" + attrName + "] after include"); } request.removeAttribute(attrName); } else if (attrValue != request.getAttribute(attrName)) { if (logger.isDebugEnabled()) { logger.debug("Restoring original value of attribute [" + attrName + "] after include"); } request.setAttribute(attrName, attrValue); } } }
From source file:org.testdwr.plain.Test.java
@SuppressWarnings("unchecked") public Map<String, String> listParameters(HttpServletRequest request) { Map<String, String> reply = new HashMap<String, String>(); Enumeration<String> names = request.getAttributeNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String value = request.getAttribute(name).toString(); reply.put(name, value);// www . j av a 2 s. c o m } return reply; }
From source file:org.springframework.web.servlet.DispatcherServlet.java
/** * Restore the request attributes after an include. * @param request current HTTP request//from ww w .jav a 2 s. co m * @param attributesSnapshot the snapshot of the request attributes before the include */ @SuppressWarnings("unchecked") private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?, ?> attributesSnapshot) { // Need to copy into separate Collection here, to avoid side effects // on the Enumeration when removing attributes. Set<String> attrsToCheck = new HashSet<>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) { attrsToCheck.add(attrName); } } // Add attributes that may have been removed attrsToCheck.addAll((Set<String>) attributesSnapshot.keySet()); // Iterate over the attributes to check, restoring the original value // or removing the attribute, respectively, if appropriate. for (String attrName : attrsToCheck) { Object attrValue = attributesSnapshot.get(attrName); if (attrValue == null) { request.removeAttribute(attrName); } else if (attrValue != request.getAttribute(attrName)) { request.setAttribute(attrName, attrValue); } } }
From source file:org.sakaiproject.entitybroker.util.http.EntityHttpServletRequest.java
/** * Set all the values from a request on this request object and set this request * as the one which the values were copied from * @param req any request/*from w ww. ja v a 2s .co m*/ */ public void setRequestValues(HttpServletRequest req) { if (req == null) { throw new IllegalArgumentException("request cannot be null"); } // get the collections of values out Enumeration<String> attribNames = req.getAttributeNames(); while (attribNames.hasMoreElements()) { String name = (String) attribNames.nextElement(); Object obj = req.getAttribute(name); if (obj != null) { attributes.put(name, obj); } } Cookie[] ck = req.getCookies(); if (ck != null) { for (int i = 0; i < ck.length; i++) { cookies.add(ck[i]); } } Enumeration<String> headerNames = req.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); Enumeration<String> henum = req.getHeaders(name); Vector<String> v = new Vector<String>(1); while (henum.hasMoreElements()) { String h = henum.nextElement(); v.add(h); } } for (Entry<String, String[]> entry : (Set<Entry<String, String[]>>) req.getParameterMap().entrySet()) { parameters.put(entry.getKey(), entry.getValue()); } // get the basic values out this.locale = req.getLocale(); this.method = req.getMethod(); this.contentType = req.getContentType(); this.characterEncoding = req.getCharacterEncoding() == null ? "UTF-8" : req.getCharacterEncoding(); this.contentLength = req.getContentLength(); this.contextPath = req.getContextPath(); this.pathInfo = req.getPathInfo(); this.queryString = req.getQueryString(); this.requestURI = req.getRequestURI(); this.servletPath = req.getServletPath(); this.scheme = req.getScheme(); this.protocol = req.getProtocol(); this.serverName = req.getServerName(); this.serverPort = req.getServerPort(); this.remoteAddr = req.getRemoteAddr(); this.remoteHost = req.getRemoteHost(); this.realDispatcher = true; }
From source file:ro.raisercostin.web.DebuggingFilter.java
public String debug(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, DebuggingPrinter debuggingPrinter, boolean debugAll, boolean debugRequest) { final JspFactory jspFactory = JspFactory.getDefaultFactory(); HttpSession session = request.getSession(); debuggingPrinter.addHeader();/*from w w w . j a v a2 s. c o m*/ debuggingPrinter.addSection("Request Parameters"); for (Iterator iterator = request.getParameterMap().entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> parameter = (Map.Entry<String, Object>) iterator.next(); addRow(debuggingPrinter, parameter.getKey(), StringUtils.arrayToCommaDelimitedString((Object[]) parameter.getValue())); } debuggingPrinter.endSection(); if (debugRequest) { debuggingPrinter.addSection("Request Header"); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(request.getHeader(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Attributes"); java.util.Enumeration en = request.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(request.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Session Attributes"); en = session.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(session.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Info"); addRow(debuggingPrinter, "AuthType", request.getAuthType()); addRow(debuggingPrinter, "ContextPath", request.getContextPath()); addRow(debuggingPrinter, "Method", request.getMethod()); addRow(debuggingPrinter, "PathInfo", request.getPathInfo()); addRow(debuggingPrinter, "PathTranslated", request.getPathTranslated()); addRow(debuggingPrinter, "Protocol", request.getProtocol()); addRow(debuggingPrinter, "QueryString", request.getQueryString()); addRow(debuggingPrinter, "RemoteAddr", request.getRemoteAddr()); addRow(debuggingPrinter, "RemoteUser", request.getRemoteUser()); addRow(debuggingPrinter, "RequestedSessionId", request.getRequestedSessionId()); addRow(debuggingPrinter, "RequestURI", request.getRequestURI()); addRow(debuggingPrinter, "RequestURL", request.getRequestURL().toString()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); addRow(debuggingPrinter, "Scheme", request.getScheme()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); } if (debugAll) { debuggingPrinter.addSection("Server"); addRow(debuggingPrinter, "Server Info", servletContext.getServerInfo()); addRow(debuggingPrinter, "Servlet Engine Version", servletContext.getMajorVersion() + "." + servletContext.getMinorVersion()); addRow(debuggingPrinter, "JSP Version", jspFactory.getEngineInfo().getSpecificationVersion()); debuggingPrinter.endSection(); debuggingPrinter.addSection("JVM Properties"); for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(System.getProperty(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Environment"); for (Map.Entry<String, String> property : System.getenv().entrySet()) { addRow(debuggingPrinter, property.getKey(), debuggingPrinter.transform(property.getValue())); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Debugger Provided by"); addRow(debuggingPrinter, "provided by", "raisercostin"); debuggingPrinter.addRow("source", "<a target='_blank' href='http://code.google.com/p/raisercostin/wiki/DebuggingFilter'>http://code.google.com/p/raisercostin/wiki/DebuggingFilter</a>"); addRow(debuggingPrinter, "version", "1.0"); addRow(debuggingPrinter, "timestamp", "2008.June.14"); addRow(debuggingPrinter, "license", "<a target='_blank' href='http://www.apache.org/licenses/LICENSE-2.0.html'>Apache License 2.0</a>"); debuggingPrinter.endSection(); } debuggingPrinter.addFooter(); return debuggingPrinter.getString(); }
From source file:org.foxbpm.web.controller.AbstWebController.java
/** * http request ??//from ww w . j a va 2 s. c o m * * @param request * http * @return ?http? */ @SuppressWarnings("unchecked") protected Map<String, Object> getRequestParams(HttpServletRequest request) { // ? Map<String, Object> requestParams = new HashMap<String, Object>(); requestParams.putAll(request.getParameterMap()); try { Enumeration<String> enumeration = null; if (ServletFileUpload.isMultipartContent(request)) { ServletFileUpload Uploader = new ServletFileUpload(new DiskFileItemFactory()); Uploader.setHeaderEncoding("utf-8"); List<FileItem> fileItems = Uploader.parseRequest(request); for (FileItem item : fileItems) { requestParams.put(item.getFieldName(), item); if (WebContextAttributeName.ATTRIBUTE_DEPLOYMENTID.equals(item.getFieldName())) { requestParams.put(WebContextAttributeName.ATTRIBUTE_DEPLOYMENTID, item.getString()); } } } else { // ?parmeter? enumeration = request.getParameterNames(); if (null != enumeration) { String key = null; String value = null; while (enumeration.hasMoreElements()) { key = enumeration.nextElement(); value = request.getParameter(key); requestParams.put(key, new String(value.getBytes("ISO8859-1"), "utf-8")); } } } // ?attribute? enumeration = request.getAttributeNames(); if (null != enumeration) { String key = null; while (enumeration.hasMoreElements()) { key = enumeration.nextElement(); requestParams.put(key, request.getAttribute(key)); } } // ?? requestParams.put(WebContextAttributeName.USERID, request.getSession().getAttribute(WebContextAttributeName.USERID)); } catch (Exception e) { throw new FoxbpmWebException(e); } return requestParams; }
From source file:com.mystudy.source.spring.mvc.DispatcherServlet.java
/** * Restore the request attributes after an include. * @param request current HTTP request//www. j a v a2 s . c o m * @param attributesSnapshot the snapshot of the request attributes before the include */ @SuppressWarnings("unchecked") private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?, ?> attributesSnapshot) { logger.debug("Restoring snapshot of request attributes after include"); // Need to copy into separate Collection here, to avoid side effects // on the Enumeration when removing attributes. Set<String> attrsToCheck = new HashSet<String>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) { attrsToCheck.add(attrName); } } // Add attributes that may have been removed attrsToCheck.addAll((Set<String>) attributesSnapshot.keySet()); // Iterate over the attributes to check, restoring the original value // or removing the attribute, respectively, if appropriate. for (String attrName : attrsToCheck) { Object attrValue = attributesSnapshot.get(attrName); if (attrValue == null) { if (logger.isDebugEnabled()) { logger.debug("Removing attribute [" + attrName + "] after include"); } request.removeAttribute(attrName); } else if (attrValue != request.getAttribute(attrName)) { if (logger.isDebugEnabled()) { logger.debug("Restoring original value of attribute [" + attrName + "] after include"); } request.setAttribute(attrName, attrValue); } } }
From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java
protected PageInfo buildPage(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { // Invoke the next entity in the chain SerializableByteArrayOutputStream out = new SerializableByteArrayOutputStream(); GenericResponseWrapper wrapper = new GenericResponseWrapper(response, out); Map<String, Serializable> cacheableRequestAttributes = new HashMap<String, Serializable>(); // TODO: split the special include handling out into a separate method HttpServletResponse originalResponse = null; boolean isInclude = WebUtils.isIncludeRequest(request); if (isInclude) { originalResponse = WrappedResponseHolder.getWrappedResponse(); WrappedResponseHolder.setWrappedResponse(wrapper); }/*from ww w . j av a2 s . c o m*/ try { List<String> attributesBefore = toList(request.getAttributeNames()); chain.doFilter(request, wrapper); List<String> attributesAfter = toList(request.getAttributeNames()); attributesAfter.removeAll(attributesBefore); for (String attrName : attributesAfter) { Object value = request.getAttribute(attrName); if (value instanceof Serializable) { cacheableRequestAttributes.put(attrName, (Serializable) value); } } } finally { if (isInclude) { WrappedResponseHolder.setWrappedResponse(originalResponse); } } wrapper.flush(); long timeToLiveSeconds = Integer.MAX_VALUE; // TODO cacheManager.getEhcache(context.cacheName).cacheConfiguration.timeToLiveSeconds; String contentType = wrapper.getContentType(); if (!StringUtils.hasLength(contentType)) { contentType = response.getContentType(); } return new PageInfo(wrapper.getStatus(), contentType, out.toByteArray(), false, timeToLiveSeconds, wrapper.getAllHeaders(), wrapper.getCookies(), cacheableRequestAttributes); }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/sitemap", method = RequestMethod.GET) public final ModelAndView showSiteMap() { final String methodName = CommonController.CNAME + "#showSiteMap()"; if (DEBUG) {//from www . ja v a2 s.c om DEBUGGER.debug(methodName); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } mView.setViewName(this.appConfig.getSiteMap()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }