org.apache.catalina.util.RequestUtil Java Examples

The following examples show how to use org.apache.catalina.util.RequestUtil. 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: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected static boolean validateContextName(ContextName cn,
        PrintWriter writer, StringManager sm) {
    
    // ContextName should be non-null with a path that is empty or starts
    // with /
    if (cn != null &&
            (cn.getPath().startsWith("/") || cn.getPath().equals(""))) {
        return true;
    }
    
    String path = null;
    if (cn != null) {
        path = RequestUtil.filter(cn.getPath());
    }
    writer.println(sm.getString("managerServlet.invalidPath", path));
    return false;
}
 
Example #2
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected static boolean validateContextName(ContextName cn,
        PrintWriter writer, StringManager sm) {
    
    // ContextName should be non-null with a path that is empty or starts
    // with /
    if (cn != null &&
            (cn.getPath().startsWith("/") || cn.getPath().equals(""))) {
        return true;
    }
    
    String path = null;
    if (cn != null) {
        path = RequestUtil.filter(cn.getPath());
    }
    writer.println(sm.getString("managerServlet.invalidPath", path));
    return false;
}
 
Example #3
Source File: ApplicationHttpRequest.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Merge the parameters from the saved query parameter string (if any), and
 * the parameters already present on this request (if any), such that the
 * parameter values from the query string show up first if there are
 * duplicate parameter names.
 */
private void mergeParameters() {

    if ((queryParamString == null) || (queryParamString.length() < 1))
        return;

    HashMap<String, String[]> queryParameters = new HashMap<String, String[]>();
    String encoding = getCharacterEncoding();
    if (encoding == null)
        encoding = "ISO-8859-1";
    RequestUtil.parseParameters(queryParameters, queryParamString,
            encoding);
    for (Entry<String, String[]> entry : parameters.entrySet()) {
        String entryKey = entry.getKey();
        String[] entryValue = entry.getValue();
        Object value = queryParameters.get(entryKey);
        if (value == null) {
            queryParameters.put(entryKey, entryValue);
            continue;
        }
        queryParameters.put
            (entryKey, mergeValues(value, entryValue));
    }
    parameters = queryParameters;

}
 
Example #4
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Reload the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be restarted
 */
