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.ziduye.base.web.Servlets.java

/**
 * ??//from   ww  w . j a v a 2s . com
 * @param request
 * @param uri
 * @return
 */
public static boolean isTableRequest(HttpServletRequest request, String uri) {
    String userAgent = request.getHeader("USER-AGENT").toLowerCase();
    if (null == userAgent) {
        userAgent = "";
    }
    Matcher matcherTable = tablePat.matcher(userAgent);
    if (matcherTable.find()) {
        return true;
    } else {
        return false;
    }
}

From source file:com.tek271.reverseProxy.servlet.ProxyFilter.java

private static void addCustomGetHeaders(HttpServletRequest request, HttpGet httpGet) {
    httpGet.addHeader("preferred-role", request.getHeader("preferred-role"));
    httpGet.addHeader("X-Source", request.getHeader("X-Source"));
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        Enumeration enumerationOfHeaderValues = request.getHeaders(headerName);
        while (enumerationOfHeaderValues.hasMoreElements()) {
            String headerValue = (String) enumerationOfHeaderValues.nextElement();
            if (headerName.equalsIgnoreCase("accept")) {
                httpGet.setHeader(headerName, headerValue);
            }//w ww  . j a  v a2 s.  c o m
        }

    }
}

From source file:org.artifactory.webapp.servlet.RequestUtils.java

/**
 * check weather api key is found on request
 *
 * @param request - http servlet request
 * @return Token key value/*from   www  . j  a  v  a  2 s . c o m*/
 */
public static TokenKeyValue getApiKeyTokenKeyValue(HttpServletRequest request) {
    String apiKeyValue = request.getHeader("X-Api-Key");
    if (apiKeyValue != null) {
        return new TokenKeyValue(ApiKeyManager.API_KEY, apiKeyValue);
    }
    return null;
}

From source file:tv.arte.resteventapi.core.presentation.decoration.RestEventApiControllerLinkBuilder.java

/**
 * Returns a {@link UriComponentsBuilder} obtained from the current servlet mapping with the host tweaked in case the
 * request contains an {@code X-Forwarded-Host} header and the scheme tweaked in case the request contains an
 * {@code X-Forwarded-Ssl} header//from  www  . j  ava 2  s .  co m
 * 
 * @return
 */
static UriComponentsBuilder getBuilder() {

    HttpServletRequest request = getCurrentRequest();
    ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromServletMapping(request);

    String forwardedSsl = request.getHeader("X-Forwarded-Ssl");

    if (StringUtils.hasText(forwardedSsl) && forwardedSsl.equalsIgnoreCase("on")) {
        builder.scheme("https");
    }

    String host = request.getHeader("X-Forwarded-Host");

    if (!StringUtils.hasText(host)) {
        return builder;
    }

    String[] hosts = StringUtils.commaDelimitedListToStringArray(host);
    String hostToUse = hosts[0];

    if (hostToUse.contains(":")) {

        String[] hostAndPort = StringUtils.split(hostToUse, ":");

        builder.host(hostAndPort[0]);
        builder.port(Integer.parseInt(hostAndPort[1]));

    } else {
        builder.host(hostToUse);
        builder.port(-1); // reset port if it was forwarded from default port
    }

    String port = request.getHeader("X-Forwarded-Port");

    if (StringUtils.hasText(port)) {
        builder.port(Integer.parseInt(port));
    }

    return builder;
}

From source file:mojo.view.util.DebugUtils.java

@SuppressWarnings("rawtypes")
public static void logRequestHeaders(HttpServletRequest req) {
    logger.debug("REQUEST HEADERS");
    logger.debug("---------------");

    Enumeration enums = req.getHeaderNames();

    while (enums.hasMoreElements()) {
        String headerName = (String) enums.nextElement();
        String headerValue = req.getHeader(headerName);
        logger.debug(headerName + ": " + headerValue);
    }//from  w  w w . j a  v  a2  s .  c  o m

    logger.debug("");
}

From source file:com.qatickets.common.HttpUtils.java

public static Map<String, String> getHeadersAsMap(HttpServletRequest req) {
    final Map<String, String> headers = new HashMap<String, String>();
    final Enumeration enames = req.getHeaderNames();
    while (enames.hasMoreElements()) {
        final String name = (String) enames.nextElement();
        final String value = req.getHeader(name);
        headers.put(name, value);// w ww .  j  av a2s . co m
    }
    return headers;
}

From source file:com.log4ic.compressor.utils.HttpUtils.java

/**
 * ???//from w ww  . j  av  a2 s  .com
 *
 * @param request
 * @return
 */
public static List<String> getRequestPlatform(HttpServletRequest request) {
    List<String> list = new FastList<String>();
    String userAgent = request.getHeader("User-Agent");
    for (PlatformTester tester : platformTesterList) {
        //??
        String platform = findPattern(userAgent, tester.getRegex());
        if (platform != null) {
            list.add(tester.getIdentity());
        }
    }
    return list;
}

From source file:com.googlecode.jsonplugin.JSONUtil.java

public static boolean isGzipInRequest(HttpServletRequest request) {
    String header = request.getHeader("Accept-Encoding");
    return header != null && header.indexOf("gzip") >= 0;
}

From source file:com.tek271.reverseProxy.servlet.ProxyFilter.java

@SuppressWarnings({ "unchecked" })
private static StringEntity getEntity(HttpServletRequest request) throws IOException {
    if (APPLICATION_JSON.equalsIgnoreCase(request.getHeader("Content-type"))) {
        StringBuilder stringBuilder = new StringBuilder();
        BufferedReader bufferedReader = null;
        InputStream inputStream = request.getInputStream();
        if (inputStream != null) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            char[] charBuffer = new char[512];
            int bytesRead = -1;
            while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
                stringBuilder.append(charBuffer, 0, bytesRead);
            }/* w ww .java2 s .  com*/
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        } else {
            stringBuilder.append("");
        }
        return new StringEntity(stringBuilder.toString(), "UTF-8");

    }
    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    Enumeration<String> en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String name = en.nextElement();
        String value = request.getParameter(name);
        formparams.add(new BasicNameValuePair(name, value));
    }
    return new UrlEncodedFormEntity(formparams, "UTF-8");
}

From source file:fi.hsl.parkandride.MDCFilter.java

private static void setValues(ServletRequest request) {
    HttpServletRequest httpReq = HttpServletRequest.class.cast(request);
    MDC.put(Key.REQUESTID, UUID.randomUUID().toString());
    MDC.put(Key.SRCIP, httpReq.getRemoteHost());
    // Authenticated username will be set in UserArgumentResolver iff authentication is required
    MDC.put(Key.USERNAME, "<ANONYMOUS>");
    String appId = httpReq.getHeader(LIIPI_APPLICATION_ID);
    if (appId != null) {
        MDC.put(Key.APPID, appId);
    }/*from   w  ww . ja  va2 s .  c o m*/
}