Example usage for javax.servlet.http HttpServletRequest getHeaders

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

Introduction

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

Prototype

public Enumeration<String> getHeaders(String name);

Source Link

Document

Returns all the values of the specified request header as an Enumeration of String objects.

Usage

From source file:nl.surfnet.coin.shared.filter.LoggingFilter.java

private void preHandle(HttpServletRequest request, String requestId) {
    // Log basic request information at debug level
    if (REQUEST_LOG.isDebugEnabled()) {
        REQUEST_LOG.debug("{} {} {}?{}", requestId, request.getMethod(), request.getRequestURL(),
                request.getQueryString());

        // Log headers with Trace level
        if (REQUEST_LOG.isTraceEnabled()) {
            @SuppressWarnings("unchecked")
            Enumeration<String> headerNames = request.getHeaderNames();
            while (headerNames.hasMoreElements()) {
                String headerName = headerNames.nextElement();
                Enumeration headerValues = request.getHeaders(headerName);
                while (headerValues.hasMoreElements()) {
                    Object value = headerValues.nextElement();
                    REQUEST_LOG.trace("{} Header: {}: {}", requestId, headerName, value);
                }/*from   ww  w.  j a  v  a 2 s. c o  m*/
            }
        }
    }
}

From source file:com.mockey.model.RequestFromClient.java

@SuppressWarnings("unchecked")
private void parseRequestHeaders(HttpServletRequest rawRequest) {

    // Put header information coming from client.
    Enumeration<String> e = rawRequest.getHeaderNames();

    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        // Let's ignore some headers
        if (this.shouldIncludeHeader(name)) {
            List<String> values = new ArrayList<String>();
            Enumeration eValues = rawRequest.getHeaders(name);

            while (eValues.hasMoreElements()) {
                String value = (String) eValues.nextElement();
                values.add(value);/* ww  w .  j av a2 s . c  o  m*/
            }

            headers.put(name, values);
        }
    }
    // Override header information to prevent CACHING
    // As of 4/29/2011, updated Apache HttpClient. Result was the
    // following:
    // Testing with MAMP (Apache 2.0.63), I was seeing
    // this parameter being sent by Browsers Firefox 4 and
    // and Chrome 9, but NOT Safari 5.
    // To prevent caching, removing this attribute.
    e = rawRequest.getHeaderNames();
    List<String> p = new ArrayList<String>();
    p.add("Fri, 13 May 2006 23:54:18 GMT");
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();

        if ("if-none-match".equalsIgnoreCase(name)) {
            headers.remove(name);
        } else if ("If-modified-Since".equalsIgnoreCase(name)) {
            headers.put(name, p);
        }

    }

}

From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java

private void debugRequest(HttpServletRequest request) {
    log.debug("=====================request begin==========================");
    String uri = request.getRequestURI();
    String queryString = request.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        uri = uri + "?" + queryString;
    }/*  w  w  w . j a  v a2  s.c om*/
    log.debug("{}:{}", request.getMethod(), uri);
    log.debug("remote ip:{}  sessionId:{}  ", IpUtils.getIpAddr(request), request.getRequestedSessionId());
    log.debug("===header begin============================================");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();
        String value = headersToString(request.getHeaders(name));
        log.debug("{}={}", name, value);
    }
    log.debug("===header   end============================================");
    log.debug("===parameter begin==========================================");
    Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        String value = StringUtils.join(request.getParameterValues(name), "||");
        log.debug("{}={}", name, value);
    }
    log.debug("===parameter   end==========================================");
    log.debug("=====================request   end==========================");
}

From source file:com.yoho.core.trace.instrument.web.TraceInterceptor.java

/**
 * Override to add annotations not defined in {@link TraceKeys}.
 *///from www .  j a  va  2  s  . co  m
