javax.servlet.http.HttpServletRequest#getAttributeNames()源码实例Demo

下面列出了javax.servlet.http.HttpServletRequest#getAttributeNames() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: portals-pluto   文件: ServletRequestUtils.java
public static void logDebugInfo(HttpServletRequest req, String title) {

      if (LOGGER.isTraceEnabled()) {
         StringBuilder txt = new StringBuilder(128);
         txt.append("Servlet request info: \nAttributes for ").append(title).append(":");
         
         Enumeration<String> names = req.getAttributeNames();
         for (String name : Collections.list(names)) {
            txt.append("\nName: ").append(name);
            txt.append(", value: ").append(req.getAttribute(name));
         }
         
         txt.append("\n\nPath info:");
         txt.append("\nRequestUri:").append(req.getRequestURI());
         txt.append("\nContextPath:").append(req.getContextPath());
         txt.append("\nServletPath:").append(req.getServletPath());
         txt.append("\nPathInfo:").append(req.getPathInfo());
         txt.append("\nQueryString:").append(req.getQueryString());

         LOGGER.trace(txt.toString());
      }
   }
 
源代码2 项目: uyuni   文件: DumpFilter.java
private void logAttributes(HttpServletRequest req) {
    Enumeration items = req.getAttributeNames();
    while (items.hasMoreElements()) {
        String name = (String) items.nextElement();
        Object obj = req.getAttribute(name);
        if (obj != null) {
            log.debug("Attribute: name [" + name + "] value [" +
                ReflectionToStringBuilder.toString(obj) + "]");
        }
        else {
            log.debug("Attribute: name [" + name + "] value [null]");
        }
    }
}
 
源代码3 项目: scipio-erp   文件: UtilHttp.java
/**
 * SCIPIO: Gets the request attribute names into the specified collection and returns the collection.
 */
public static <C extends Collection<? super String>> C getRequestAttrNames(HttpServletRequest request, C out, Collection<String> namesToSkip) {
    Enumeration<String> names = request.getAttributeNames();
    while(names.hasMoreElements()) {
        String name = names.nextElement();
        if (namesToSkip == null || !namesToSkip.contains(name)) {
            out.add(name);
        }
    }
    return out;
}
 
源代码4 项目: rice   文件: WebUtils.java
/**
 * Iterates through and logs (at the given level) all attributes and
 * parameters of the given request onto the given Logger
 * 
 * @param request
 * @param logger
 */
public static void logRequestContents(Logger logger, Level level, HttpServletRequest request) {
	if (logger.isEnabledFor(level)) {
		logger.log(level, "--------------------");
		logger.log(level, "HttpRequest attributes:");
		for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
			String attrName = (String) e.nextElement();
			Object attrValue = request.getAttribute(attrName);

			if (attrValue.getClass().isArray()) {
				logCollection(logger, level, attrName, Arrays.asList((Object[]) attrValue));
			}
			else if (attrValue instanceof Collection) {
				logCollection(logger, level, attrName, (Collection) attrValue);
			}
			else if (attrValue instanceof Map) {
				logMap(logger, level, attrName, (Map) attrValue);
			}
			else {
				logObject(logger, level, attrName, attrValue);
			}
		}

		logger.log(level, "--------------------");
		logger.log(level, "HttpRequest parameters:");
		for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
			String paramName = (String) i.nextElement();
			String[] paramValues = (String[]) request.getParameterValues(paramName);

			logArray(logger, level, paramName, paramValues);
		}

		logger.log(level, "--------------------");
	}
}
 
源代码5 项目: trimou   文件: TrimouView.java
private void exposeRequestAttributesAsModel(Map<String, Object> model,
        HttpServletRequest request) {
    if (request == null || request.getAttributeNames() == null) {
        return;
    }
    Enumeration<String> attributeNames = request.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        String attributeName = attributeNames.nextElement();
        model.put(attributeName, request.getAttribute(attributeName));
    }
}
 
源代码6 项目: mycore   文件: MCRParameterCollector.java
/**
 * Sets those request parameters as XSL parameters that start with "XSL.",
 * others will be ignored. The "XSL." prefix is cut off from the name.
 */
