Example usage for javax.servlet.http HttpServletRequest getHeader

List of usage examples for javax.servlet.http HttpServletRequest getHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getHeader.

Prototype

public String getHeader(String name);

Source Link

Document

Returns the value of the specified request header as a String.

Usage

From source file:com.fengduo.bee.web.utils.InvokeTypeTools.java

public static InvokeType getInvokeType(HttpServletRequest request) {
    return InvokeType.getEnum(request.getHeader(INVOKE_TYPE));
}

From source file:com.onehippo.gogreen.utils.UserAgentUtils.java

public static boolean isMobile(HttpServletRequest request) {
    String userAgent = request.getHeader("User-Agent");
    if (StringUtils.isEmpty(userAgent)) {
        return false;
    }//from   ww w. jav  a2  s  .c o m
    for (final Pattern pattern : mobileUserAgentPatterns) {
        final Matcher matcher = pattern.matcher(userAgent);
        if (matcher.find()) {
            return true;
        }
    }

    return false;
}

From source file:com.neocotic.blingaer.common.RequestUtils.java

/**
 * Returns the referrer of the specified {@code request}.
 * /*from w  w  w . j a  va2s  .  c o  m*/
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return the referrer
 */
public static String getReferrer(HttpServletRequest request) {
    return request.getHeader("Referer");
}

From source file:com.neocotic.blingaer.common.RequestUtils.java

/**
 * Returns the user agent of the specified {@code request}.
 * //from w  ww  .j  ava 2s. com
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return the user agent
 */
public static String getUserAgent(HttpServletRequest request) {
    return request.getHeader("User-Agent");
}

From source file:org.owasp.webgoat.plugin.challenge1.Assignment1.java

public static boolean containsHeader(HttpServletRequest request) {
    return StringUtils.hasText(request.getHeader("X-Forwarded-For"));

}

From source file:net.duckling.ddl.util.ClientValidator.java

public static String getRealIp(HttpServletRequest request) {
    String nginxIp = request.getHeader("x-real-ip");
    if (StringUtils.isNotEmpty(nginxIp)) {
        return nginxIp;
    }//from ww w . j  a v  a 2s. co  m
    return request.getRemoteAddr();
}

From source file:com.qing.common.util.IPUtils.java

/**
 * ?IP?s/* w  w  w . j a v a2  s  . c o  m*/
 * 
 * @param request
 * @return IP?
 */
public static String getRemoteIp(HttpServletRequest request) {
    String ipString = request.getHeader("x-forwarded-for");
    if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) {
        ipString = request.getHeader("Proxy-Client-IP");
    }
    if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) {
        ipString = request.getHeader("WL-Proxy-Client-IP");
    }
    if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) {
        ipString = request.getRemoteAddr();
    }

    // ??unknownip
    final String[] arr = ipString.split(",");
    for (final String str : arr) {
        if (!"unknown".equalsIgnoreCase(str)) {
            ipString = str;
            break;
        }
    }

    return ipString;
}

From source file:com.enonic.cms.web.portal.instanttrace.InstantTraceRequestInspector.java

public static boolean isClientEnabled(final HttpServletRequest request) {
    return "true".equals(request.getHeader("X-Instant-Trace-Enabled"));
}

From source file:com.fengduo.bee.commons.util.HttpUtil.java

/**
 * ?ip<br>/*from w ww . j av a 2 s  .c  o  m*/
 * ip?x-forwarded-for??remoteAddr
 * 
 * @param request
 * @return
 */
public static String getIpAddr(HttpServletRequest request) {
    String ip = request.getHeader("X-Forwarded-For");
    if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
        return ip;
    }
    // X-Real-IP
    // Proxy-Client-IP
    // WL-Proxy-Client-IP
    return request.getRemoteAddr();
}

From source file:com.neocotic.blingaer.common.RequestUtils.java

/**
 * Returns the IP address that appears to be the source of the specified
 * {@code request}./* ww  w.j av a  2  s .c o m*/
 * 
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return the IP address
 */
public static String getIpAddress(HttpServletRequest request) {
    String ipAddress = request.getHeader("X-Forwarded-For");

    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    } else {
        String[] ipAddresses = StringUtils.split(ipAddress, ",");

        if (ipAddresses.length > 0) {
            ipAddress = ipAddresses[0];
        }
    }

    return ipAddress;
}