Example usage for javax.servlet ServletRequest getLocale

List of usage examples for javax.servlet ServletRequest getLocale

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getLocale.

Prototype

public Locale getLocale();

Source Link

Document

Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.

Usage

From source file:org.zilverline.web.RequestDumperFilter.java

/**
 * Time the processing that is performed by all subsequent filters in the current filter stack, including the ultimately invoked
 * servlet.//from  w ww.  j  ava  2s.c  o m
 * 
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param chain The filter chain we are processing
 * 
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {

    if (filterConfig == null) {
        return;
    }

    log.debug("Request Received at " + (new Timestamp(System.currentTimeMillis())));
    log.debug(" characterEncoding=" + request.getCharacterEncoding());
    log.debug("     contentLength=" + request.getContentLength());
    log.debug("       contentType=" + request.getContentType());
    log.debug("            locale=" + request.getLocale());
    Enumeration locales = request.getLocales();
    StringBuffer localesBuffer = new StringBuffer("           locales=");
    boolean first = true;
    while (locales.hasMoreElements()) {
        Locale locale = (Locale) locales.nextElement();
        if (first) {
            first = false;
        } else {
            localesBuffer.append(", ");
        }
        localesBuffer.append(locale.toString());
    }
    log.debug(localesBuffer);
    Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        StringBuffer paramsBuffer = new StringBuffer();
        paramsBuffer.append("         parameter=" + name + "=");
        String[] values = request.getParameterValues(name);
        for (int i = 0; i < values.length; i++) {
            if (i > 0) {
                paramsBuffer.append(", ");
            }
            paramsBuffer.append(values[i]);
        }
        log.debug(paramsBuffer);
    }
    log.debug("          protocol=" + request.getProtocol());
    log.debug("        remoteAddr=" + request.getRemoteAddr());
    log.debug("        remoteHost=" + request.getRemoteHost());
    log.debug("            scheme=" + request.getScheme());
    log.debug("        serverName=" + request.getServerName());
    log.debug("        serverPort=" + request.getServerPort());
    log.debug("          isSecure=" + request.isSecure());

    // Render the HTTP servlet request properties
    if (request instanceof HttpServletRequest) {
        log.debug("---------------------------------------------");
        HttpServletRequest hrequest = (HttpServletRequest) request;
        log.debug("       contextPath=" + hrequest.getContextPath());
        Cookie[] cookies = hrequest.getCookies();
        if (cookies == null) {
            cookies = new Cookie[0];
        }
        for (int i = 0; i < cookies.length; i++) {
            log.debug("            cookie=" + cookies[i].getName() + "=" + cookies[i].getValue());
        }
        names = hrequest.getHeaderNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            String value = hrequest.getHeader(name);
            log.debug("            header=" + name + "=" + value);
        }
        log.debug("            method=" + hrequest.getMethod());
        log.debug("          pathInfo=" + hrequest.getPathInfo());
        log.debug("       queryString=" + hrequest.getQueryString());
        log.debug("        remoteUser=" + hrequest.getRemoteUser());
        log.debug("requestedSessionId=" + hrequest.getRequestedSessionId());
        log.debug("        requestURI=" + hrequest.getRequestURI());
        log.debug("       servletPath=" + hrequest.getServletPath());
    }
    log.debug("=============================================");

    // Pass control on to the next filter
    chain.doFilter(request, response);

}