private void setFromRequestAttributes(HttpServletRequest request) {
    for (Enumeration<String> e = request.getAttributeNames(); e.hasMoreElements();) {
        String name = e.nextElement();
        if (!(name.endsWith(".SESSION"))) {
            final Object attributeValue = request.getAttribute(name);
            if (attributeValue != null) {
                setXSLParameter(name, attributeValue.toString());
            }
        }
    }
}
 
源代码7 项目: vespa   文件: JDiscHttpServlet.java
private static String formatAttributes(final HttpServletRequest request) {
    StringBuilder out = new StringBuilder();
    out.append("attributes = {");
    for (Enumeration<String> names = request.getAttributeNames(); names.hasMoreElements(); ) {
        String name = names.nextElement();
        out.append(" '").append(name).append("' = '").append(request.getAttribute(name)).append("'");
        if (names.hasMoreElements()) {
            out.append(",");
        }
    }
    out.append(" }");
    return out.toString();
}
 
源代码8 项目: sakai   文件: WebServlet.java
/**
 * Handle file upload requests.
 * 
 * @param req
 * @param res
 */
protected void postUpload(HttpServletRequest req, HttpServletResponse res)
{
	String path = req.getPathInfo();
	log.debug("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();
		log.debug("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;
			try (InputStream inputStream = fi.getInputStream())
			{
				if (!writeFile(fi.getName(), fi.getContentType(), inputStream, path, req, res, true)) return;
			} catch (IOException ioe) {
				log.warn("Problem getting InputStream", ioe);
			}
		}
	}
}
 
源代码9 项目: hasor   文件: InvokerCallerParamsBuilder.java
private Object getAttributeParam(Invoker invoker, AttributeParameter pAnno) {
    String paramName = pAnno.value();
    if (StringUtils.isBlank(paramName)) {
        return null;
    }
    HttpServletRequest httpRequest = invoker.getHttpRequest();
    Enumeration<?> e = httpRequest.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = e.nextElement().toString();
        if (name.equalsIgnoreCase(paramName)) {
            return httpRequest.getAttribute(paramName);
        }
    }
    return null;
}
 
源代码10 项目: spacewalk   文件: DumpFilter.java
private void logAttributes(HttpServletRequest req) {
    Enumeration items = req.getAttributeNames();
    while (items.hasMoreElements()) {
        String name = (String) items.nextElement();
        Object obj = req.getAttribute(name);
        if (obj != null) {
            log.debug("Attribute: name [" + name + "] value [" +
                ReflectionToStringBuilder.toString(obj) + "]");
        }
        else {
            log.debug("Attribute: name [" + name + "] value [null]");
        }
    }
}
 
源代码11 项目: spring-analysis-note   文件: DispatcherServlet.java
/**
 * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch}
 * for the actual dispatching.
 */
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
	logRequest(request);

	// Keep a snapshot of the request attributes in case of an include,
	// to be able to restore the original attributes after the include.
	// 暂存请求参数
	Map<String, Object> attributesSnapshot = null;
	if (WebUtils.isIncludeRequest(request)) {
		attributesSnapshot = new HashMap<>();
		Enumeration<?> attrNames = request.getAttributeNames();
		while (attrNames.hasMoreElements()) {
			String attrName = (String) attrNames.nextElement();
			if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) {
				attributesSnapshot.put(attrName, request.getAttribute(attrName));
			}
		}
	}

	// Make framework objects available to handlers and view objects.
	// 使框架对象可用于处理程序和视图对象
	request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
	request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
	request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
	request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());

	if (this.flashMapManager != null) {
		FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
		if (inputFlashMap != null) {
			request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
		}
		request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
		request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);
	}

	try {
		// 经过前面的准备(属性、辅助变量),进入请求处理过程
		doDispatch(request, response);
	}
	finally {
		if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {
			// Restore the original attribute snapshot, in case of an include.
			// 恢复原始参数
			if (attributesSnapshot != null) {
				restoreAttributesAfterInclude(request, attributesSnapshot);
			}
		}
	}
}
 
