001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.coyote.http11.filters;
019:
020: import java.io.IOException;
021:
022: import org.apache.coyote.InputBuffer;
023: import org.apache.coyote.http11.InputFilter;
024: import org.apache.tomcat.util.buf.ByteChunk;
025:
026: /**
027: * Input filter responsible for replaying the request body when restoring the
028: * saved request after FORM authentication.
029: */
030: public class SavedRequestInputFilter implements InputFilter {
031:
032: /**
033: * The original request body.
034: */
035: protected ByteChunk input = null;
036:
037: /**
038: * Create a new SavedRequestInputFilter.
039: *
040: * @param input The saved request body to be replayed.
041: */
042: public SavedRequestInputFilter(ByteChunk input) {
043: this .input = input;
044: }
045:
046: /**
047: * Read bytes.
048: */
049: public int doRead(ByteChunk chunk, org.apache.coyote.Request request)
050: throws IOException {
051: int writeLength = 0;
052:
053: if (chunk.getLimit() > 0
054: && chunk.getLimit() < input.getLength()) {
055: writeLength = chunk.getLimit();
056: } else {
057: writeLength = input.getLength();
058: }
059:
060: if (input.getOffset() >= input.getEnd())
061: return -1;
062:
063: input.substract(chunk.getBuffer(), 0, writeLength);
064: chunk.setOffset(0);
065: chunk.setEnd(writeLength);
066:
067: return writeLength;
068: }
069:
070: /**
071: * Set the content length on the request.
072: */
073: public void setRequest(org.apache.coyote.Request request) {
074: request.setContentLength(input.getLength());
075: }
076:
077: /**
078: * Make the filter ready to process the next request.
079: */
080: public void recycle() {
081: input = null;
082: }
083:
084: /**
085: * Return the name of the associated encoding; here, the value is null.
086: */
087: public ByteChunk getEncodingName() {
088: return null;
089: }
090:
091: /**
092: * Set the next buffer in the filter pipeline (has no effect).
093: */
094: public void setBuffer(InputBuffer buffer) {
095: }
096:
097: /**
098: * Amount of bytes still available in a buffer.
099: */
100: public int available() {
101: return input.getLength();
102: }
103:
104: /**
105: * End the current request (has no effect).
106: */
107: public long end() throws IOException {
108: return 0;
109: }
110:
111: }
|