protected void reload(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("restart: Reloading web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    RequestUtil.filter(cn.getDisplayName())));
            return;
        }
        // It isn't possible for the manager to reload itself
        if (context.getName().equals(this.context.getName())) {
            writer.println(smClient.getString("managerServlet.noSelf"));
            return;
        }
        context.reload();
        writer.println(smClient.getString("managerServlet.reloaded",
                cn.getDisplayName()));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.reload[" + cn.getDisplayName() + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example #5
Source File: SecurityCollection.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Add a URL pattern to be part of this web resource collection.
 */
public void addPattern(String pattern) {

    if (pattern == null)
        return;

    String decodedPattern = RequestUtil.URLDecode(pattern);
    String results[] = new String[patterns.length + 1];
    for (int i = 0; i < patterns.length; i++) {
        results[i] = patterns[i];
    }
    results[patterns.length] = decodedPattern;
    patterns = results;

}
 
Example #6
Source File: ErrorPage.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Set the location.
 *
 * @param location The new location
 */
public void setLocation(String location) {

    //        if ((location == null) || !location.startsWith("/"))
    //            throw new IllegalArgumentException
    //                ("Error Page Location must start with a '/'");
    this.location = RequestUtil.URLDecode(location);

}
 
Example #7
Source File: FilterMap.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void addURLPattern(String urlPattern) {
    if ("*".equals(urlPattern)) {
        this.matchAllUrlPatterns = true;
    } else {
        String[] results = new String[urlPatterns.length + 1];
        System.arraycopy(urlPatterns, 0, results, 0, urlPatterns.length);
        results[urlPatterns.length] = RequestUtil.URLDecode(urlPattern);
        urlPatterns = results;
    }
}
 
Example #8
Source File: Response.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Internal method that allows a redirect to be sent with a status other
 * than {@link HttpServletResponse#SC_FOUND} (302). No attempt is made to
 * validate the status code.
 */
public void sendRedirect(String location, int status) throws IOException {
    if (isCommitted()) {
        throw new IllegalStateException(sm.getString("coyoteResponse.sendRedirect.ise"));
    }

    // Ignore any call from an included servlet
    if (included) {
        return;
    }

    // Clear any data content that has been buffered
    resetBuffer(true);

    // Generate a temporary redirect to the specified location
    try {
        String locationUri;
        // Relative redirects require HTTP/1.1
        if (getRequest().getCoyoteRequest().getSupportsRelativeRedirects() &&
                getContext().getUseRelativeRedirects()) {
            locationUri = location;
        } else {
            locationUri = toAbsolute(location);
        }
        setStatus(status);
        setHeader("Location", locationUri);
        if (getContext().getSendRedirectBody()) {
            PrintWriter writer = getWriter();
            writer.print(sm.getString("coyoteResponse.sendRedirect.note",
                    RequestUtil.filter(locationUri)));
            flushBuffer();
        }
    } catch (IllegalArgumentException e) {
        log.warn(sm.getString("response.sendRedirectFail", location), e);
        setStatus(SC_NOT_FOUND);
    }

    // Cause the response to be finished (from the application perspective)
    setSuspended(true);
}
 
Example #9
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Stop the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be stopped
 */
protected void stop(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("stop: Stopping web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    String displayPath = cn.getDisplayName();

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    RequestUtil.filter(displayPath)));
            return;
        }
        // It isn't possible for the manager to stop itself
        if (context.getName().equals(this.context.getName())) {
            writer.println(smClient.getString("managerServlet.noSelf"));
            return;
        }
        context.stop();
        writer.println(smClient.getString(
                "managerServlet.stopped", displayPath));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.stop[" + displayPath + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example #10
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Start the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be started
 */
protected void start(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("start: Starting web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    String displayPath = cn.getDisplayName();

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext", 
                    RequestUtil.filter(displayPath)));
            return;
        }
        context.start();
        if (context.getState().isAvailable())
            writer.println(smClient.getString("managerServlet.started",
                    displayPath));
        else
            writer.println(smClient.getString("managerServlet.startFailed",
                    displayPath));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log(sm.getString("managerServlet.startFailed",
                displayPath), t);
        writer.println(smClient.getString("managerServlet.startFailed",
                displayPath));
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example #11
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Reload the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be restarted
 */
protected void reload(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("restart: Reloading web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    RequestUtil.filter(cn.getDisplayName())));
            return;
        }
        // It isn't possible for the manager to reload itself
        if (context.getName().equals(this.context.getName())) {
            writer.println(smClient.getString("managerServlet.noSelf"));
            return;
        }
        context.reload();
        writer.println(smClient.getString("managerServlet.reloaded",
                cn.getDisplayName()));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.reload[" + cn.getDisplayName() + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example #12
Source File: HTMLManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
protected List<Session> getSessionsForName(ContextName cn,
        StringManager smClient) {
    if ((cn == null) || !(cn.getPath().startsWith("/") ||
            cn.getPath().equals(""))) {
        String path = null;
        if (cn != null) {
            path = cn.getPath();
        }
        throw new IllegalArgumentException(smClient.getString(
                "managerServlet.invalidPath",
                RequestUtil.filter(path)));
    }

    Context ctxt = (Context) host.findChild(cn.getName());
    if (null == ctxt) {
        throw new IllegalArgumentException(smClient.getString(
                "managerServlet.noContext",
                RequestUtil.filter(cn.getDisplayName())));
    }
    Manager manager = ctxt.getManager();
    List<Session> sessions = new ArrayList<Session>();
    sessions.addAll(Arrays.asList(manager.findSessions()));
    if (manager instanceof DistributedManager && showProxySessions) {
        // Add dummy proxy sessions
        Set<String> sessionIds =
            ((DistributedManager) manager).getSessionIdsFull();
        // Remove active (primary and backup) session IDs from full list
        for (Session session : sessions) {
            sessionIds.remove(session.getId());
        }
        // Left with just proxy sessions - add them
        for (String sessionId : sessionIds) {
            sessions.add(new DummyProxySession(sessionId));
        }
    }
    return sessions;
}
 
Example #13
Source File: SecurityCollection.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Add a URL pattern to be part of this web resource collection.
 */
public void addPattern(String pattern) {

    if (pattern == null)
        return;

    String decodedPattern = RequestUtil.URLDecode(pattern);
    String results[] = new String[patterns.length + 1];
    for (int i = 0; i < patterns.length; i++) {
        results[i] = patterns[i];
    }
    results[patterns.length] = decodedPattern;
    patterns = results;

}
 
Example #14
Source File: ErrorPage.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the location.
 *
 * @param location The new location
 */
public void setLocation(String location) {

    //        if ((location == null) || !location.startsWith("/"))
    //            throw new IllegalArgumentException
    //                ("Error Page Location must start with a '/'");
    this.location = RequestUtil.URLDecode(location);

}
 
Example #15
Source File: FilterMap.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void addURLPattern(String urlPattern) {
    if ("*".equals(urlPattern)) {
        this.matchAllUrlPatterns = true;
    } else {
        String[] results = new String[urlPatterns.length + 1];
        System.arraycopy(urlPatterns, 0, results, 0, urlPatterns.length);
        results[urlPatterns.length] = RequestUtil.URLDecode(urlPattern);
        urlPatterns = results;
    }
}
 
Example #16
Source File: Response.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Send a temporary redirect to the specified redirect location URL.
 *
 * @param location Location URL to redirect to
 *
 * @exception IllegalStateException if this response has
 *  already been committed
 * @exception IOException if an input/output error occurs
 */
@Override
public void sendRedirect(String location) throws IOException {
    if (isCommitted()) {
        throw new IllegalStateException(sm.getString("coyoteResponse.sendRedirect.ise"));
    }

    // Ignore any call from an included servlet
    if (included) {
        return;
    }

    // Clear any data content that has been buffered
    resetBuffer(true);

    // Generate a temporary redirect to the specified location
    try {
        String locationUri;
        // Relative redirects require HTTP/1.1
        if (getRequest().getCoyoteRequest().getSupportsRelativeRedirects() &&
                getContext().getUseRelativeRedirects()) {
            locationUri = URI.create(location).toASCIIString();
        } else {
            locationUri = toAbsolute(location);
        }
        setStatus(SC_FOUND);
        setHeader("Location", locationUri);
        if (getContext().getSendRedirectBody()) {
            PrintWriter writer = getWriter();
            writer.print(sm.getString("coyoteResponse.sendRedirect.note",
                    RequestUtil.filter(locationUri)));
            flushBuffer();
        }
    } catch (IllegalArgumentException e) {
        setStatus(SC_NOT_FOUND);
    }

    // Cause the response to be finished (from the application perspective)
    setSuspended(true);
}
 
Example #17
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Stop the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be stopped
 */
protected void stop(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("stop: Stopping web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    String displayPath = cn.getDisplayName();

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    RequestUtil.filter(displayPath)));
            return;
        }
        // It isn't possible for the manager to stop itself
        if (context.getName().equals(this.context.getName())) {
            writer.println(smClient.getString("managerServlet.noSelf"));
            return;
        }
        context.stop();
        writer.println(smClient.getString(
                "managerServlet.stopped", displayPath));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.stop[" + displayPath + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example #18
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Start the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be started
 */
protected void start(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("start: Starting web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    String displayPath = cn.getDisplayName();

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext", 
                    RequestUtil.filter(displayPath)));
            return;
        }
        context.start();
        if (context.getState().isAvailable())
            writer.println(smClient.getString("managerServlet.started",
                    displayPath));
        else
            writer.println(smClient.getString("managerServlet.startFailed",
                    displayPath));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log(sm.getString("managerServlet.startFailed",
                displayPath), t);
        writer.println(smClient.getString("managerServlet.startFailed",
                displayPath));
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example #19
Source File: HTMLManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
protected List<Session> getSessionsForName(ContextName cn,
        StringManager smClient) {
    if ((cn == null) || !(cn.getPath().startsWith("/") ||
            cn.getPath().equals(""))) {
        String path = null;
        if (cn != null) {
            path = cn.getPath();
        }
        throw new IllegalArgumentException(smClient.getString(
                "managerServlet.invalidPath",
                RequestUtil.filter(path)));
    }

    Context ctxt = (Context) host.findChild(cn.getName());
    if (null == ctxt) {
        throw new IllegalArgumentException(smClient.getString(
                "managerServlet.noContext",
                RequestUtil.filter(cn.getDisplayName())));
    }
    Manager manager = ctxt.getManager();
    List<Session> sessions = new ArrayList<Session>();
    sessions.addAll(Arrays.asList(manager.findSessions()));
    if (manager instanceof DistributedManager && showProxySessions) {
        // Add dummy proxy sessions
        Set<String> sessionIds =
            ((DistributedManager) manager).getSessionIdsFull();
        // Remove active (primary and backup) session IDs from full list
        for (Session session : sessions) {
            sessionIds.remove(session.getId());
        }
        // Left with just proxy sessions - add them
        for (String sessionId : sessionIds) {
            sessions.add(new DummyProxySession(sessionId));
        }
    }
    return sessions;
}
 
Example #20
Source File: LoginConfig.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public void setLoginPage(String loginPage) {
    //        if ((loginPage == null) || !loginPage.startsWith("/"))
    //            throw new IllegalArgumentException
    //                ("Login Page resource path must start with a '/'");
    this.loginPage = RequestUtil.URLDecode(loginPage);
}
 
Example #21
Source File: LoginConfig.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public void setErrorPage(String errorPage) {
    //        if ((errorPage == null) || !errorPage.startsWith("/"))
    //            throw new IllegalArgumentException
    //                ("Error Page resource path must start with a '/'");
    this.errorPage = RequestUtil.URLDecode(errorPage);
}
 
Example #22
Source File: Request.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Return the portion of the request URI used to select the Context
 * of the Request. The value returned is not decoded which also implies it
 * is not normalised.
 */
@Override
public String getContextPath() {
    String canonicalContextPath = getServletContext().getContextPath();
    String uri = getRequestURI();
    char[] uriChars = uri.toCharArray();
    int lastSlash = mappingData.contextSlashCount;
    // Special case handling for the root context
    if (lastSlash == 0) {
        return "";
    }
    int pos = 0;
    // Need at least the number of slashes in the context path
    while (lastSlash > 0) {
        pos = nextSlash(uriChars, pos + 1);
        if (pos == -1) {
            break;
        }
        lastSlash--;
    }
    // Now allow for normalization and/or encoding. Essentially, keep
    // extending the candidate path up to the next slash until the decoded
    // and normalized candidate path is the same as the canonical path.
    String candidate;
    if (pos == -1) {
        candidate = uri;
    } else {
        candidate = uri.substring(0, pos);
    }
    candidate = RequestUtil.URLDecode(candidate, connector.getURIEncoding());
    candidate = org.apache.tomcat.util.http.RequestUtil.normalize(candidate);
    boolean match = canonicalContextPath.equals(candidate);
    while (!match && pos != -1) {
        pos = nextSlash(uriChars, pos + 1);
        if (pos == -1) {
            candidate = uri;
        } else {
            candidate = uri.substring(0, pos);
        }
        candidate = RequestUtil.URLDecode(candidate, connector.getURIEncoding());
        candidate = org.apache.tomcat.util.http.RequestUtil.normalize(candidate);
        match = canonicalContextPath.equals(candidate);
    }
    if (match) {
        if (pos == -1) {
            return uri;
        } else {
            return uri.substring(0, pos);
        }
    } else {
        // Should never happen
        throw new IllegalStateException(sm.getString(
                "coyoteRequest.getContextPath.ise", canonicalContextPath, uri));
    }
}
 
Example #23
Source File: Request.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Return the portion of the request URI used to select the Context
 * of the Request. The value returned is not decoded which also implies it
 * is not normalised.
 */
@Override
public String getContextPath() {
    String canonicalContextPath = getServletContext().getContextPath();
    String uri = getRequestURI();
    char[] uriChars = uri.toCharArray();
    int lastSlash = mappingData.contextSlashCount;
    // Special case handling for the root context
    if (lastSlash == 0) {
        return "";
    }
    int pos = 0;
    // Need at least the number of slashes in the context path
    while (lastSlash > 0) {
        pos = nextSlash(uriChars, pos + 1);
        if (pos == -1) {
            break;
        }
        lastSlash--;
    }
    // Now allow for path parameters, normalization and/or encoding.
    // Essentially, keep extending the candidate path up to the next slash
    // until the decoded and normalized candidate path (with the path
    // parameters removed) is the same as the canonical path.
    String candidate;
    if (pos == -1) {
        candidate = uri;
    } else {
        candidate = uri.substring(0, pos);
    }
    candidate = removePathParameters(candidate);
    candidate = RequestUtil.URLDecode(candidate, connector.getURIEncoding());
    candidate = org.apache.tomcat.util.http.RequestUtil.normalize(candidate);
    boolean match = canonicalContextPath.equals(candidate);
    while (!match && pos != -1) {
        pos = nextSlash(uriChars, pos + 1);
        if (pos == -1) {
            candidate = uri;
        } else {
            candidate = uri.substring(0, pos);
        }
        candidate = removePathParameters(candidate);
        candidate = RequestUtil.URLDecode(candidate, connector.getURIEncoding());
        candidate = org.apache.tomcat.util.http.RequestUtil.normalize(candidate);
        match = canonicalContextPath.equals(candidate);
    }
    if (match) {
        if (pos == -1) {
            return uri;
        } else {
            return uri.substring(0, pos);
        }
    } else {
        // Should never happen
        throw new IllegalStateException(sm.getString(
                "coyoteRequest.getContextPath.ise", canonicalContextPath, uri));
    }
}
 
Example #24
Source File: LoginConfig.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void setErrorPage(String errorPage) {
    //        if ((errorPage == null) || !errorPage.startsWith("/"))
    //            throw new IllegalArgumentException
    //                ("Error Page resource path must start with a '/'");
    this.errorPage = RequestUtil.URLDecode(errorPage);
}
 
Example #25
Source File: LoginConfig.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void setLoginPage(String loginPage) {
    //        if ((loginPage == null) || !loginPage.startsWith("/"))
    //            throw new IllegalArgumentException
    //                ("Login Page resource path must start with a '/'");
    this.loginPage = RequestUtil.URLDecode(loginPage);
}
 
Example #26
Source File: AccessValve.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void invoke (Request request, Response response) throws IOException,
   ServletException
{
   // Case of Valve disabled.
   if (!isEnable())
   {
      getNext().invoke(request, response);
      return;
   }
   
   final AccessInformation ai = new AccessInformation();
   ai.setConnectionStatus(new PendingConnectionStatus());
   
   // To be sure not to retrieve the same date trough concurrency calls.
   synchronized (this)
   {
      ai.setStartTimestamp(System.nanoTime());  
      ai.setStartDate (new Date ());
   }
   try
   {
      this.doLog(request, response, ai);
   }
   finally
   {
      Element cached_element = new Element(UUID.randomUUID(), ai);
      getCache().put(cached_element);
      
      try
      {
         // Log of the pending request command.
         if (isUseLogger()) LOGGER.info ("Access " + ai);
         
         getNext().invoke(request, response);
      }
      catch (Throwable e)
      {
         response.addHeader("cause-message", 
            e.getClass().getSimpleName() + " : " + e.getMessage());
         //ai.setConnectionStatus(new FailureConnectionStatus(e));
         response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
         //throw e;
      }
      finally
      {
         ai.setReponseSize(response.getContentLength());
         ai.setWrittenResponseSize(response.getContentWritten());
         
         if (response.getStatus()>=400)
         {
            String message = RequestUtil.filter(response.getMessage());
            if (message==null)
            {
               // The cause-message has been inserted into the reponse header
               // at error handler time. It no message is retrieved in the
               // standard response, the cause-message is used.
               message = response.getHeader("cause-message");
            }
            Throwable throwable = null;
            if (message != null) throwable = new Throwable(message);
            else throwable = (Throwable) request.getAttribute(
               RequestDispatcher.ERROR_EXCEPTION); 
            if (throwable==null) throwable = new Throwable();
            
            ai.setConnectionStatus(new FailureConnectionStatus(throwable));
         }
         else
            ai.setConnectionStatus(new SuccessConnectionStatus());
   
         ai.setEndTimestamp(System.nanoTime());
         if ((getPattern()==null) || ai.getRequest().matches(getPattern()))
         {
            cached_element.updateUpdateStatistics();
            if (isUseLogger()) LOGGER.info ("Access " + ai);
         }
      }
   }
}