源代码12 项目: java-technology-stack   文件: DispatcherServlet.java
/**
 * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch}
 * for the actual dispatching.
 */
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
	logRequest(request);

	// Keep a snapshot of the request attributes in case of an include,
	// to be able to restore the original attributes after the include.
	Map<String, Object> attributesSnapshot = null;
	if (WebUtils.isIncludeRequest(request)) {
		attributesSnapshot = new HashMap<>();
		Enumeration<?> attrNames = request.getAttributeNames();
		while (attrNames.hasMoreElements()) {
			String attrName = (String) attrNames.nextElement();
			if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) {
				attributesSnapshot.put(attrName, request.getAttribute(attrName));
			}
		}
	}

	// Make framework objects available to handlers and view objects.
	request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
	request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
	request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
	request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());

	if (this.flashMapManager != null) {
		FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
		if (inputFlashMap != null) {
			request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
		}
		request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
		request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);
	}

	try {
		// 核心逻辑
		doDispatch(request, response);
	}
	finally {
		if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {
			// Restore the original attribute snapshot, in case of an include.
			if (attributesSnapshot != null) {
				restoreAttributesAfterInclude(request, attributesSnapshot);
			}
		}
	}
}
 
源代码13 项目: onedev   文件: ServletRequestCopy.java
public ServletRequestCopy(HttpServletRequest request) {
	this.servletPath = request.getServletPath();
	this.contextPath = request.getContextPath();
	this.pathInfo = request.getPathInfo();
	this.requestUri = request.getRequestURI();
	this.requestURL = request.getRequestURL();
	this.method = request.getMethod();
	this.serverName = request.getServerName();
	this.serverPort = request.getServerPort();
	this.protocol = request.getProtocol();
	this.scheme = request.getScheme();
	
	
	/*
	 * have to comment out below two lines as otherwise web socket will
	 * report UnSupportedOperationException upon connection
	 */
	//this.characterEncoding = request.getCharacterEncoding();
	//this.contentType = request.getContentType();
	//this.requestedSessionId = request.getRequestedSessionId();
	this.characterEncoding = null;
	this.contentType = null;
	this.requestedSessionId = null;
	
	this.locale = request.getLocale();
	this.locales = request.getLocales();
	this.isSecure = request.isSecure();
	this.remoteUser = request.getRemoteUser();
	this.remoteAddr = request.getRemoteAddr();
	this.remoteHost = request.getRemoteHost();
	this.remotePort = request.getRemotePort();
	this.localAddr = request.getLocalAddr();
	this.localName = request.getLocalName();
	this.localPort = request.getLocalPort();
	this.pathTranslated = request.getPathTranslated();
	this.principal = request.getUserPrincipal();

	HttpSession session = request.getSession(true);
	httpSession = new HttpSessionCopy(session);

	String s;
	Enumeration<String> e = request.getHeaderNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		Enumeration<String> headerValues = request.getHeaders(s);
		this.headers.put(s, headerValues);
	}

	e = request.getAttributeNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		attributes.put(s, request.getAttribute(s));
	}

	e = request.getParameterNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		parameters.put(s, request.getParameterValues(s));
	}
}
 
源代码14 项目: choerodon-starters   文件: HttpRequestUtils.java
/**
 * Build a String containing a multi-line dump of an HTTP request.
 *
 * @param fromMethod      the method that this method was called from
 * @param request         the HTTP request build the request dump from
 * @param includePostData if true will include the POST data in the dump
 * @return a String containing a multi-line dump of the HTTP request, If an error occurs,
 * the message from the exception will be returned
 */
public static String getRequestDump(String fromMethod, HttpServletRequest request, boolean includePostData) {

    String shortDump = getShortRequestDump(fromMethod, request);
    StringBuilder buf = new StringBuilder(shortDump);
    try {

        buf.append("\nAttributes:\n");
        Enumeration<String> attrs = request.getAttributeNames();
        while (attrs.hasMoreElements()) {
            String attr = attrs.nextElement();
            buf.append("\t").append(attr).append(": ").append(request.getAttribute(attr)).append('\n');
        }

        buf.append("\nHeaders:\n");
        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()) {
            String header = headers.nextElement();
            buf.append("\t").append(header).append(": ").append(request.getHeader(header)).append('\n');
        }

        buf.append("\nParameters:\n");
        Enumeration<String> params = request.getParameterNames();
        while (params.hasMoreElements()) {
            String param = params.nextElement();
            buf.append("\t").append(param).append(": ").append(request.getParameter(param)).append('\n');
        }

        buf.append("\nCookies:\n");
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                String cstr = "\t" + cookie.getDomain() + "." + cookie.getPath() + "." + cookie.getName() + ": " + cookie.getValue() + "\n";
                buf.append(cstr);
            }
        }

        if (includePostData) {
            buf.append(getPostDataAsString(request)).append("\n");
        }

        return (buf.toString());

    } catch (IOException e) {
        return e.getMessage();
    }
}
 
