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.cloud.servlet.StaticResourceServlet.java

static boolean isClientCompressionSupported(final HttpServletRequest req) {
    return StringUtils.contains(req.getHeader("Accept-Encoding"), "gzip");
}

From source file:com.tang.util.RequestBeanKit.java

public static String getIp(HttpServletRequest request) {
    String remoteAddr = request.getHeader("X-Real-IP");
    if (remoteAddr == null) {
        remoteAddr = request.getHeader("X-Forwarded-For");
    }//from  w  w w .  j a v  a 2 s.  c o m
    if (remoteAddr == null) {
        remoteAddr = request.getRemoteAddr();
    }
    return remoteAddr;
}

From source file:architecture.ee.web.util.ServletUtils.java

public static String getDomainName(HttpServletRequest request, boolean opt) {
    String url = request.getHeader("Referer");

    return getDomainName(url, opt);
}

From source file:com.neocotic.bloggaer.common.Requests.java

/**
 * Returns the referrer of the specified {@code request}.
 * /*from   w w w  .  j  a  v a  2 s .  c om*/
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return The referrer.
 */
public static String getReferrer(HttpServletRequest request) {
    logger.entering(request);

    String referrer = request.getHeader("Referer");

    logger.exiting(referrer);
    return referrer;
}

From source file:com.neocotic.bloggaer.common.Requests.java

/**
 * Returns the user agent of the specified {@code request}.
 * //  w  w  w. j  a va 2  s .  c o  m
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return The user agent.
 */
public static String getUserAgent(HttpServletRequest request) {
    logger.entering(request);

    String userAgent = request.getHeader("User-Agent");

    logger.exiting(userAgent);
    return userAgent;
}

From source file:io.renren.common.utils.IPUtils.java

/**
 * ?IP?//from   ww w  .j  a  va 2  s .  c om
 * 
 * Nginx???? ?request.getRemoteAddr()?IP?
 * ?????X-Forwarded-For?IP?X-Forwarded-For?unknownIPIP?
 */
public static String getIpAddr(HttpServletRequest request) {
    String ip = null;
    try {
        ip = request.getHeader("x-forwarded-for");
        if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
    } catch (Exception e) {
        logger.error("IPUtils ERROR ", e);
    }

    //        //??IP?
    //        if(StringUtils.isEmpty(ip) && ip.length() > 15) {
    //         if(ip.indexOf(",") > 0) {
    //            ip = ip.substring(0, ip.indexOf(","));
    //         }
    //      }

    return ip;
}

From source file:de.itsvs.cwtrpc.core.CwtRpcUtils.java

public static boolean containsStrongName(HttpServletRequest request) {
    return (request.getHeader(RpcRequestBuilder.STRONG_NAME_HEADER) != null);
}

From source file:com.lll.util.SpringSecurityUtils.java

public static String getIpAddr(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
        //System.out.println(ip);
    }//  w ww  . j  av  a  2  s .  com
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
        //System.out.println(ip);
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
        //System.out.println(ip);
    }
    return ip;
}

From source file:com.neocotic.bloggaer.common.Requests.java

/**
 * Returns the IP address that appears to be the source of the specified {@code request}.
 * /*from  ww  w  . j a  v  a  2 s .  com*/
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return The IP address.
 */
public static String getIpAddress(HttpServletRequest request) {
    logger.entering(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];
    }

    logger.exiting(ipAddress);
    return ipAddress;
}

From source file:com.esri.gpt.framework.http.CredentialProvider.java

/**
 * Establishes a thread local instance of credentials based upon authorization
 * credentials found within the HTTP request header.
 * <p/>//from ww w .  ja v  a 2  s .com
 * The general pattern is to challenge the UI client (browser) to provide credentials for
 * accessing a remote server.
 * @param request the executing HTTP servlet request
 * @return the extablished thread local instance (null if authorization credentials were not found)
 */
public static CredentialProvider establishThreadLocalInstance(HttpServletRequest request) {
    String sAuthorization = request.getHeader("Authorization");
    if (sAuthorization != null) {
        if (sAuthorization.startsWith("Basic ")) {
            sAuthorization = sAuthorization.substring(6);
            if (sAuthorization.length() > 0) {
                String sDecoded = new String(Base64.decodeBase64(sAuthorization.getBytes()));
                int nIdx = sDecoded.indexOf(':');
                if (nIdx > 0) {
                    String user = sDecoded.substring(0, nIdx);
                    String pwd = sDecoded.substring(nIdx + 1);
                    CredentialProvider creds = new CredentialProvider(user, pwd);
                    threadLocalInstance.set(creds);
                }
            }
        }
    }
    return threadLocalInstance.get();
}