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:jp.terasoluna.fw.service.thin.BLogicMapper.java
/** * NGXgwv?peBli[?B//from w ww .j av a 2s . c o m * * @param value ?ol * @param propName v?peB * @param request HTTPNGXg * @param response HTTPX|X */ @SuppressWarnings("unchecked") @Override public void setValueToRequest(Object value, String propName, HttpServletRequest request, HttpServletResponse response) { if (propName == null || "".equals(propName)) { log.error("illegal argument:propName = [" + propName + "]"); throw new IllegalArgumentException(); } if (log.isDebugEnabled()) { Enumeration<String> enumeration = request.getAttributeNames(); int existFlag = 0; while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); if (key.equals(propName)) { existFlag = 1; break; } } if (existFlag != 1) { log.debug("Request's key does not exist:key =[" + propName + "]"); } } // NGXgli[ request.setAttribute(propName, value); }
From source file:org.jtwig.util.render.RenderHttpServletRequest.java
public RenderHttpServletRequest(HttpServletRequest initialRequest) { initialValues = snapshot(initialRequest, HttpServletRequest.class); Enumeration attributeNames = initialRequest.getAttributeNames(); if (attributeNames != null) { while (attributeNames.hasMoreElements()) { String name = (String) attributeNames.nextElement(); attributes.put(name, initialRequest.getAttribute(name)); }//from w w w. ja v a 2 s .c o m } realPath = initialRequest.getRealPath(""); requestDispatcher = initialRequest.getRequestDispatcher(initialRequest.getServletPath()); }
From source file:org.sakaiproject.access.tool.WebServlet.java
/** * Handle file upload requests./*from ww w. j av a2s .c o m*/ * * @param req * @param res */ protected void postUpload(HttpServletRequest req, HttpServletResponse res) { String path = req.getPathInfo(); // System.out.println("path " + path); if (path == null) path = ""; // assume caller has verified that it is a request for content and that it's multipart // loop over attributes in request, picking out the ones // that are file uploads and doing them for (Enumeration e = req.getAttributeNames(); e.hasMoreElements();) { String iname = (String) e.nextElement(); // System.out.println("Item " + iname); Object o = req.getAttribute(iname); // NOTE: Fileitem is from // org.apache.commons.fileupload.FileItem, not // sakai's parameterparser version if (o != null && o instanceof FileItem) { FileItem fi = (FileItem) o; // System.out.println("found file " + fi.getName()); if (!writeFile(fi.getName(), fi.getContentType(), fi.get(), path, req, res, true)) return; } } }
From source file:org.apache.ofbiz.base.util.UtilHttp.java
/** * Create a map from a HttpRequest (attributes) object * @return The resulting Map//from w ww .j a v a 2 s . co m */ public static Map<String, Object> getAttributeMap(HttpServletRequest request, Set<? extends String> namesToSkip) { Map<String, Object> attributeMap = new HashMap<String, Object>(); // look at all request attributes Enumeration<String> requestAttrNames = UtilGenerics.cast(request.getAttributeNames()); while (requestAttrNames.hasMoreElements()) { String attrName = requestAttrNames.nextElement(); if (namesToSkip != null && namesToSkip.contains(attrName)) continue; Object attrValue = request.getAttribute(attrName); attributeMap.put(attrName, attrValue); } if (Debug.verboseOn()) { Debug.logVerbose("Made Request Attribute Map with [" + attributeMap.size() + "] Entries", module); Debug.logVerbose("Request Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(attributeMap), module); } return attributeMap; }
From source file:org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory.java
public void create(IdentityRequest.IdentityRequestBuilder builder, HttpServletRequest request, HttpServletResponse response) throws FrameworkClientException { Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); builder.addHeader(headerName, request.getHeader(headerName)); }//from w w w. ja v a2 s .c om // We need to create a new map with the parameters sent in servlet request to avoid having a reference. Map<String, String[]> paramMap = new HashMap<>(request.getParameterMap()); builder.setParameters(paramMap); Enumeration<String> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); builder.addAttribute(attrName, request.getAttribute(attrName)); } Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { builder.addCookie(cookie.getName(), cookie); } } String requestURI = request.getRequestURI(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); if (StringUtils.isNotBlank(tenantDomain)) { builder.setTenantDomain(tenantDomain); } else { builder.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); } builder.setContentType(request.getContentType()); builder.setContextPath(request.getContextPath()); builder.setMethod(request.getMethod()); builder.setPathInfo(request.getPathInfo()); builder.setPathTranslated(request.getPathTranslated()); builder.setQueryString(request.getQueryString()); builder.setRequestURI(requestURI); builder.setRequestURL(request.getRequestURL()); builder.setServletPath(request.getServletPath()); }
From source file:org.nuxeo.ecm.platform.ui.web.shield.ErrorPageForwarder.java
private String getRequestDump(HttpServletRequest request) { StringBuilder builder = new StringBuilder(); builder.append("\nParameter:\n"); Map<String, String[]> m = request.getParameterMap(); for (Map.Entry<String, String[]> entry : m.entrySet()) { builder.append(entry.getKey()).append(":"); if (entry.getValue() == null) { continue; }//from w w w.jav a2 s .c o m for (String s : entry.getValue()) { builder.append(s).append(","); } builder.deleteCharAt(builder.length() - 1); builder.append("\n"); } builder.append("\n"); Enumeration<String> names = request.getAttributeNames(); builder.append("Attributes:\n"); while (names.hasMoreElements()) { String name = names.nextElement(); if (name.equals(SEAM_MESSAGES)) { continue; } Object obj = request.getAttribute(name); builder.append(name).append(": ").append(obj.toString()).append("\n"); } builder.append("\n"); Collection<RegistrationInfo> infos = Framework.getRuntime().getComponentManager().getRegistrations(); builder.append("Components:\n"); for (RegistrationInfo info : infos) { builder.append(info.getComponent().getName()).append(",") .append(info.isActivated() ? "activated" : "not activated").append("\n"); } nuxeoErrorLog.trace("User Principal: " + request.getUserPrincipal() + "\n" + builder.toString()); return builder.toString(); }
From source file:org.dbflute.saflute.web.servlet.filter.RequestLoggingFilter.java
protected void buildRequestAttributes(StringBuilder sb, HttpServletRequest request) { for (Iterator<?> it = toSortedSet(request.getAttributeNames()).iterator(); it.hasNext();) { final String name = (String) it.next(); if (ERROR_ATTRIBUTE_KEY.equals(name)) { continue; // because the error is handled in this filter }/*from w w w. j ava 2 s . c o m*/ final Object attr = request.getAttribute(name); sb.append(IND); sb.append("[request] ").append(name).append("="); sb.append(filterAttributeDisp(attr)); sb.append(LF); } }
From source file:com.netspective.sparx.form.DialogContextUtils.java
/** * Copy any request parameters or attributes that match field names in the dialog *//*from w w w .j a v a 2 s . c o m*/ public void populateFieldValuesFromRequestParamsAndAttrs(DialogContext dc) { HttpServletRequest request = dc.getHttpRequest(); Map params = request.getParameterMap(); DialogFieldStates fieldStates = dc.getFieldStates(); Iterator i = params.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String name = (String) entry.getKey(); DialogField.State state = fieldStates.getState(name, null); if (state != null) { String[] values = (String[]) entry.getValue(); state.getValue().setValue(values); } } Enumeration e = request.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); DialogField.State state = fieldStates.getState(name, null); if (state != null) state.getValue().setValue(request.getAttribute(name)); } }
From source file:net.sourceforge.fenixedu.presentationTier.util.ExceptionInformation.java
private void requestContextAppend(HttpServletRequest request, StringBuilder exceptionInfo) { Map<String, Object> requestContext = new HashMap<String, Object>(); Enumeration requestContents = request.getAttributeNames(); while (requestContents.hasMoreElements()) { String requestElement = requestContents.nextElement().toString(); requestContext.put(requestElement, request.getAttribute(requestElement)); exceptionInfo.append("RequestElement:").append(requestElement).append("\n"); exceptionInfo.append("RequestElement Value:").append(request.getAttribute(requestElement)).append("\n"); }/*from w w w . j a v a 2 s . c o m*/ this.requestContextEntries = requestContext; }
From source file:org.apache.hadoop.hdfsproxy.ProxyFilter.java
/** {@inheritDoc} */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest rqst = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; if (LOG.isDebugEnabled()) { StringBuilder b = new StringBuilder("Request from ").append(rqst.getRemoteHost()).append("/") .append(rqst.getRemoteAddr()).append(":").append(rqst.getRemotePort()); @SuppressWarnings("unchecked") Enumeration<String> e = rqst.getAttributeNames(); for (; e.hasMoreElements();) { String attribute = e.nextElement(); b.append("\n " + attribute + " => " + rqst.getAttribute(attribute)); }/*from w w w .jav a 2 s . c o m*/ X509Certificate[] userCerts = (X509Certificate[]) rqst .getAttribute("javax.servlet.request.X509Certificate"); if (userCerts != null) for (X509Certificate cert : userCerts) b.append("\n Client certificate Subject Name is " + cert.getSubjectX500Principal().getName()); b.append("\n The Scheme is " + rqst.getScheme()); b.append("\n The Auth Type is " + rqst.getAuthType()); b.append("\n The Path Info is " + rqst.getPathInfo()); b.append("\n The Translated Path Info is " + rqst.getPathTranslated()); b.append("\n The Context Path is " + rqst.getContextPath()); b.append("\n The Query String is " + rqst.getQueryString()); b.append("\n The Remote User is " + rqst.getRemoteUser()); b.append("\n The User Principal is " + rqst.getUserPrincipal()); b.append("\n The Request URI is " + rqst.getRequestURI()); b.append("\n The Request URL is " + rqst.getRequestURL()); b.append("\n The Servlet Path is " + rqst.getServletPath()); LOG.debug(b.toString()); } boolean unitTest = false; if (rqst.getScheme().equalsIgnoreCase("http") && rqst.getParameter("UnitTest") != null) unitTest = true; if (rqst.getScheme().equalsIgnoreCase("https") || unitTest) { boolean isAuthorized = false; X509Certificate[] certs = (X509Certificate[]) rqst .getAttribute("javax.servlet.request.X509Certificate"); if (unitTest) { try { LOG.debug("==> Entering https unit test"); String SslPath = rqst.getParameter("SslPath"); InputStream inStream = new FileInputStream(SslPath); CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream); inStream.close(); certs = new X509Certificate[] { cert }; } catch (Exception e) { // do nothing here } } if (certs == null || certs.length == 0) { rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "No client SSL certificate received"); LOG.info("No Client SSL certificate received"); return; } for (X509Certificate cert : certs) { try { cert.checkValidity(); } catch (CertificateExpiredException e) { LOG.info("Received cert for " + cert.getSubjectX500Principal().getName() + " expired"); rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "Certificate expired"); return; } catch (CertificateNotYetValidException e) { LOG.info("Received cert for " + cert.getSubjectX500Principal().getName() + " is not yet valid"); rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "Certificate is not yet valid"); return; } } String[] tokens = certs[0].getSubjectX500Principal().getName().split("\\s*,\\s*"); String userID = null; for (String s : tokens) { if (s.startsWith("CN=")) { userID = s; break; } } if (userID == null || userID.length() < 4) { LOG.info("Can't retrieve user ID from SSL certificate"); rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "Can't retrieve user ID from SSL certificate"); return; } userID = userID.substring(3); String servletPath = rqst.getServletPath(); if (unitTest) { servletPath = rqst.getParameter("TestSevletPathInfo"); LOG.info("this is for unit test purpose only"); } if (HFTP_PATTERN.matcher(servletPath).matches()) { // request is an HSFTP request if (FILEPATH_PATTERN.matcher(servletPath).matches()) { // file path as part of the URL isAuthorized = checkPath(userID, certs[0], rqst.getPathInfo() != null ? rqst.getPathInfo() : "/"); } else { // file path is stored in "filename" parameter isAuthorized = checkPath(userID, certs[0], rqst.getParameter("filename")); } } else if (RELOAD_PATTERN.matcher(servletPath).matches() && checkUser("Admin", certs[0])) { Configuration conf = new Configuration(false); conf.addResource("hdfsproxy-default.xml"); Map<String, Set<Path>> permsMap = getPermMap(conf); Map<String, Set<BigInteger>> certsMap = getCertsMap(conf); if (permsMap == null || certsMap == null) { LOG.warn("Permission files reloading failed"); rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Permission files reloading failed"); return; } ProxyFilter.permsMap = permsMap; ProxyFilter.certsMap = certsMap; LOG.info("User permissions and user certs files reloaded"); rsp.setStatus(HttpServletResponse.SC_OK); return; } if (!isAuthorized) { rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "Unauthorized access"); return; } // request is authorized, set ugi for servlets UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userID); rqst.setAttribute("authorized.ugi", ugi); rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.userID", userID); } else if (rqst.getScheme().equalsIgnoreCase("http")) { // http request, set ugi for servlets, only for testing purposes String ugi = rqst.getParameter("ugi"); if (ugi != null) { rqst.setAttribute("authorized.ugi", UserGroupInformation.createRemoteUser(ugi)); rqst.setAttribute("org.apache.hadoop.hdfsproxy.authorized.userID", ugi.split(",")[0]); } } chain.doFilter(request, response); }