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:org.artifactory.rest.common.util.RestUtils.java

/**
 * For backward compatability, if the build info version is less or equals to 2.0.11
 * then we need to decode the request parameters since we used a different encoding technique in the past,
 * otherwise we simply let Jersey do the decoding for us
 *
 * @return True if we need to manually decode the request params, false otherwise
 *//* ww w  . j  ava 2s.c om*/
public static boolean shouldDecodeParams(HttpServletRequest request) {
    String userAgent = request.getHeader(HttpHeaders.USER_AGENT);

    // If the request didn't come from build info let Jersey do the work
    if (StringUtils.isBlank(userAgent) || !userAgent.startsWith("ArtifactoryBuildClient/")) {
        return false;
    }

    String buildInfoVersion = StringUtils.removeStart(userAgent, "ArtifactoryBuildClient/");
    boolean snapshotCondition = StringUtils.contains(buildInfoVersion, "SNAPSHOT");
    boolean newVersionCondition = new DefaultArtifactVersion("2.0.11")
            .compareTo(new DefaultArtifactVersion(buildInfoVersion)) < 0;

    // Build info version is SNAPSHOT or newer than 2.0.11 we also let Jersey do the work
    if (snapshotCondition || newVersionCondition) {
        return false;
    }

    // If we got here it means client is using an old build-info (<= 2.0.11) we must manually decode the http params
    return true;
}

From source file:com.ai.smart.common.helper.util.RequestUtils.java

/**
 * ?IP//from  w  w w  .  j  av a2 s  .  c o  m
 * <p>
 * Request.getRemoteAddr()???nginx?????
 * <p>
 * Header?X-Real-IP??X-Forwarded-ForIP(,)
 * ?Request .getRemoteAddr()
 *
 * @param request
 * @return
 */
public static String getIpAddr(HttpServletRequest request) {
    String ip = request.getHeader("X-Real-IP");
    if (!StringUtils.isBlank(ip) && !"unknown".equalsIgnoreCase(ip)) {
        return ip;
    }
    ip = request.getHeader("X-Forwarded-For");
    if (!StringUtils.isBlank(ip) && !"unknown".equalsIgnoreCase(ip)) {
        // ?????IPIP
        int index = ip.indexOf(',');
        if (index != -1) {
            return ip.substring(0, index);
        } else {
            return ip;
        }
    } else {
        return request.getRemoteAddr();
    }
}

From source file:com.daimler.spm.storefront.util.CSRFTokenManager.java

/**
 * Returns the CSRF token from the httpServletRequest.
 *
 * @param httpServletRequest//w  ww.j ava 2  s  . co  m
 *           the httpServletRequest to retrieve CSRF token from
 * @return the CSRF token
 */
public static String getTokenFromRequest(final HttpServletRequest httpServletRequest) {
    final String requestCsrfToken = httpServletRequest.getParameter(CSRF_PARAM_NAME);

    if (requestCsrfToken == null) {
        return httpServletRequest.getHeader(CSRF_PARAM_NAME);
    } else {
        return requestCsrfToken;
    }
}

From source file:org.acoustid.server.util.ParameterMap.java

public static ParameterMap parseRequest(HttpServletRequest request) throws IOException {
    String contentEncoding = request.getHeader("Content-Encoding");
    if (contentEncoding != null) {
        contentEncoding = contentEncoding.toLowerCase();
    }//from w  w w.  j  a va2  s .c  o m
    String contentType = request.getContentType();
    Map<String, String[]> map;
    if ("gzip".equals(contentEncoding) && "application/x-www-form-urlencoded".equals(contentType)) {
        InputStream inputStream = new GZIPInputStream(request.getInputStream());
        InputStreamEntity entity = new InputStreamEntity(inputStream, -1);
        entity.setContentType(contentType);
        map = new HashMap<String, String[]>();
        for (NameValuePair param : URLEncodedUtils.parse(entity)) {
            String name = param.getName();
            String value = param.getValue();
            String[] values = map.get(name);
            if (values == null) {
                values = new String[] { value };
            } else {
                values = (String[]) ArrayUtils.add(values, value);
            }
            map.put(name, values);
        }
    } else {
        map = request.getParameterMap();
    }
    return new ParameterMap(map);
}

From source file:io.lavagna.web.security.HSTSFilter.java

private static boolean isOverHttps(HttpServletRequest req) {
    return req.isSecure() || req.getRequestURL().toString().startsWith("https://")
            || StringUtils.equals("https", req.getHeader("X-Forwarded-Proto"));
}

From source file:ee.ria.xroad.asyncsender.ProxyClientTest.java

private static void checkHeader(HttpServletRequest request) {
    if (request.getHeader(SoapUtils.X_IGNORE_ASYNC) == null) {
        throw new CodedException(ErrorCodes.X_HTTP_ERROR, "Request missing header " + SoapUtils.X_IGNORE_ASYNC);
    }/*from  ww w. j  a v a  2 s . c om*/
}

From source file:com.handpay.ibenefit.framework.util.WebUtils.java

public static boolean checkAccetptGzip(HttpServletRequest request) {
    // Http1.1 header
    String acceptEncoding = request.getHeader("Accept-Encoding");

    if (StringUtils.contains(acceptEncoding, "gzip")) {
        return true;
    } else {//from www  .j  a  va 2 s.  c  o  m
        return false;
    }
}

From source file:com.bluexml.side.framework.alfresco.shareLanguagePicker.LanguageSetter.java

private static String getLanguageFromBrowser(HttpServletRequest req) {
    // set language locale from browser header
    String acceptLang = req.getHeader(ACCEPT_LANGUAGE);
    String language = null;//w  w w  . j a  v a2  s .com
    if (acceptLang != null && acceptLang.length() != 0) {
        StringTokenizer t = new StringTokenizer(acceptLang, ",; ");
        // get language and convert to java locale format
        language = t.nextToken().replace('-', '_');
    } else {
        language = Locale.getDefault().getLanguage();
    }
    return language;
}

From source file:com.mmd.mssp.util.WebUtil.java

public static String getHttpQueryParam(HttpServletRequest request, String key)
        throws UnsupportedEncodingException {
    String val, ie = request.getParameter("ie");
    String ua = request.getHeader("User-Agent");
    if (ua != null && ua.contains("MSIE")) {//IE  GBK ?
        if (ie != null) {
            try {
                val = WebUtil.getHttpQueryParam(request, key, ie);
            } catch (UnsupportedEncodingException ex) {
                val = WebUtil.getHttpQueryParam(request, key, "UTF-8");
            }// ww w  .j ava  2  s  .  c  om
        } else {
            val = WebUtil.getHttpQueryParam(request, key, "GBK");
        }
    } else {
        val = WebUtil.getHttpQueryParam(request, key, "UTF-8");
    }
    request.setAttribute("QueryValue", val);
    //      val = val.replaceAll("\\\\", "\\\\\\\\").replaceAll("%", "\\\\%").replaceAll("_", "\\\\_");
    return val;
}

From source file:de.adorsys.oauth.authdispatcher.matcher.BasicAuthAuthenticatorMatcher.java

private static boolean isBasicAuthentication(HttpServletRequest httpServletRequest) {
    for (String name : Collections.list(httpServletRequest.getHeaderNames())) {
        if ("authorization".equalsIgnoreCase(name)) {
            return httpServletRequest.getHeader(name).substring(0, 5).equalsIgnoreCase("Basic");
        }//from  www  .j  av  a  2  s. c om
    }

    return false;

}