源代码15 项目: olat   文件: DefaultServlet.java
/**
 * Show HTTP header information.
 */
protected void showRequestInfo(HttpServletRequest req) {

    System.out.println();
    System.out.println("SlideDAV Request Info");
    System.out.println();

    // Show generic info
    System.out.println("Encoding : " + req.getCharacterEncoding());
    System.out.println("Length : " + req.getContentLength());
    System.out.println("Type : " + req.getContentType());

    System.out.println();
    System.out.println("Parameters");

    Enumeration parameters = req.getParameterNames();

    while (parameters.hasMoreElements()) {
        String paramName = (String) parameters.nextElement();
        String[] values = req.getParameterValues(paramName);
        System.out.print(paramName + " : ");
        for (int i = 0; i < values.length; i++) {
            System.out.print(values[i] + ", ");
        }
        System.out.println();
    }

    System.out.println();

    System.out.println("Protocol : " + req.getProtocol());
    System.out.println("Address : " + req.getRemoteAddr());
    System.out.println("Host : " + req.getRemoteHost());
    System.out.println("Scheme : " + req.getScheme());
    System.out.println("Server Name : " + req.getServerName());
    System.out.println("Server Port : " + req.getServerPort());

    System.out.println();
    System.out.println("Attributes");

    Enumeration attributes = req.getAttributeNames();

    while (attributes.hasMoreElements()) {
        String attributeName = (String) attributes.nextElement();
        System.out.print(attributeName + " : ");
        System.out.println(req.getAttribute(attributeName).toString());
    }

    System.out.println();

    // Show HTTP info
    System.out.println();
    System.out.println("HTTP Header Info");
    System.out.println();

    System.out.println("Authentication Type : " + req.getAuthType());
    System.out.println("HTTP Method : " + req.getMethod());
    System.out.println("Path Info : " + req.getPathInfo());
    System.out.println("Path translated : " + req.getPathTranslated());
    System.out.println("Query string : " + req.getQueryString());
    System.out.println("Remote user : " + req.getRemoteUser());
    System.out.println("Requested session id : " + req.getRequestedSessionId());
    System.out.println("Request URI : " + req.getRequestURI());
    System.out.println("Context path : " + req.getContextPath());
    System.out.println("Servlet path : " + req.getServletPath());
    System.out.println("User principal : " + req.getUserPrincipal());

    System.out.println();
    System.out.println("Headers : ");

    Enumeration headers = req.getHeaderNames();

    while (headers.hasMoreElements()) {
        String headerName = (String) headers.nextElement();
        System.out.print(headerName + " : ");
        System.out.println(req.getHeader(headerName));
    }

    System.out.println();
    System.out.println();

}
 
源代码16 项目: lams   文件: WebResource.java
private String deriveUsefulInfo()
{
   if(servletRequest instanceof HttpServletRequest == false)
      return " ";
   
   HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
   StringBuilder sb = new StringBuilder();
   sb.append("[").append(httpRequest.getContextPath());
   //Append cookies
   if(auditFlag.contains("cookies"))
   {
      sb.append(":cookies=").append(Arrays.toString(httpRequest.getCookies()));   
   }
   //Append Header information
   if(auditFlag.contains("headers"))
   {
      sb.append(":headers=");
      Enumeration<?> en = httpRequest.getHeaderNames();
      for(;en.hasMoreElements();)
      {
         String headerName = (String)en.nextElement();
         sb.append(headerName).append("="); 
         if(headerName.contains("authorization") == false)
            sb.append(httpRequest.getHeader(headerName)).append(",");
      }
      sb.append("]");         
   }
   
   //Append Request parameter information
   if(auditFlag.contains("parameters"))
   {
      sb.append("[parameters=");
      Enumeration<?> enparam = httpRequest.getParameterNames();
      for(;enparam.hasMoreElements();)
      {
         String paramName = (String)enparam.nextElement();
         sb.append(paramName).append("=");
         if (paramName.equalsIgnoreCase("j_password"))
         {
            sb.append("***");
         }
         else
         {
            String[] paramValues = httpRequest.getParameterValues(paramName);
            int len = paramValues != null ? paramValues.length : 0;
            for(int i = 0 ; i < len ; i++)
               sb.append(paramValues[i]).append("::");
         }
         sb.append(",");
      }
   } 
   //Append Request attribute information
   if(auditFlag.contains("attributes"))
   {
      sb.append("][attributes=");
      Enumeration<?> enu = httpRequest.getAttributeNames();
      for(;enu.hasMoreElements();)
      {
         String attrName = (String)enu.nextElement();
         sb.append(attrName).append("=");
         sb.append(httpRequest.getAttribute(attrName)).append(",");
      }
   }
   sb.append("]");
   return sb.toString();
}
 
