Java Code Examples for org.apache.catalina.connector.Request#getHeaderNames()

The following examples show how to use org.apache.catalina.connector.Request#getHeaderNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormAuthenticator.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Save the original request information into our session.
 *
 * @param request The request to be saved
 * @param session The session to contain the saved information
 * @throws IOException if an IO error occurred during the process
 */
protected void saveRequest(Request request, Session session)
    throws IOException {

    // Create and populate a SavedRequest object for this request
    SavedRequest saved = new SavedRequest();
    Cookie cookies[] = request.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            saved.addCookie(cookies[i]);
        }
    }
    Enumeration<String> names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        Enumeration<String> values = request.getHeaders(name);
        while (values.hasMoreElements()) {
            String value = values.nextElement();
            saved.addHeader(name, value);
        }
    }
    Enumeration<Locale> locales = request.getLocales();
    while (locales.hasMoreElements()) {
        Locale locale = locales.nextElement();
        saved.addLocale(locale);
    }

    // May need to acknowledge a 100-continue expectation
    request.getResponse().sendAcknowledgement();

    int maxSavePostSize = request.getConnector().getMaxSavePostSize();
    if (maxSavePostSize != 0) {
        ByteChunk body = new ByteChunk();
        body.setLimit(maxSavePostSize);

        byte[] buffer = new byte[4096];
        int bytesRead;
        InputStream is = request.getInputStream();

        while ( (bytesRead = is.read(buffer) ) >= 0) {
            body.append(buffer, 0, bytesRead);
        }

        // Only save the request body if there is something to save
        if (body.getLength() > 0) {
            saved.setContentType(request.getContentType());
            saved.setBody(body);
        }
    }

    saved.setMethod(request.getMethod());
    saved.setQueryString(request.getQueryString());
    saved.setRequestURI(request.getRequestURI());
    saved.setDecodedRequestURI(request.getDecodedRequestURI());

    // Stash the SavedRequest in our session for later use
    session.setNote(Constants.FORM_REQUEST_NOTE, saved);
}
 
Example 2
Source File: FormAuthenticator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Save the original request information into our session.
 *
 * @param request The request to be saved
 * @param session The session to contain the saved information
 * @throws IOException
 */
protected void saveRequest(Request request, Session session)
    throws IOException {

    // Create and populate a SavedRequest object for this request
    SavedRequest saved = new SavedRequest();
    Cookie cookies[] = request.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            saved.addCookie(cookies[i]);
        }
    }
    Enumeration<String> names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        Enumeration<String> values = request.getHeaders(name);
        while (values.hasMoreElements()) {
            String value = values.nextElement();
            saved.addHeader(name, value);
        }
    }
    Enumeration<Locale> locales = request.getLocales();
    while (locales.hasMoreElements()) {
        Locale locale = locales.nextElement();
        saved.addLocale(locale);
    }

    // May need to acknowledge a 100-continue expectation
    request.getResponse().sendAcknowledgement();

    ByteChunk body = new ByteChunk();
    body.setLimit(request.getConnector().getMaxSavePostSize());

    byte[] buffer = new byte[4096];
    int bytesRead;
    InputStream is = request.getInputStream();

    while ( (bytesRead = is.read(buffer) ) >= 0) {
        body.append(buffer, 0, bytesRead);
    }

    // Only save the request body if there is something to save
    if (body.getLength() > 0) {
        saved.setContentType(request.getContentType());
        saved.setBody(body);
    }

    saved.setMethod(request.getMethod());
    saved.setQueryString(request.getQueryString());
    saved.setRequestURI(request.getRequestURI());
    saved.setDecodedRequestURI(request.getDecodedRequestURI());

    // Stash the SavedRequest in our session for later use
    session.setNote(Constants.FORM_REQUEST_NOTE, saved);
}
 
Example 3
Source File: FormAuthenticator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Save the original request information into our session.
 *
 * @param request The request to be saved
 * @param session The session to contain the saved information
 * @throws IOException
 */
protected void saveRequest(Request request, Session session)
    throws IOException {

    // Create and populate a SavedRequest object for this request
    SavedRequest saved = new SavedRequest();
    Cookie cookies[] = request.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            saved.addCookie(cookies[i]);
        }
    }
    Enumeration<String> names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        Enumeration<String> values = request.getHeaders(name);
        while (values.hasMoreElements()) {
            String value = values.nextElement();
            saved.addHeader(name, value);
        }
    }
    Enumeration<Locale> locales = request.getLocales();
    while (locales.hasMoreElements()) {
        Locale locale = locales.nextElement();
        saved.addLocale(locale);
    }

    // May need to acknowledge a 100-continue expectation
    request.getResponse().sendAcknowledgement();

    ByteChunk body = new ByteChunk();
    body.setLimit(request.getConnector().getMaxSavePostSize());

    byte[] buffer = new byte[4096];
    int bytesRead;
    InputStream is = request.getInputStream();

    while ( (bytesRead = is.read(buffer) ) >= 0) {
        body.append(buffer, 0, bytesRead);
    }

    // Only save the request body if there is something to save
    if (body.getLength() > 0) {
        saved.setContentType(request.getContentType());
        saved.setBody(body);
    }

    saved.setMethod(request.getMethod());
    saved.setQueryString(request.getQueryString());
    saved.setRequestURI(request.getRequestURI());
    saved.setDecodedRequestURI(request.getDecodedRequestURI());

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