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:com.sslexplorer.vfs.webdav.DAVServlet.java

private void debugRequest(HttpServletRequest req) {
    if (SystemProperties.get("sslexplorer.webdav.debug", "false").equalsIgnoreCase("true")) {
        for (Enumeration e = req.getHeaderNames(); e.hasMoreElements();) {
            String header = (String) e.nextElement();
            for (Enumeration e2 = req.getHeaders(header); e2.hasMoreElements();) {
                log.info(header + ": " + (String) e2.nextElement());
            }// w w  w . ja v a2 s.  c  o  m
        }
    }

    if (log.isDebugEnabled())
        log.debug("Processing " + req.getMethod() + " " + req.getPathInfo());
}

From source file:org.owasp.benchmark.testcode.BenchmarkTest01101.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String param = "";
    java.util.Enumeration<String> names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();

        if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) {
            continue;
        }//from   w w  w .  j ava  2 s. com

        java.util.Enumeration<String> values = request.getHeaders(name);
        if (values != null && values.hasMoreElements()) {
            param = name;
            break;
        }
    }
    // Note: We don't URL decode header names because people don't normally do that

    String bar = new Test().doSomething(request, param);

    // Code based on example from:
    // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/

    try {
        javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher();
        // encrypt and store the results
        byte[] input = { (byte) '?' };
        Object inputParam = bar;
        if (inputParam instanceof String)
            input = ((String) inputParam).getBytes();
        if (inputParam instanceof java.io.InputStream) {
            byte[] strInput = new byte[1000];
            int i = ((java.io.InputStream) inputParam).read(strInput);
            if (i == -1) {
                response.getWriter().println(
                        "This input source requires a POST, not a GET. Incompatible UI for the InputStream source.");
                return;
            }
            input = java.util.Arrays.copyOf(strInput, i);
        }
        byte[] result = c.doFinal(input);

        java.io.File fileTarget = new java.io.File(
                new java.io.File(org.owasp.benchmark.helpers.Utils.testfileDir), "passwordFile.txt");
        java.io.FileWriter fw = new java.io.FileWriter(fileTarget, true); //the true will append the new data
        fw.write("secret_value=" + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + "\n");
        fw.close();
        response.getWriter()
                .println("Sensitive value: '" + org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(input))
                        + "' encrypted and stored<br/>");

    } catch (javax.crypto.IllegalBlockSizeException e) {
        response.getWriter().println(
                "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
        e.printStackTrace(response.getWriter());
        throw new ServletException(e);
    } catch (javax.crypto.BadPaddingException e) {
        response.getWriter().println(
                "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case");
        e.printStackTrace(response.getWriter());
        throw new ServletException(e);
    }
    response.getWriter()
            .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed");
}

From source file:com.eviware.soapui.impl.wsdl.monitor.JProxyServletWsdlMonitorMessageExchange.java

@SuppressWarnings("unchecked")
public void setRequestHeader(HttpServletRequest httpRequest) {
    Enumeration<String> headerNames = httpRequest.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();
        Enumeration<String> header = httpRequest.getHeaders(name);
        while (header.hasMoreElements()) {
            String value = header.nextElement();
            if (value != null) {
                requestHeaders.put(name, value);
            }//  w  ww  .  j ava2  s. c  om
        }
    }
}

From source file:org.wso2.carbon.identity.oauth.endpoint.revoke.OAuthRevocationEndpoint.java

private void logAccessTokenRevocationRequest(HttpServletRequest request) {
    log.debug("Received a access token revocation request : " + request.getRequestURI());
    // log the headers.
    log.debug("----------logging request headers.----------");
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        Enumeration headers = request.getHeaders(headerName);
        while (headers.hasMoreElements()) {
            log.debug(headerName + " : " + headers.nextElement());
        }/*from   w  ww .  j  a v  a  2s  .c  o m*/
    }
    // log the parameters.
    log.debug("----------logging request parameters.----------");
    log.debug("token - " + request.getParameter("token"));
}

From source file:com.adito.boot.Util.java

/**
 * Dump all request headers to {@link System#err}.
 * //  w  w w  .  ja  v  a  2s.co m
 * @param request request to get headers from
 */
public static void dumpRequestHeaders(HttpServletRequest request) {
    System.err.println("Request headers for " + request.getPathTranslated());
    for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) {
        String n = (String) e.nextElement();
        for (Enumeration e2 = request.getHeaders(n); e2.hasMoreElements();) {
            String v = (String) e2.nextElement();
            System.err.println("   " + n + " = " + v);
        }
    }
}

