View Javadoc

    1   //========================================================================
    2   //Copyright 2006 Mort Bay Consulting Pty. Ltd.
    3   //------------------------------------------------------------------------
    4   //Licensed under the Apache License, Version 2.0 (the "License");
    5   //you may not use this file except in compliance with the License.
    6   //You may obtain a copy of the License at
    7   //http://www.apache.org/licenses/LICENSE-2.0
    8   //Unless required by applicable law or agreed to in writing, software
    9   //distributed under the License is distributed on an "AS IS" BASIS,
    10  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  //See the License for the specific language governing permissions and
    12  //limitations under the License.
    13  //========================================================================
    14
    15  package org.mortbay.jetty.handler;
    16
    17  import java.io.IOException;
    18
    19  import javax.servlet.ServletException;
    20  import javax.servlet.http.HttpServletRequest;
    21  import javax.servlet.http.HttpServletResponse;
    22
    23  import org.mortbay.jetty.Handler;
    24  import org.mortbay.jetty.HttpConnection;
    25  import org.mortbay.jetty.Request;
    26
    27  /* ------------------------------------------------------------ */
    28  /** HandlerList.
    29   * This extension of {@link org.mortbay.jetty.handler.HandlerCollection} will call
    30   * each contained handler in turn until either an exception is thrown, the response
    31   * is committed or a positive response status is set.
    32   */
    33  public class HandlerList extends HandlerCollection
    34  {
    35      /* ------------------------------------------------------------ */
    36      /*
    37       * @see org.mortbay.jetty.EventHandler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    38       */
    39      public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
    40          throws IOException, ServletException
    41      {
    42          Handler[] handlers = getHandlers();
    43
    44          if (handlers!=null && isStarted())
    45          {
    46              Request base_request = HttpConnection.getCurrentConnection().getRequest();
    47              for (int i=0;i<handlers.length;i++)
    48              {
    49                  handlers[i].handle(target,request, response, dispatch);
    50                  if ( base_request.isHandled())
    51                      return;
    52              }
    53          }
    54      }
    55  }