protected void addRequestTags(HttpServletRequest request) {

    //add uid
    this.tracer.addTag(this.traceKeys.getYoho().getUid(), request.getParameter("uid"));

    //add http
    String uri = this.urlPathHelper.getPathWithinApplication(request);
    this.tracer.addTag(this.traceKeys.getHttp().getUrl(), getFullUrl(request));
    this.tracer.addTag(this.traceKeys.getHttp().getHost(), request.getServerName());
    this.tracer.addTag(this.traceKeys.getHttp().getPath(), uri);
    this.tracer.addTag(this.traceKeys.getHttp().getMethod(), request.getMethod());
    for (String name : this.traceKeys.getHttp().getHeaders()) {
        Enumeration<String> values = request.getHeaders(name);
        if (values.hasMoreElements()) {
            String key = this.traceKeys.getHttp().getPrefix() + name.toLowerCase();
            ArrayList<String> list = Collections.list(values);
            String value = list.size() == 1 ? list.get(0)
                    : StringUtils.collectionToDelimitedString(list, ",", "'", "'");
            this.tracer.addTag(key, value);
        }
    }
}

From source file:de.digitalcollections.streaming.euphoria.controller.StreamingController.java

private void logRequestHeaders(HttpServletRequest request) {
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        Enumeration<String> headers = request.getHeaders(headerName);
        while (headers.hasMoreElements()) {
            String header = headers.nextElement();
            LOGGER.debug("request header: {} = {}", headerName, header);
        }/*www. j  a  v a 2 s  .c  o m*/
    }
}

From source file:com.formkiq.core.api.FolderFilesController.java

/**
 * Save File to Folder.//from  w ww .  j a v  a  2  s .c  o  m
 * @param request {@link HttpServletRequest}
 * @param response {@link HttpServletResponse}
 * @param folder {@link String}
 * @param entity HttpEntity&lt;byte[]&gt;
 * @param lastSha1hash {@link String}
 * @return {@link ApiMessageResponse}
 * @throws IOException IOException
 */
@Transactional
@RequestMapping(value = API_FOLDER_FILE + "/{folder}", method = POST)
public ApiMessageResponse saveFolderFile(final HttpServletRequest request, final HttpServletResponse response,
        @PathVariable(name = "folder", required = true) final String folder,
        @RequestParam(value = "sha1hash", required = false) final String lastSha1hash,
        final HttpEntity<byte[]> entity) throws IOException {

    getApiVersion(request);

    FormSaveResult result = null;
    ApiMessageResponse msg = new ApiMessageResponse("Save successful");

    Enumeration<String> e = request.getHeaders("accept");
    boolean isAdmin = this.securityService.isAdmin()
            && this.securityService.hasAcceptHeader(e, ACCEPT_HEADER_ADMIN);

    if (request instanceof MultipartHttpServletRequest) {

        MultipartHttpServletRequest rr = (MultipartHttpServletRequest) request;

        Iterator<String> itr = rr.getFileNames();
        MultipartFile mpf = rr.getFile(itr.next());
        result = this.folderService.saveForm(folder, mpf.getBytes(), lastSha1hash, isAdmin);
        checkForValidationErrors(result.getErrors());
        response.addHeader("sha1hash", result.getSha1hash());

    } else {

        result = this.folderService.saveForm(folder, entity.getBody(), lastSha1hash, isAdmin);
        checkForValidationErrors(result.getErrors());
        response.addHeader("sha1hash", result.getSha1hash());
    }

    if (FolderFormStatus.IN_PROCESS.equals(result.getStatus())) {
        msg = new ApiMessageResponse("Saved as 'In Process'");
    }

    return msg;
}

From source file:org.apache.catalina.authenticator.FormAuthenticator.java

/**
 * Save the original request information into our session.
 *
 * @param request The request to be saved
 * @param session The session to contain the saved information
 *//*from w  w w  .  j av  a2 s .  c o m*/
private void saveRequest(HttpRequest request, Session session) {

    // Create and populate a SavedRequest object for this request
    HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
    SavedRequest saved = new SavedRequest();
    Cookie cookies[] = hreq.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++)
            saved.addCookie(cookies[i]);
    }
    Enumeration names = hreq.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Enumeration values = hreq.getHeaders(name);
        while (values.hasMoreElements()) {
            String value = (String) values.nextElement();
            saved.addHeader(name, value);
        }
    }
    Enumeration locales = hreq.getLocales();
    while (locales.hasMoreElements()) {
        Locale locale = (Locale) locales.nextElement();
        saved.addLocale(locale);
    }
    Map parameters = hreq.getParameterMap();
    Iterator paramNames = parameters.keySet().iterator();
    while (paramNames.hasNext()) {
        String paramName = (String) paramNames.next();
        String paramValues[] = (String[]) parameters.get(paramName);
        saved.addParameter(paramName, paramValues);
    }
    saved.setMethod(hreq.getMethod());
    saved.setQueryString(hreq.getQueryString());
    saved.setRequestURI(hreq.getRequestURI());

    // Stash the SavedRequest in our session for later use
    session.setNote(Constants.FORM_REQUEST_NOTE, saved);

}