源代码17 项目: sakai   文件: XSLTEntityHandler.java
public void addRequestAttributes(ContentHandler ch, HttpServletRequest request)
		throws Exception
{
	if (!isAvailable()) return;

	// add the attributes
	AttributesImpl dummyAttributes = new AttributesImpl();
	ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_ATTRIBUTES,
			SchemaNames.EL_NSREQUEST_ATTRIBUTES, dummyAttributes);
	for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();)
	{
		String name = (String) e.nextElement();
		Object attr = request.getAttribute(name);
		AttributesImpl propA = new AttributesImpl();
		propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$
				SchemaNames.ATTR_NAME, "string", name); //$NON-NLS-1$
		if (attr instanceof Object[])
		{
			Object[] oattr = (Object[]) attr;
			ch.startElement(SchemaNames.NS_CONTAINER,
					SchemaNames.EL_REQUEST_ATTRIBUTE,
					SchemaNames.EL_NSREQUEST_ATTRIBUTE, propA);
			for (int i = 0; i < oattr.length; i++)
			{
				addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_VALUE,
						SchemaNames.EL_NSVALUE, dummyAttributes, oattr[i]);
			}
			ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_ATTRIBUTE,
					SchemaNames.EL_NSREQUEST_ATTRIBUTE);
		}
		else
		{
			ch.startElement(SchemaNames.NS_CONTAINER,
					SchemaNames.EL_REQUEST_ATTRIBUTE,
					SchemaNames.EL_NSREQUEST_ATTRIBUTE, propA);
			addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_VALUE,
					SchemaNames.EL_NSVALUE, dummyAttributes, attr);
			ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_ATTRIBUTE,
					SchemaNames.EL_NSREQUEST_ATTRIBUTE);
		}
	}

	ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_ATTRIBUTES,
			SchemaNames.EL_NSREQUEST_ATTRIBUTES);
}
 
源代码18 项目: mdw   文件: WebAppContext.java
/**
 * Request info for System REST service.
 */
public static SysInfoCategory getRequestInfo(HttpServletRequest request) {
    List<SysInfo> requestInfos = new ArrayList<SysInfo>();
    requestInfos.add(new SysInfo("Method", request.getMethod()));
    requestInfos.add(new SysInfo("URL", request.getRequestURL().toString()));
    requestInfos.add(new SysInfo("Protocol", request.getProtocol()));
    requestInfos.add(new SysInfo("Servlet path", request.getServletPath()));
    requestInfos.add(new SysInfo("Context path", request.getContextPath()));
    requestInfos.add(new SysInfo("Path info", request.getPathInfo()));
    requestInfos.add(new SysInfo("Path translated", request.getPathTranslated()));
    requestInfos.add(new SysInfo("Query string", request.getQueryString()));
    requestInfos.add(new SysInfo("Content length: ", String.valueOf(request.getContentLength())));
    requestInfos.add(new SysInfo("Content type: ", request.getContentType()));
    requestInfos.add(new SysInfo("Server name", request.getServerName()));
    requestInfos.add(new SysInfo("Server port", String.valueOf(request.getServerPort())));
    requestInfos.add(new SysInfo("Remote user", request.getRemoteUser()));
    requestInfos.add(new SysInfo("Remote address", request.getRemoteAddr()));
    requestInfos.add(new SysInfo("Remote host", request.getRemoteHost()));
    requestInfos.add(new SysInfo("Authorization type", request.getAuthType()));
    requestInfos.add(new SysInfo("Locale", String.valueOf(request.getLocale())));

    SysInfo paramInfo = new SysInfo("Parameters");
    Enumeration<?> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = (String)paramNames.nextElement();
        paramInfo.addSysInfo(new SysInfo(paramName, request.getParameter(paramName)));
    }
    requestInfos.add(paramInfo);

    SysInfo headerInfo = new SysInfo("Headers");
    Enumeration<?> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String)headerNames.nextElement();
        headerInfo.addSysInfo(new SysInfo(headerName, request.getHeader(headerName)));
    }
    requestInfos.add(headerInfo);

    SysInfo attrInfo = new SysInfo("Attributes");
    Enumeration<?> attrNames = request.getAttributeNames();
    while (attrNames.hasMoreElements()) {
        String attrName = (String)attrNames.nextElement();
        attrInfo.addSysInfo(new SysInfo(attrName, String.valueOf(request.getAttribute(attrName))));
    }
    requestInfos.add(attrInfo);

    return new SysInfoCategory("Request Details", requestInfos);
}
 
