本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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";
}
示例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;
}
};
}
示例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());
}
示例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;
}
示例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;
}
示例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");
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
};
}
示例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;
}