Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.enterprise.web.accesslog;
 
 
 import java.util.*;
Access log formatter using the SJSAS format.
 
 
     private static final Logger _logger = .....;
 
     @LogMessageInfo(
             message = "Illegal access log pattern [{0}], is not a valid nickname and does not contain any ''%''",
             level = "SEVERE",
             cause = "The pattern is either null or does not contain '%'",
             action = "Check the pattern for validity")
     public static final String ACCESS_LOG_VALVE_INVALID_ACCESS_LOG_PATTERN = "AS-WEB-00236";
 
     @LogMessageInfo(
             message = "Missing end delimiter in access log pattern: {0}",
             level = "SEVERE",
             cause = "An end delimiter ismissing in the access log pattern",
             action = "Check the pattern for validity")
     public static final String MISSING_ACCESS_LOG_PATTERN_END_DELIMITER = "AS-WEB-00237";
 
     @LogMessageInfo(
             message = "Invalid component: {0} in access log pattern: {1}",
             level = "SEVERE",
             cause = "Access log pattern containds invalid component",
             action = "Check the pattern for validity")
     public static final String INVALID_ACCESS_LOG_PATTERN_COMPONENT = "AS-WEB-00238";
 
     private static final String QUOTE = "\"";
 
     /*
      * HTTP header names
      */
     private static final String HTTP_HEADER_ACCEPT = "Accept";
     private static final String HTTP_HEADER_AUTHORIZATION = "Authorization";
     private static final String HTTP_HEADER_DATE = "Date";
     private static final String HTTP_HEADER_IF_MODIFIED_SINCE = "If-Modified-Since";
 
    /*
     * Supported access log entry tokens
     */
    private static final String ATTRIBUTE_BY_NAME_PREFIX = "attribute.";
    private static final int ATTRIBUTE_BY_NAME_PREFIX_LEN =
    private static final String SESSION_ATTRIBUTE_BY_NAME_PREFIX = "session.";
    private static final int SESSION_ATTRIBUTE_BY_NAME_PREFIX_LEN =
    private static final String AUTH_USER_NAME = "auth-user-name";
    private static final String CLIENT_DNS = "client.dns";
    private static final String CLIENT_NAME = "client.name";
    private static final String COOKIE = "cookie";
    private static final String COOKIES = "cookies";
    private static final String COOKIE_VALUE = "cookie.value";
    private static final String COOKIE_BY_NAME_PREFIX = "cookie.";
    private static final int COOKIE_BY_NAME_PREFIX_LEN
        = .length();
    private static final String COOKIES_BY_NAME_PREFIX = "cookies.";
    private static final int COOKIES_BY_NAME_PREFIX_LEN
        = .length();
    private static final String DATE_TIME = "datetime";
    private static final String HEADER_ACCEPT = "header.accept";
    private static final String HEADER_BY_NAME_PREFIX = "header.";
    private static final int HEADER_BY_NAME_PREFIX_LEN
        = .length();
    private static final String HEADERS_BY_NAME_PREFIX = "headers.";
    private static final int HEADERS_BY_NAME_PREFIX_LEN =
    private static final String RESPONSE_HEADER_BY_NAME_PREFIX =
        "response.header.";
    private static final int RESPONSE_HEADER_BY_NAME_PREFIX_LEN =
    private static final String RESPONSE_HEADERS_BY_NAME_PREFIX =
        "response.headers.";
    private static final int RESPONSE_HEADERS_BY_NAME_PREFIX_LEN =
    private static final String HEADER_AUTH = "header.auth";
    private static final String HEADER_DATE = "header.date";
    private static final String HEADER_IF_MOD_SINCE = "header.if-mod-since";
    private static final String HEADER_USER_AGENT = "header.user-agent";
    private static final String HEADER_REFERER = "header.referer";
    private static final String HTTP_METHOD = "http-method";
    private static final String HTTP_URI = "http-uri";
    private static final String HTTP_VERSION = "http-version";
    private static final String QUERY_STR = "query-str";
    private static final String REFERER = "referer";
    private static final String REQUEST = "request";
    private static final String RESPONSE_LENGTH = "response.length";
    private static final String RESPONSE_CONTENT_TYPE = "response.content-type";
    private static final String STATUS = "status";
    private static final String TIME_TAKEN = "time-taken";
    private static final String USER_AGENT = "user.agent";
    private static final String VS_ID = "vs.id";
    private Container container;

    