源代码19 项目: thymeleaf-spring-data-dialect   文件: PageUtils.java
public static Page<?> findPage(final ITemplateContext context) {
    // 1. Get Page object from local variables (defined with sd:page-object)
    // 2. Search Page using ${page} expression
    // 3. Search Page object as request attribute

    final Object pageFromLocalVariable = context.getVariable(Keys.PAGE_VARIABLE_KEY);
    if (isPageInstance(pageFromLocalVariable)) {
        return (Page<?>) pageFromLocalVariable;
    }

    // Check if not null and Page instance available with ${page} expression
    final IEngineConfiguration configuration = context.getConfiguration();
    final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
    final IStandardExpression expression = parser.parseExpression(context, Keys.PAGE_EXPRESSION);
    final Object page = expression.execute(context);
    if (isPageInstance(page)) {
        return (Page<?>) page;
    }

    // Search for Page object, and only one instance, as request attribute
    if (context instanceof IWebContext) {
        HttpServletRequest request = ((IWebContext) context).getRequest();
        Enumeration<String> attrNames = request.getAttributeNames();
        Page<?> pageOnRequest = null;
        while (attrNames.hasMoreElements()) {
            String attrName = (String) attrNames.nextElement();
            Object attr = request.getAttribute(attrName);
            if (isPageInstance(attr)) {
                if (pageOnRequest != null) {
                    throw new InvalidObjectParameterException("More than one Page object found on request!");
                }

                pageOnRequest = (Page<?>) attr;
            }
        }

        if (pageOnRequest != null) {
            return pageOnRequest;
        }
    }

    throw new InvalidObjectParameterException("Invalid or not present Page object found on request!");
}
 
源代码20 项目: gitlab4j-api   文件: HttpRequestUtils.java
/**
 * Build a String containing a multi-line dump of an HTTP request.
 * 
 * @param fromMethod the method that this method was called from
 * @param request the HTTP request build the request dump from
 * @param includePostData if true will include the POST data in the dump
 * @return a String containing a multi-line dump of the HTTP request, If an error occurs,
 * the message from the exception will be returned
 */
public static String getRequestDump(String fromMethod, HttpServletRequest request, boolean includePostData) {

    String shortDump = getShortRequestDump(fromMethod, request);
    StringBuilder buf = new StringBuilder(shortDump);
    try {

        buf.append("\nAttributes:\n");
        Enumeration<String> attrs = request.getAttributeNames();
        while (attrs.hasMoreElements()) {
            String attr = attrs.nextElement();
            buf.append("\t").append(attr).append(": ").append(request.getAttribute(attr)).append('\n');
        }

        buf.append("\nHeaders:\n");
        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()) {
            String header = headers.nextElement();
            buf.append("\t").append(header).append(": ").append(request.getHeader(header)).append('\n');
        }

        buf.append("\nParameters:\n");
        Enumeration<String> params = request.getParameterNames();
        while (params.hasMoreElements()) {
            String param = params.nextElement();
            buf.append("\t").append(param).append(": ").append(request.getParameter(param)).append('\n');
        }

        buf.append("\nCookies:\n");
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                String cstr = "\t" + cookie.getDomain() + "." + cookie.getPath() + "." + cookie.getName() + ": " + cookie.getValue() + "\n";
                buf.append(cstr);
            }
        }

        if (includePostData) {
            buf.append(getPostDataAsString(request)).append("\n");
        }

        return (buf.toString());

    } catch (IOException e) {
        return e.getMessage();
    }
}