From source file:com.keithhutton.ws.proxy.ProxyServlet.java

protected XmlRpcHttpRequestConfigImpl getConfig(HttpServletRequest pRequest) {
    XmlRpcHttpRequestConfigImpl result = newConfig(pRequest);
    XmlRpcHttpServerConfig serverConfig = (XmlRpcHttpServerConfig) getConfig();
    result.setBasicEncoding(serverConfig.getBasicEncoding());
    result.setContentLengthOptional(//from   w w  w  . j  av  a  2s .co m
            serverConfig.isContentLengthOptional() && (pRequest.getHeader("Content-Length") == null));
    result.setEnabledForExtensions(serverConfig.isEnabledForExtensions());
    result.setGzipCompressing(HttpUtil.isUsingGzipEncoding(pRequest.getHeader("Content-Encoding")));
    result.setGzipRequesting(HttpUtil.isUsingGzipEncoding(pRequest.getHeaders("Accept-Encoding")));
    result.setEncoding(pRequest.getCharacterEncoding());
    result.setEnabledForExceptions(serverConfig.isEnabledForExceptions());
    HttpUtil.parseAuthorization(result, pRequest.getHeader("Authorization"));
    return result;
}

From source file:com.evon.injectTemplate.InjectTemplateFilter.java

private void loadContentTemplate(TemplateBean template, String domain, Integer port, boolean https,
        HttpServletRequest httpRequest) throws Exception {
    HTMLInfoBean htmlInfo = templates.get("/" + template.path);

    String sport = (port == null) ? "" : ":" + String.valueOf(port);

    String url = htmlInfo.getProtocol() + "://" + domain + sport + "/" + template.path;

    Request request = Request.Get(url);

    Enumeration<String> headerNames = httpRequest.getHeaderNames();

    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();

        Enumeration<String> headerValues = httpRequest.getHeaders(name);
        while (headerValues.hasMoreElements()) {
            String value = headerValues.nextElement();
            request = request.addHeader(name, value);
        }/*w ww  .ja  va  2 s. co  m*/
    }

    String content = request.execute().returnContent().asString();

    Pattern pattern = Pattern.compile("<INJECT[ ]{1,}selector=[\"'](.*?)[\"']/>",
            Pattern.CASE_INSENSITIVE + Pattern.DOTALL);

    Matcher matcher = pattern.matcher(content);

    List<String> selectors = new ArrayList<String>();

    while (matcher.find()) {
        String tagInject = matcher.group(0);
        String selector = matcher.group(1);
        selectors.add(selector);
        content = content.replace(tagInject, "<INJECT selector='" + selector + "'/>");
    }

    String key = null;

    if (template.cache.equals("SESSION")) {
        String cookiesNames = getCookieHashs(httpRequest);
        key = template.path + cookiesNames;
    } else {
        key = template.path;
    }

    HtmlContentBean contentBean = new HtmlContentBean();
    contentBean.setContent(content);
    contentBean.setLastAccess(System.currentTimeMillis());
    htmlContents.remove(key);
    htmlContents.put(key, contentBean);
    htmlInfo.setSelectors(selectors);
}

From source file:uk.ac.ebi.phenotype.web.controller.GenesController.java

/**
 * Prints out the request object/*w w w  . j a v a 2  s.com*/
 */
@RequestMapping("/genes/print-request")
public ResponseEntity<String> printRequest(HttpServletRequest request) {

    Enumeration<String> s = request.getHeaderNames();

    while (s.hasMoreElements()) {
        String header = (String) s.nextElement();
        Enumeration<String> headers = request.getHeaders(header);

        while (headers.hasMoreElements()) {
            String actualHeader = (String) headers.nextElement();
        }
    }

    HttpHeaders resp = new HttpHeaders();
    resp.setContentType(MediaType.APPLICATION_JSON);

    return new ResponseEntity<String>(request.toString(), resp, HttpStatus.CREATED);
}