List of access log pattern components
    private LinkedList<StringpatternComponents;

    
Constructor.

Parameters:
pattern The access log pattern
container The container associated with the access log valve
    public DefaultAccessLogFormatterImpl(String patternContainer container) {
        super();
        this. = parsePattern(pattern);
        if ( == null) {
            // Use default format if error in pattern
             = parsePattern(ConfigBeansUtilities.getDefaultFormat());
        }
        this. = container;
        final TimeZone timeZone = ;
         = new ThreadLocal<SimpleDateFormat>() {
            @Override
            protected SimpleDateFormat initialValue() {
                SimpleDateFormat f = new SimpleDateFormat("dd");
                f.setTimeZone(timeZone);
                return f;
            }
        };
         =  new ThreadLocal<SimpleDateFormat>() {
            @Override
            protected SimpleDateFormat initialValue() {
                SimpleDateFormat f = new SimpleDateFormat("MM");
                f.setTimeZone(timeZone);
                return f;
            }
        };
         = new ThreadLocal<SimpleDateFormat>() {
            @Override
            protected SimpleDateFormat initialValue() {
                SimpleDateFormat f = new SimpleDateFormat("yyyy");
                f.setTimeZone(timeZone);
                return f;
            }
        };
         = new ThreadLocal<SimpleDateFormat>() {
            @Override
            protected SimpleDateFormat initialValue() {
                SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss");
                f.setTimeZone(timeZone);
                return f;
            }
        };
    }

    
Appends an access log entry line, with info obtained from the given request and response objects, to the given CharBuffer.

