當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletRequest.getHeaderNames方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getHeaderNames方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getHeaderNames方法的具體用法?Java HttpServletRequest.getHeaderNames怎麽用?Java HttpServletRequest.getHeaderNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getHeaderNames方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createHeaders

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private List<HttpRequestHeader> createHeaders(HttpServletRequest request) {
    List<HttpRequestHeader> headers = Collections.emptyList();
    Enumeration<String> names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String value = request.getHeader(name);
        ImmutableHttpRequestHeader header = ImmutableHttpRequestHeader
                .builder()
                .setName(name)
                .setValue(value)
                .build();
        if (headers.isEmpty()) {
            headers = new ArrayList<HttpRequestHeader>();
        }
        headers.add(header);
    }
    return headers;
}
 
開發者ID:vy,項目名稱:hrrs,代碼行數:19,代碼來源:HrrsFilter.java

示例2: echoHeaders

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = "/headers", method = {GET, POST})
public Map<String, Object> echoHeaders(HttpServletRequest request) {
    Map<String, Object> map = new LinkedHashMap<>();
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        Enumeration<String> headerValues = request.getHeaders(headerName);
        List<String> list = new ArrayList();
        while (headerValues.hasMoreElements()) {
            String headerValue = headerValues.nextElement();
            list.add(headerValue);
        }
        map.put(headerName.toLowerCase(), list);
    }
    return map;
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:17,代碼來源:SearchController.java

示例3: getHeadersInfo

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * 獲取header信息
 */
private Map<String, String> getHeadersInfo(HttpServletRequest request) {
    Map<String, String> map = new HashMap<>();
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String key = (String) headerNames.nextElement();
        String value = request.getHeader(key);
        map.put(key, value);
    }
    System.out.println(map);
    return map;
}
 
開發者ID:lucid-lynxz,項目名稱:Webhook_server,代碼行數:15,代碼來源:ApiServlet.java

