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:am.ik.categolj2.core.web.RemoteAddresses.java

public static String getRemoteAddress(HttpServletRequest request) {
    String forwardedFor = request.getHeader(HttpHeaders.X_FORWARDED_FOR);
    String result;//w ww  .j  a va2 s.c  om
    if (forwardedFor != null) {
        result = forwardedFor;
    } else {
        result = request.getRemoteAddr();
    }
    return StringUtils.substring(result, 0, 128);
}

From source file:com.ms.app.web.commons.utils.InvokeTypeTools.java

public static boolean isAjax(HttpServletRequest request) {
    String type = request.getHeader(INVOKE_TYPE);
    return InvokeType.isAjax(type);
}

From source file:com.ms.app.web.commons.utils.InvokeTypeTools.java

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

From source file:com.djt.utils.RequestUtils.java

/**
 * ?IP?//from ww  w .  ja v a 2  s  . com
 */
public static String getRequestIp(HttpServletRequest request) {
    String ip = request.getHeader("X-Forwarded-For");
    if (StringUtils.isNotEmpty(ip) && "unKnown".equalsIgnoreCase(ip)) {
        //?????IPIP?IP
        int index = ip.indexOf(", ");
        if (index != -1) {
            return ip.substring(0, index);
        } else {
            return ip;
        }
    }
    ip = request.getHeader("X-Real-IP");
    if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) {
        return ip;
    }
    return request.getRemoteAddr();
}

From source file:am.ik.categolj2.core.web.UserAgents.java

public static String getUserAgent(HttpServletRequest request) {
    String userAgent = StringUtils.substring(request.getHeader(HttpHeaders.USER_AGENT), 0, 256);
    return userAgent;
}

From source file:com.netflix.spinnaker.gate.interceptors.RequestLoggingInterceptor.java

private static String sourceIpAddress(HttpServletRequest request) {
    String ip = request.getHeader("X-FORWARDED-FOR");
    if (ip == null) {
        return request.getRemoteAddr();
    }//  w  ww  .j  a  v  a 2  s . c  om
    return ip;
}

From source file:com.ms.app.web.commons.utils.DeviceUtils.java

/**
 * ?UA??//from w w  w  .  j ava  2s. c  o m
 * 
 * @param ua
 * @return
 */
public static WebBrowserEnum getBowser(HttpServletRequest request) {
    return request == null ? null : getBowser(request.getHeader(USER_AGENT));
}

From source file:com.jmu.util.ResponseJsonUtils.java

public static boolean isJsonAccept(HttpServletRequest request) {
    if (request.getHeader("accept").indexOf("application/json") > -1
            || (request.getHeader("X-Requested-With") != null
                    && request.getHeader("X-Requested-With").indexOf("XMLHttpRequest") > -1)) {
        return true;
    }//from w w w . j av a 2  s .  co  m
    return false;
}

From source file:com.iflytek.edu.cloud.frame.utils.ServiceUtil.java

public static String getRemoteAddr(HttpServletRequest request) {
    String remoteIp = request.getHeader(X_REAL_IP); //nginx????  
    if (StringUtils.hasText(remoteIp)) {
        return remoteIp;
    } else {//from  w  ww  .ja v  a  2s .  com
        remoteIp = request.getHeader(X_FORWARDED_FOR);//apache???  
        if (StringUtils.hasText(remoteIp)) {
            String[] ips = remoteIp.split(",");
            for (String ip : ips) {
                if (!"null".equalsIgnoreCase(ip)) {
                    return ip;
                }
            }
        }
        return request.getRemoteAddr();
    }
}

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

public static boolean isAjax(HttpServletRequest request) {
    return InvokeType.isAjax(request.getHeader(INVOKE_TYPE))
            || "XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"));
}