Parameters:
request The request object from which to obtain access log info
response The response object from which to obtain access log info
charBuffer The CharBuffer to which to append access log info
    public void appendLogEntry(Request request,
                               Response response,
                               CharBuffer charBuffer) {
        HttpServletRequest hreq = (HttpServletRequest)
            request.getRequest();
        HttpServletResponse hres = (HttpServletResponse)
            response.getResponse();
        for (int i=0; i<.size(); i++) {
            String pc = .get(i);
            if (pc.startsWith()) {
                appendAttributeByName(
                    charBuffer,
                    pc.substring(),
                    hreq);
            } else if (pc.startsWith()) {
                appendSessionAttributeByName(
                    charBuffer,
                    pc.substring(),
                    hreq);
            } else if (.equals(pc)) {
                appendAuthUserName(charBufferhreq);
            } else if (.equals(pc)) {
                appendClientDNS(charBufferhreq);
            } else if (.equals(pc)) {
                appendClientName(charBufferhreq);
            } else if (.equals(pc)) {
                appendCookie(charBufferhreq);
            } else if (.equals(pc)) {
                appendCookies(charBufferhreq);
            } else if (.equals(pc)) {
                appendCookieValue(charBufferhreq);
            } else if (pc.startsWith()) {
                appendCookieByName(charBuffer,
                                   pc.substring(),
                                   hreq);
            } else if (pc.startsWith()) {
                appendCookiesByName(charBuffer,
                                   pc.substring(),
                                   hreq);
            } else if (.equals(pc)) {
                appendCurrentDate(charBuffer);       
            } else if (.equals(pc)) {
                appendHeaderAccept(charBufferhreq);
            } else if (.equals(pc)) {
                appendHeaderAuth(charBufferhreq);
            } else if (.equals(pc)) {
                appendHeaderDate(charBufferhreq);
            } else if (.equals(pc)) {
                appendHeaderIfModSince(charBufferhreq);
            } else if (.equals(pc)) {
                appendUserAgent(charBufferhreq);
            } else if (.equals(pc)) {
                appendReferer(charBufferhreq);
            } else if (.equals(pc)) {
                appendHTTPMethod(charBufferhreq);
            } else if (.equals(pc)) {
                appendHTTPUri(charBufferhreq);
            } else if (.equals(pc)) {
                appendHTTPVersion(charBufferhreq);
            } else if (.equals(pc)) {
                appendQueryString(charBufferhreq);
            } else if (.equals(pc)) {
                appendReferer(charBufferhreq);
            } else if (.equals(pc)) {
                appendRequestInfo(charBufferhreq);
            } else if (.equals(pc)) {
                appendResponseLength(charBufferresponse);
            } else if (.equals(pc)) {
                appendResponseContentType(charBufferresponse);
            } else if (.equals(pc)) {
                appendResponseStatus(charBufferresponse);
            } else if (.equals(pc)) {
                appendTimeTaken(charBufferrequest);
            } else if (.equals(pc)) {
                appendUserAgent(charBufferhreq);
            } else if (.equals(pc)) {
                appendVirtualServerId(charBuffer);
            } else if (pc.startsWith()) {
                appendHeaderByName(charBuffer,
                                   pc.substring(),
                                   hreq);
            } else if (pc.startsWith()) {
                appendHeadersByName(charBuffer,
                                    pc.substring(),
                                    hreq);
            } else if (pc.startsWith()) {
                appendResponseHeaderByName(charBuffer,
                    pc.substring(), hresresponse);
            } else if (pc.startsWith()) {
                appendResponseHeadersByName(charBuffer,
                    pc.substring(), hresresponse);
            }
            charBuffer.put();
        }
    }
    /*
     * Parses the access log pattern (that was specified via setPattern) into
     * its individual components, and returns them as a list.
     *
     * @param pattern The pattern to parse
     *
     * @return List containing the access log pattern components
     */
    private LinkedList<StringparsePattern(String pattern) {
        LinkedList<Stringlist = new LinkedList<String>();
        int from = 0;
        int end = -1;
        int index = -1;
        boolean errorInPattern = false;
        if (pattern == null || pattern.indexOf('%') < 0) {
            .log(.,
                        ,
                        pattern);
            errorInPattern = true;
        }
        while ((index = pattern.indexOf('%'from)) >= 0) {
            end = pattern.indexOf('%'index+1);
            if (end < 0) {
                .log(
                    .,
                    ,
                    pattern);
                errorInPattern = true;
                break;
            }
            String component = pattern.substring(index+1, end);
            if (!component.startsWith()
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component)
                    && !component.startsWith()
                    && !component.startsWith()
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component)
                    && !.equals(component)
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component
                    && !.equals(component)
                    && !component.startsWith()
                    && !component.startsWith()
                    && !component.startsWith()
                    && !component.startsWith()) {
                .log(
                    .,
                    ,
                    new Object[] { componentpattern });
                errorInPattern = true;
            }
            if (.equals(component)) {
                 = true;
            }
            list.add(component);
            from = end + 1;    
        }
        if (errorInPattern) {
            return null;
        } else {
            return list;
        }
    }
    /*
     * Appends the string representation of the value of the request
     * attribute with the given name to the given char buffer, or
     * NULL-ATTRIBUTE-<attributeName> if no attribute with the given name
     * is present in the request.
     */
    private void appendAttributeByName(CharBuffer cb,
                                       String attributeName,
                                       HttpServletRequest hreq) {
        if (attributeName == null) {
            throw new IllegalArgumentException("Null request attribute name");
        }
        cb.put();
        Object attrValue = hreq.getAttribute(attributeName);
        if (attrValue != null) {
            cb.put(attrValue.toString());
        } else {
            cb.put("NULL-ATTRIBUTE-" + attributeName.toUpperCase(.));
        }
        cb.put();
    }
    /*
     * Appends the string representation of the value of the session
     * attribute with the given name to the given char buffer, or
     * NULL-SESSION-ATTRIBUTE-<attributeName> if no attribute with the
     * given name is present in the session, or NULL-SESSION if
     * no session exists.
     */
    private void appendSessionAttributeByName(CharBuffer cb,
                                              String attributeName,
                                              HttpServletRequest hreq) {
        if (attributeName == null) {
            throw new IllegalArgumentException("Null session attribute name");
        }
        cb.put();
        HttpSession session = hreq.getSession(false);
        if (session != null) {
            Object attrValue = session.getAttribute(attributeName);
            if (attrValue != null) {
                cb.put(attrValue.toString());
            } else {
                cb.put("NULL-SESSION-ATTRIBUTE-" +
                       attributeName.toUpperCase(.));
            }
        } else {
            cb.put("NULL-SESSION");
        }
        cb.put();
    }
    /*
     * Appends the client host name of the given request to the given char
     * buffer.
     */
    private void appendClientName(CharBuffer cbServletRequest req) {
        cb.put();
        String value = req.getRemoteHost();
        if (value == null) {
            value = "NULL-CLIENT-NAME";
        }
        cb.put(value);
        cb.put();
    }
    /*
     * Appends the client DNS of the given request to the given char
     * buffer.
     */
    private void appendClientDNS(CharBuffer cbServletRequest req) {
        cb.put();
        String value = req.getRemoteAddr();
        if (value == null) {
            value = "NULL-CLIENT-DNS";
        }
        cb.put(value);
        cb.put();
    }
    /*
     * Appends the authenticated user (if any) to the given char buffer.
     */
    private void appendAuthUserName(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String user = hreq.getRemoteUser();
        if (user == null) {
            user = "NULL-AUTH-USER";
        }
        cb.put(user);
        cb.put();
    }
    /*
     * Appends the current date to the given char buffer.
     */
    private void appendCurrentDate(CharBuffer cb) {
        cb.put();
        Date date = getDate();
        cb.put(.get().format(date));           // Day
        cb.put('/');
        cb.put(lookup(.get().format(date))); // Month
        cb.put('/');
        cb.put(.get().format(date));          // Year
        cb.put(':');
        cb.put(.get().format(date));          // Time
        cb.put();
        cb.put();                                  // Time Zone
        cb.put();
    }
    /*
     * Appends info about the given request to the given char buffer.
     */
    private void appendRequestInfo(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        cb.put(hreq.getMethod());
        cb.put();
        String uri = hreq.getRequestURI();
        if (uri == null) {
            uri = "NULL-HTTP-URI";
        }
        cb.put(uri);
        if (hreq.getQueryString() != null) {
            cb.put('?');
            cb.put(hreq.getQueryString());
        }
        cb.put();
        cb.put(hreq.getProtocol());
        cb.put();
    }
    /*
     * Appends the response status to the given char buffer.
     */
    private void appendResponseStatus(CharBuffer cbResponse response) {
        cb.put(String.valueOf(((HttpResponseresponse).getStatus()));
    }
    /*
     * Appends the content length of the given response to the given char
     * buffer.
     */
    private void appendResponseLength(CharBuffer cbResponse response) {
        cb.put("" + response.getContentCount());
    }
    /*
     * Appends the content type of the given response to the given char
     * buffer.
     */
    private void appendResponseContentType(CharBuffer cbResponse response) {
        cb.put(response.getContentType());
    }
    /*
     * Appends the value of the 'user-agent' header of the given request to
     * the given char buffer.
     */
    private void appendUserAgent(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String ua = hreq.getHeader("user-agent");
        if (ua == null) {
            ua = "NULL-USER-AGENT";
        }
        cb.put(ua);
        cb.put();
    }
    /*
     * Appends the time (in milliseconds) it has taken to service the given
     * request to the given char buffer.
     */
    private void appendTimeTaken(CharBuffer cbRequest req) {
        String timeTaken = "NULL-TIME-TAKEN";
        cb.put();
        Long startTimeObj = (Longreq.getNote(
            .);
        if (startTimeObj != null) {
            long startTime = startTimeObj.longValue();
            long endTime = System.currentTimeMillis();
            timeTaken = String.valueOf(endTime - startTime);
        } 
        cb.put(timeTaken);
        cb.put();
    }
    /*
     * Appends the value of the 'referer' header of the given request to
     * the given char buffer.
     */
    private void appendReferer(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String referer = hreq.getHeader("referer");
        if (referer == null) {
            referer = "NULL-REFERER";
        }
        cb.put(referer);
        cb.put();
    }
    /*
     * Appends the Accept header of the given request to the given char
     * buffer.
     */
    private void appendHeaderAccept(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String accept = hreq.getHeader();
        if (accept == null) {
            accept = "NULL-HEADER-ACCEPT";
        }
        cb.put(accept);
        cb.put();
    }
    /*
     * Appends the Authorization header of the given request to the given char
     * buffer.
     */
    private void appendHeaderAuth(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String auth = hreq.getHeader();
        if (auth == null) {
            auth = "NULL-HEADER-AUTHORIZATION";
        }
        cb.put(auth);
        cb.put();
    }
    /*
     * Appends the Date header of the given request to the given char buffer.
     */
    private void appendHeaderDate(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String date = hreq.getHeader();
        if (date == null) {
            date = "NULL-HEADER-DATE";
        }
        cb.put(date);
        cb.put();
    }
    /*
     * Appends the If-Modified-Since header of the given request to the
     * given char buffer.
     */
    private void appendHeaderIfModSince(CharBuffer cb,
                                        HttpServletRequest hreq) {
        cb.put();
        String ifModSince = hreq.getHeader();
        if (ifModSince == null) {
            ifModSince = "NULL-HEADER-IF-MODIFIED-SINCE";
        }
        cb.put(ifModSince);
        cb.put();
    }
    /*
     * Appends the value of the header with the specified name in the given
     * request to the given char buffer, or NULL-HEADER-<headerName> if no
     * header with the given name is present in the request..
     */
    private void appendHeaderByName(CharBuffer cb,
                                    String headerName,
                                    HttpServletRequest hreq) {
        if (headerName == null) {
            throw new IllegalArgumentException("Null request header name");
        }
        cb.put();
        String value = hreq.getHeader(headerName);
        if (value == null) {
            value = "NULL-HEADER-" + headerName.toUpperCase(.);
        }
        cb.put(value);
        cb.put();
    }
    /*
     * Appends the value of the header with the specified name in the given
     * response to the given char buffer, or
     * NULL-RESPONSE-HEADER-<headerName> if no header with the given name
     * is present in the response.
     */
    private void appendResponseHeaderByName(CharBuffer cb,
                                            String headerName,
                                            HttpServletResponse hresResponse response) {
        if (headerName == null) {
            throw new IllegalArgumentException("Null response header name");
        }
        cb.put();
        String value = hres.getHeader(headerName);
        if (value == null) {
            if (headerName.equalsIgnoreCase("Content-Type")) {
                value = hres.getContentType();
            } else if (headerName.equalsIgnoreCase("Content-Length")) {
                value = ""+response.getContentLength();
            } else {
                value = "NULL-RESPONSE-HEADER-" + headerName.toUpperCase(.);
            }
        }
        cb.put(value);
        cb.put();
    }
    /*
     * Appends the values (separated by ";") of all headers with the
     * specified name in the given request to the given char buffer, or
     * NULL-HEADERS-<headerName> if no headers with the given name are 
     * present in the request..
     */
    private void appendHeadersByName(CharBuffer cb,
                                     String headerName,
                                     HttpServletRequest hreq) {
        if (headerName == null) {
            throw new IllegalArgumentException("Null request header name");
        }
        cb.put();
        Enumeration e = hreq.getHeaders(headerName);
        if (e != null) {
            boolean first = true;
            while (e.hasMoreElements()) {
                if (first) {
                    first = false;
                } else {
                    cb.put(";");
                }
                cb.put(e.nextElement().toString());
            }
            if (first) {
                cb.put("NULL-HEADERS-" + headerName.toUpperCase(.));
            }
        } else {
            cb.put("NULL-HEADERS-" + headerName.toUpperCase(.));
        }
        cb.put();
    }
    /*
     * Appends the values (separated by ";") of all headers with the
     * specified name in the given response to the given char buffer, or
     * NULL-RESPONSE-HEADERS-<headerName> if no headers with the given name
     * are present in the response.
     */
    private void appendResponseHeadersByName(CharBuffer cb,
            String headerNameHttpServletResponse hresResponse response) {
        if (headerName == null) {
            throw new IllegalArgumentException("Null response header name");
        }
        cb.put();
        boolean first = true;
        Collection<Stringvalues = hres.getHeaders(headerName);
        if (!values.isEmpty()) {
            for (String value : values) {
                if (first) {
                    first = false;
                } else {
                    cb.put(";");
                }
                cb.put(value);
            }
        } else {
            String value = null;
            if (headerName.equalsIgnoreCase("Content-Type")) {
                value = hres.getContentType();
            } else if (headerName.equalsIgnoreCase("Content-Length")) {
                value = ""+response.getContentLength();
            }
            if (value != null) {
                first = false;
                cb.put(value);
            }
        }
        if (first) {
            cb.put("NULL-RESPONSE-HEADERS-" + headerName.toUpperCase(.));
        }
        cb.put();
    }
    /*
     * Appends the name and value (separated by '=') of the first cookie
     * in the given request to the given char buffer, or NULL-COOKIE if no
     * cookies are present in the request.
     */
    private void appendCookie(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String cookie = "NULL-COOKIE";
        Cookie[] cookies = hreq.getCookies();
        if (cookies != null && cookies.length > 0) {
            cookie = cookies[0].getName() + "=" + cookies[0].getValue();
        }
        cb.put(cookie);
        cb.put();
    }
    /*
     * Appends the name and value (separated by '=') of all cookies
     * (separated by ';') in the given request to the given char buffer,
     * or NULL-COOKIES if no cookies are present in the request.
     */
    private void appendCookies(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        Cookie[] cookies = hreq.getCookies();
        if (cookies != null && cookies.length > 0) {
            for (int i=0; i<cookies.lengthi++) {
                cb.put(cookies[i].getName() + "=" + cookies[i].getValue());
                if (i<cookies.length-1) {
                    cb.put(";");
                }
            }
        } else {
            cb.put("NULL-COOKIES");
        }
        cb.put();
    }
    /*
     * Appends the value of the first cookie in the given request to the
     * given char buffer, or NULL-COOKIE-VALUE if no cookies are present
     * in the request.
     */
    private void appendCookieValue(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String cookieValue = "NULL-COOKIE-VALUE";
        Cookie[] cookies = hreq.getCookies();
        if (cookies != null && cookies.length > 0) {
            cookieValue = cookies[0].getValue();
        }
        cb.put(cookieValue);
        cb.put();
    }
    /*
     * Appends the value of the first cookie with the given cookie name to the
     * given char buffer, or NULL-COOKIE-<cookieName> if no cookies with the
     * given cookie name are present in the request.
     */
    private void appendCookieByName(CharBuffer cb,
                                    String cookieName,
                                    HttpServletRequest hreq) {
        if (cookieName == null) {
            throw new IllegalArgumentException("Null request cookie name");
        }
        cb.put();
        String cookieValue = null;
        Cookie[] cookies = hreq.getCookies();
        if (cookies != null && cookies.length > 0) {
            for (Cookie cookie : cookies) {
                if (cookieName.equals(cookie.getName())) {
                    cookieValue = cookie.getValue();
                    break;
                }
            }
        }
        if (cookieValue == null) {
            cookieValue = "NULL-COOKIE-" + cookieName.toUpperCase(.);
        }
        cb.put(cookieValue);
        cb.put();
    }
    /*
     * Appends the value of all cookies with the given cookie name to the
     * given char buffer, or NULL-COOKIES-<cookieName> if no cookies with the
     * given cookie name are present in the request.
     */
    private void appendCookiesByName(CharBuffer cb,
                                     String cookieName,
                                     HttpServletRequest hreq) {
        if (cookieName == null) {
            throw new IllegalArgumentException("Null request cookie name");
        }
        cb.put();
        Cookie[] cookies = hreq.getCookies();
        if (cookies != null && cookies.length > 0) {
            boolean first = true;
            for (int i=0; i<cookies.lengthi++) {
                if (cookieName.equals(cookies[i].getName())) {
                    if (first) {
                        first = false;
                    } else {
                        cb.put(";");
		    }
                    cb.put(cookies[i].getValue());
                }
            }
        } else {
            cb.put("NULL-COOKIES-" + cookieName.toUpperCase(.));
        }
        cb.put();
    }
    /*
     * Appends the HTTP method of the given request to the given char buffer.
     */
    private void appendHTTPMethod(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String method = hreq.getMethod();
        if (method == null) {
            method = "NULL-HTTP-METHOD";
        }
        cb.put(method);
        cb.put();
    }
    /*
     * Appends the URI of the given request to the given char buffer.
     */
    private void appendHTTPUri(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String uri = hreq.getRequestURI();
        if (uri == null) {
            uri = "NULL-HTTP-URI";
        }
        cb.put(uri);
        cb.put();
    }
    /*
     * Appends the HTTP protocol version of the given request to the given
     * char buffer.
     */
    private void appendHTTPVersion(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String protocol = hreq.getProtocol();
        if (protocol == null) {
            protocol = "NULL-HTTP-PROTOCOL";
        }
        cb.put(protocol);
        cb.put();
    }
    /*
     * Appends the query string of the given request to the given char buffer.
     */
    private void appendQueryString(CharBuffer cbHttpServletRequest hreq) {
        cb.put();
        String query = hreq.getQueryString();
        if (query == null) {
            query = "NULL-QUERY";
        }
        cb.put(query);
        cb.put();
    }
    /*
     * Appends the id of the virtual server with which this access log valve
     * has been associated to the given char buffer.
     */
    private void appendVirtualServerId(CharBuffer cb) {
        String vsId = "NULL-VIRTUAL-SERVER";
        if ( != null) {
            vsId = .getName();
        }
        cb.put(vsId);
    }