From source file:org.springframework.cloud.sleuth.instrument.web.TraceFilter.java

/** Override to add annotations not defined in {@link TraceKeys}. */
protected void addRequestTags(Span span, HttpServletRequest request) {
    String uri = this.urlPathHelper.getPathWithinApplication(request);
    this.httpTraceKeysInjector.addRequestTags(span, getFullUrl(request), request.getServerName(), uri,
            request.getMethod());/*from w  w  w .  j a  v a 2  s . com*/
    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.httpTraceKeysInjector.tagSpan(span, key, value);
        }
    }
}

From source file:org.wso2.carbon.identity.oauth.endpoint.token.OAuth2TokenEndpoint.java

private void logAccessTokenRequest(HttpServletRequest request) {

    if (log.isDebugEnabled()) {
        log.debug("Received a request : " + request.getRequestURI());
        // log the headers.
        log.debug("----------logging request headers.----------");

        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = (String) headerNames.nextElement();
            Enumeration headers = request.getHeaders(headerName);
            while (headers.hasMoreElements()) {
                log.debug(headerName + " : " + headers.nextElement());
            }/*from  w ww .  j a  v a2  s. co m*/
        }
        // log the parameters.
        log.debug("----------logging request parameters.----------");
        log.debug(OAuth.OAUTH_GRANT_TYPE + " - " + request.getParameter(OAuth.OAUTH_GRANT_TYPE));
        log.debug(OAuth.OAUTH_CLIENT_ID + " - " + request.getParameter(OAuth.OAUTH_CLIENT_ID));
        log.debug(OAuth.OAUTH_CODE + " - " + request.getParameter(OAuth.OAUTH_CODE));
        log.debug(OAuth.OAUTH_REDIRECT_URI + " - " + request.getParameter(OAuth.OAUTH_REDIRECT_URI));
    }
}

From source file:it.greenvulcano.gvesb.adapter.http.utils.DumpUtils.java

public static void dump(HttpServletRequest request, StringBuffer log) throws IOException {
    String hN;/*from  w w w  .  ja v a 2s .  c om*/

    log.append("-- DUMP HttpServletRequest START").append("\n");
    log.append("Method             : ").append(request.getMethod()).append("\n");
    log.append("RequestedSessionId : ").append(request.getRequestedSessionId()).append("\n");
    log.append("Scheme             : ").append(request.getScheme()).append("\n");
    log.append("IsSecure           : ").append(request.isSecure()).append("\n");
    log.append("Protocol           : ").append(request.getProtocol()).append("\n");
    log.append("ContextPath        : ").append(request.getContextPath()).append("\n");
    log.append("PathInfo           : ").append(request.getPathInfo()).append("\n");
    log.append("QueryString        : ").append(request.getQueryString()).append("\n");
    log.append("RequestURI         : ").append(request.getRequestURI()).append("\n");
    log.append("RequestURL         : ").append(request.getRequestURL()).append("\n");
    log.append("ContentType        : ").append(request.getContentType()).append("\n");
    log.append("ContentLength      : ").append(request.getContentLength()).append("\n");
    log.append("CharacterEncoding  : ").append(request.getCharacterEncoding()).append("\n");

    log.append("---- Headers START\n");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        hN = headerNames.nextElement();
        log.append("[" + hN + "]=");
        Enumeration<String> headers = request.getHeaders(hN);
        while (headers.hasMoreElements()) {
            log.append("[" + headers.nextElement() + "]");
        }
        log.append("\n");
    }
    log.append("---- Headers END\n");

    log.append("---- Body START\n");
    log.append(IOUtils.toString(request.getInputStream())).append("\n");
    log.append("---- Body END\n");

    log.append("-- DUMP HttpServletRequest END \n");
}

From source file:org.osaf.cosmo.mc.MorseCodeServlet.java

private Set<TicketType> parseTicketTypes(HttpServletRequest req) {
    Set<TicketType> types = new HashSet<TicketType>();

    Enumeration<String> e = (Enumeration<String>) req.getHeaders(HEADER_TICKET_TYPE);
    while (e.hasMoreElements()) {
        for (String id : StringUtils.split(e.nextElement())) {
            if (!(id.equals(TicketType.ID_READ_ONLY) || id.equals(TicketType.ID_READ_WRITE)))
                throw new IllegalArgumentException("Ticket type " + id + " not allowed for collections");
            types.add(TicketType.createInstance(id));
        }//from ww w .jav a2 s  . c o  m
    }

    return types;
}