示例4: loginPointcut

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Before("classPointcut() && loginPointcut() && args(model,req) && @annotation(mapping)")
public String browserCheck(JoinPoint joinPoint, Model model, HttpServletRequest req, RequestMapping mapping) throws ServletException, IOException{
	
   // IP Address checking -- TO DO LIST
      // String ipAddress = req.getRemoteAddr();
   logger.info("executing " + joinPoint.getSignature().getName());
   logger.warn("MVC application trying to check browser type...");
      String loginRequestMethod = mapping.method()[0].name();
      String username = req.getParameter("username");
   String password = req.getParameter("password");
 
   req.setAttribute("username", username);
   req.setAttribute("password", password);
   
   logger.info("executing " + joinPoint.getSignature().getName() + " which is a " + loginRequestMethod + " request");
      if(loginRequestMethod.equalsIgnoreCase("GET")){
   	    Enumeration<String> headers = req.getHeaderNames();
           while(headers.hasMoreElements()){
           	String headerName = headers.nextElement(); 	
           	if(headerName.equalsIgnoreCase("user-agent")){
           	     String browserType = req.getHeader(headerName);
           	     if(browserType.contains("Chrome")){
           	    	req.setAttribute("browserNo", 1);   
           	    	logger.info("MVC application uses Chrome...");
           	     }else if (browserType.contains("Firefox")){
           	    	 req.setAttribute("browserNo", 2);
           	    	 logger.info("MVC application uses Firefox...");
           	     }else{
           	    	 req.setAttribute("browserNo", 3);
           	    	 logger.info("MVC application stops because browser not supported...");
           	     }
           	   break;
           	}
           }
      }
	return "login";
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:38,代碼來源:LoginProxyAspect.java

示例5: createHeaderMap

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 *
 * Creates the Map that maps header name to single header
 * value.
 **/
public static Map<String, String> createHeaderMap (PageContext pContext)
{
  final HttpServletRequest request =
    (HttpServletRequest) pContext.getRequest ();
  return new EnumeratedMap<String, String> ()
    {
      public Enumeration<String> enumerateKeys () 
      {
        return request.getHeaderNames ();
      }

      public String getValue (Object pKey) 
      {
        if (pKey instanceof String) {
          return request.getHeader ((String) pKey);
        }
        else {
          return null;
        }
      }

      public boolean isMutable ()
      {
        return false;
      }
    };
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:33,代碼來源:ImplicitObjectELResolver.java

示例6: log

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private void log(HttpServletRequest request, HttpServletResponse response) {
    long duration = 0;
    try {
        final Long requestStartTime = (Long) request.getAttribute(START_TIME);
        if (requestStartTime!=null && requestStartTime > 0) {
            duration = System.currentTimeMillis() - requestStartTime;
        }
    } catch (Exception x) {
        log.warn("Could not get request start time {}", x);
    }

    final StringBuilder httpHeaders = new StringBuilder('[');
    for (final Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements(); ) {
        final String headerName = headerNames.nextElement();
        httpHeaders.append('[').append(headerName).append(": ").append(request.getHeader(headerName)).append("], ");
    }
    httpHeaders.append(']');

    final StringBuffer requestStringBuffer = request.getRequestURL();

    if (request.getQueryString() != null && !request.getQueryString().isEmpty()) {
        requestStringBuffer.append("?").append(request.getQueryString());
    }

    Metrics.reportGatewayRedirectDurationStats(duration);

    log.info("Request: {} {} agent={} status={} duration={} HTTP Headers={}",
            request.getMethod(), requestStringBuffer,
            request.getHeader("User-Agent"),
            response.getStatus(),
            duration != 0 ? duration : "unknown",
            httpHeaders.toString());
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:34,代碼來源:AccessLoggingFilter.java

示例7: getHeadersInfo

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private Map<String, String> getHeadersInfo(HttpServletRequest request) {
    Map<String, String> map = new HashMap<>();
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String key = (String) headerNames.nextElement();
        String value = request.getHeader(key);
        map.put(key, value);
    }
    return map;
}
 
開發者ID:nellochen,項目名稱:springboot-start,代碼行數:11,代碼來源:WebLogAspect.java

示例8: extractRequestHeader

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * 從HttpServletRequest中提取請求頭信息
 * @param request
 * @param loggingContext
 * @return
 */
protected Map<String,String> extractRequestHeader(HttpServletRequest request, LoggingContext loggingContext) {
	Map<String,String> headerMap = new HashMap<String,String>();
	Enumeration<String> headerNames = request.getHeaderNames();
	if(headerNames != null){
		while(headerNames.hasMoreElements()){
			String headerName = headerNames.nextElement();
			headerMap.put(headerName, request.getHeader(headerName));
		}
	}
	return headerMap;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:18,代碼來源:AbstractHttpAccessLoggingInterceptor.java

示例9: showHeaders

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 *  Debugging 
 *
 * @param  request  the request
 */
private void showHeaders(HttpServletRequest request) {
	prtln("\n REQUEST HEADERS");
	Enumeration headerNames = request.getHeaderNames();
	while (headerNames.hasMoreElements()) {
		String name = (String) headerNames.nextElement();
		prtln(name + ": " + request.getHeader(name));
	}
	prtln("-----------\n");
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:15,代碼來源:UserInfoAction.java

示例10: showRequestHeaders

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 *  Display request headers for debugging.
 *
 * @param  request  Description of the Parameter
 */
public static void showRequestHeaders(HttpServletRequest request) {
	if (debug) {
		prtln("Request Headers");
		for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); ) {
			String header = (String) e.nextElement();
			String value = request.getHeader(header);
			System.out.println("\t" + header + ": " + value);
		}
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:16,代碼來源:SchemEditUtils.java

示例11: ola

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@CrossOrigin
@RequestMapping(method = RequestMethod.GET, value = "/ola", produces = "text/plain")
@ApiOperation("Returns the greeting in Portuguese")
public String ola(HttpServletRequest request) {
  String hostname = System.getenv().getOrDefault("HOSTNAME", "Unknown");
  Enumeration<String> headerNames = request.getHeaderNames();

  StringBuffer headerMsg = new StringBuffer("{");

  while (headerNames.hasMoreElements()) {
    String headerName = headerNames.nextElement();
    String headerValue = request.getHeader(headerName);
    if (headerValue != null) {
      headerMsg.append(String.format("{\"%s\":\"%s\"}", headerName, headerValue));
      headerMsg.append(",");
    }
  }

  headerMsg.append("}");

  log.info("Request Headers:{}", headerMsg);
  return String.format("Olá de %s", hostname);
}
 
開發者ID:redhat-developer-demos,項目名稱:istio-ola,代碼行數:24,代碼來源:OlaController.java

示例12: gatherHttpHeaders

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
protected Map<String, String> gatherHttpHeaders(HttpServletRequest req) {
    Map<String, String> headers = new HashMap<>();

    Enumeration<String> headerNames = req.getHeaderNames();
    if (headerNames == null) {
        return headers;
    }

    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        Enumeration<String> headerValues = req.getHeaders(headerName);
        if (headerValues == null) {
            continue;
        }

        String headerNameLower = headerName.toLowerCase();
        if (! blackListedHeaders.contains(headerNameLower)) {
            if (headerValues.hasMoreElements()) {
                headers.put(headerNameLower, headerValues.nextElement());
            }

            while (headerValues.hasMoreElements()) {
                logger.debug("Duplicate http-header, discarding: {} = {}", headerName, headerValues.nextElement());
            }
        } else {
            logger.trace("Blocking header {}", headerNameLower);
        }
    }

    return headers;
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:32,代碼來源:RpcHandler.java

示例13: printHttpHeader

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static void printHttpHeader(HttpServletRequest request) {
	Enumeration<String> headerNames = request.getHeaderNames();
	while (headerNames.hasMoreElements()) {
		String key = (String) headerNames.nextElement();
		String value = request.getHeader(key);
		log.debug(key + ":" + value);
	}
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:10,代碼來源:ServletUtils.java

示例14: createHeadersMap

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 *
 * Creates the Map that maps header name to an array of header
 * values.
 **/
public static Map<String, String[]> createHeadersMap (PageContext pContext)
{
  final HttpServletRequest request =
    (HttpServletRequest) pContext.getRequest ();
  return new EnumeratedMap<String, String[]> ()
    {
      public Enumeration<String> enumerateKeys () 
      {
        return request.getHeaderNames ();
      }

      public String[] getValue (Object pKey) 
      {
        if (pKey instanceof String) {
          // Drain the header enumeration
          List<String> l = new ArrayList<String> ();
          Enumeration<String> e = request.getHeaders ((String) pKey);
          if (e != null) {
            while (e.hasMoreElements ()) {
              l.add (e.nextElement ());
            }
          }
          return l.toArray (new String [l.size ()]);
        }
        else {
          return null;
        }
      }

      public boolean isMutable ()
      {
        return false;
      }
    };
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:41,代碼來源:ImplicitObjectELResolver.java

示例15: preHandle

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response,
    final Object handler) throws Exception {
  final Map<String, String> requestParameterValues = new HashMap<String, String>();

  for (Enumeration<String> requestParameters = request.getParameterNames(); requestParameters
      .hasMoreElements();) {
    final String requestParameter = requestParameters.nextElement();
    if (requestParameter.startsWith(ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX)) {
      String requestValue = request.getParameter(requestParameter);
      // GEODE-1469: since we enced stepArgs, we will need to decode it here. See
      // #ClientHttpRequest
      if (requestParameter.contains(CLIMultiStepHelper.STEP_ARGS)) {
        requestValue = UriUtils.decode(requestValue);
      }
      requestParameterValues.put(
          requestParameter.substring(ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX.length()),
          requestValue);
    }
  }



  for (Enumeration<String> requestHeaders = request.getHeaderNames(); requestHeaders
      .hasMoreElements();) {

    // since http request headers are case-insensitive and all our security-* properties
    // are in lower case, it's safe to do toLowerCase here.
    final String requestHeader = requestHeaders.nextElement().toLowerCase();

    if (requestHeader.startsWith(SECURITY_VARIABLE_REQUEST_HEADER_PREFIX)) {
      requestParameterValues.put(requestHeader, request.getHeader(requestHeader));
    }
  }

  String username = requestParameterValues.get(ResourceConstants.USER_NAME);
  String password = requestParameterValues.get(ResourceConstants.PASSWORD);
  this.securityService.login(username, password);

  ENV.set(requestParameterValues);

  return true;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:44,代碼來源:LoginHandlerInterceptor.java


注:本文中的javax.servlet.http.HttpServletRequest.getHeaderNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。