Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » coyote » http11 » filters » [javadoc | source]
    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.coyote.http11.filters;
   19   
   20   import java.io.IOException;
   21   
   22   import org.apache.coyote.InputBuffer;
   23   import org.apache.coyote.http11.InputFilter;
   24   import org.apache.tomcat.util.buf.ByteChunk;
   25   
   26   /**
   27    * Input filter responsible for replaying the request body when restoring the
   28    * saved request after FORM authentication.
   29    */
   30   public class SavedRequestInputFilter implements InputFilter {
   31   
   32   	/**
   33        * The original request body.
   34   	 */
   35       protected ByteChunk input = null;
   36   
   37       /**
   38        * Create a new SavedRequestInputFilter.
   39        * 
   40        * @param input The saved request body to be replayed.
   41        */
   42       public SavedRequestInputFilter(ByteChunk input) {
   43           this.input = input;
   44       }
   45   
   46       /**
   47        * Read bytes.
   48        */
   49       public int doRead(ByteChunk chunk, org.apache.coyote.Request request)
   50               throws IOException {
   51           int writeLength = 0;
   52           
   53           if (chunk.getLimit() > 0 && chunk.getLimit() < input.getLength()) {
   54               writeLength = chunk.getLimit();
   55           } else {
   56           	writeLength = input.getLength();
   57           }
   58           
   59           if(input.getOffset()>= input.getEnd())
   60               return -1;
   61           
   62           input.substract(chunk.getBuffer(), 0, writeLength);
   63           chunk.setOffset(0);
   64           chunk.setEnd(writeLength);
   65           
   66           return writeLength;
   67       }
   68   
   69       /**
   70        * Set the content length on the request.
   71        */
   72       public void setRequest(org.apache.coyote.Request request) {
   73           request.setContentLength(input.getLength());
   74       }
   75   
   76       /**
   77        * Make the filter ready to process the next request.
   78        */
   79       public void recycle() {
   80           input = null;
   81       }
   82   
   83       /**
   84        * Return the name of the associated encoding; here, the value is null.
   85        */
   86       public ByteChunk getEncodingName() {
   87           return null;
   88       }
   89   
   90       /**
   91        * Set the next buffer in the filter pipeline (has no effect).
   92        */
   93       public void setBuffer(InputBuffer buffer) {
   94       }
   95   
   96       /**
   97        * Amount of bytes still available in a buffer.
   98        */
   99       public int available() {
  100           return input.getLength();
  101       }
  102       
  103       /**
  104        * End the current request (has no effect).
  105        */
  106       public long end() throws IOException {
  107           return 0;
  108       }
  109   
  110   }

Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » coyote » http11 » filters » [javadoc | source]