import org.apache.coyote.Request;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.http.MimeHeaders;
+import org.apache.tomcat.util.net.AbstractEndpoint;
+import org.apache.tomcat.util.net.SocketWrapper;
import org.apache.tomcat.util.res.StringManager;
-public abstract class AbstractInputBuffer implements InputBuffer{
+public abstract class AbstractInputBuffer<S> implements InputBuffer{
protected static final boolean[] HTTP_TOKEN_CHAR = new boolean[128];
}
- public abstract boolean parseRequestLine(boolean useAvailableDataOnly) throws IOException;
+ public abstract boolean parseRequestLine(boolean useAvailableDataOnly)
+ throws IOException;
public abstract boolean parseHeaders() throws IOException;
protected abstract boolean fill(boolean block) throws IOException;
+ protected abstract void init(SocketWrapper<S> socketWrapper,
+ AbstractEndpoint endpoint) throws IOException;
+
// --------------------------------------------------------- Public Methods
// Setting up the socket
this.socket = socketWrapper;
+ inputBuffer.init(socketWrapper, endpoint);
long socketRef = socketWrapper.getSocket().longValue();
- inputBuffer.setSocket(socketRef);
outputBuffer.setSocket(socketRef);
// Error flag
}
@Override
- protected AbstractInputBuffer getInputBuffer() {
+ protected AbstractInputBuffer<Long> getInputBuffer() {
return inputBuffer;
}
// Setting up the socket
this.socket = socketWrapper;
- inputBuffer.setSocket(this.socket.getSocket());
+ inputBuffer.init(socketWrapper, endpoint);
outputBuffer.setSocket(this.socket.getSocket());
- inputBuffer.setSelectorPool(((NioEndpoint)endpoint).getSelectorPool());
outputBuffer.setSelectorPool(((NioEndpoint)endpoint).getSelectorPool());
// Error flag
}
@Override
- protected AbstractInputBuffer getInputBuffer() {
+ protected AbstractInputBuffer<NioChannel> getInputBuffer() {
return inputBuffer;
}
// Setting up the I/O
this.socket = socketWrapper;
- inputBuffer.setInputStream(socket.getSocket().getInputStream());
+ inputBuffer.init(socketWrapper, endpoint);
outputBuffer.setOutputStream(socket.getSocket().getOutputStream());
// Error flag
}
@Override
- protected AbstractInputBuffer getInputBuffer() {
+ protected AbstractInputBuffer<Socket> getInputBuffer() {
return inputBuffer;
}
import org.apache.tomcat.jni.Status;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.net.AbstractEndpoint;
+import org.apache.tomcat.util.net.SocketWrapper;
/**
* Implementation of InputBuffer which provides HTTP request header parsing as
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
*/
-public class InternalAprInputBuffer extends AbstractInputBuffer {
+public class InternalAprInputBuffer extends AbstractInputBuffer<Long> {
private static final Log log =
LogFactory.getLog(InternalAprInputBuffer.class);
/**
* Direct byte buffer used to perform actual reading.
*/
- protected ByteBuffer bbuf;
+ private ByteBuffer bbuf;
/**
* Underlying socket.
*/
- protected long socket;
-
-
- // ------------------------------------------------------------- Properties
-
-
- /**
- * Set the underlying socket.
- */
- public void setSocket(long socket) {
- this.socket = socket;
- Socket.setrbb(this.socket, bbuf);
- }
-
-
- /**
- * Get the underlying socket input stream.
- */
- public long getSocket() {
- return socket;
- }
+ private long socket;
// --------------------------------------------------------- Public Methods
-
/**
* Recycle the input buffer. This should be called when closing the
* connection.
* HTTP header parsing is done
*/
@SuppressWarnings("null") // headerValue cannot be null
- public boolean parseHeader()
+ private boolean parseHeader()
throws IOException {
//
// ------------------------------------------------------ Protected Methods
+ @Override
+ protected void init(SocketWrapper<Long> socketWrapper,
+ AbstractEndpoint endpoint) throws IOException {
+
+ socket = socketWrapper.getSocket().longValue();
+ Socket.setrbb(this.socket, bbuf);
+ }
+
@Override
protected boolean fill(boolean block) throws IOException {
pos = lastValid;
return (length);
-
}
-
-
}
-
-
}
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.Socket;
import java.nio.charset.Charset;
import org.apache.coyote.InputBuffer;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.net.AbstractEndpoint;
+import org.apache.tomcat.util.net.SocketWrapper;
/**
* Implementation of InputBuffer which provides HTTP request header parsing as
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
*/
-public class InternalInputBuffer extends AbstractInputBuffer {
+public class InternalInputBuffer extends AbstractInputBuffer<Socket> {
private static final Log log = LogFactory.getLog(InternalInputBuffer.class);
/**
* Underlying input stream.
*/
- protected InputStream inputStream;
+ private InputStream inputStream;
/**
/**
- * Set the underlying socket input stream.
- */
- public void setInputStream(InputStream inputStream) {
-
- // FIXME: Check for null ?
-
- this.inputStream = inputStream;
-
- }
-
-
- /**
- * Get the underlying socket input stream.
- */
- public InputStream getInputStream() {
-
- return inputStream;
-
- }
-
-
- /**
* Read the request line. This function is meant to be used during the
* HTTP request header parsing. Do NOT attempt to read the request body
* using it.
* HTTP header parsing is done
*/
@SuppressWarnings("null") // headerValue cannot be null
- public boolean parseHeader()
+ private boolean parseHeader()
throws IOException {
//
// ------------------------------------------------------ Protected Methods
+ @Override
+ protected void init(SocketWrapper<Socket> socketWrapper,
+ AbstractEndpoint endpoint) throws IOException {
+ inputStream = socketWrapper.getSocket().getInputStream();
+ }
+
+
+
private void skipLine(int start) throws IOException {
boolean eol = false;
int lastRealByte = start;
pos = lastValid;
return (length);
-
}
-
-
}
-
-
}
import org.apache.coyote.Request;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.net.AbstractEndpoint;
import org.apache.tomcat.util.net.NioChannel;
import org.apache.tomcat.util.net.NioEndpoint;
import org.apache.tomcat.util.net.NioSelectorPool;
+import org.apache.tomcat.util.net.SocketWrapper;
/**
* Implementation of InputBuffer which provides HTTP request header parsing as
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @author Filip Hanik
*/
-public class InternalNioInputBuffer extends AbstractInputBuffer {
+public class InternalNioInputBuffer extends AbstractInputBuffer<NioChannel> {
private static final org.apache.juli.logging.Log log =
org.apache.juli.logging.LogFactory.getLog(InternalNioInputBuffer.class);
* Parsing state - used for non blocking parsing so that
* when more data arrives, we can pick up where we left off.
*/
- protected boolean parsingRequestLine;
- protected int parsingRequestLinePhase = 0;
- protected boolean parsingRequestLineEol = false;
- protected int parsingRequestLineStart = 0;
- protected int parsingRequestLineQPos = -1;
- protected HeaderParsePosition headerParsePos;
+ private boolean parsingRequestLine;
+ private int parsingRequestLinePhase = 0;
+ private boolean parsingRequestLineEol = false;
+ private int parsingRequestLineStart = 0;
+ private int parsingRequestLineQPos = -1;
+ private HeaderParsePosition headerParsePos;
/**
* Underlying socket.
*/
- protected NioChannel socket;
+ private NioChannel socket;
/**
* Selector pool, for blocking reads and blocking writes
*/
- protected NioSelectorPool pool;
+ private NioSelectorPool pool;
/**
*/
private int skipBlankLinesBytes;
- // ------------------------------------------------------------- Properties
-
-
- /**
- * Set the underlying socket.
- */
- public void setSocket(NioChannel socket) {
- this.socket = socket;
- socketReadBufferSize = socket.getBufHandler().getReadBuffer().capacity();
- int bufLength = skipBlankLinesSize + headerBufferSize
- + socketReadBufferSize;
- if (buf == null || buf.length < bufLength) {
- buf = new byte[bufLength];
- }
- }
-
- /**
- * Get the underlying socket input stream.
- */
- public NioChannel getSocket() {
- return socket;
- }
-
- public void setSelectorPool(NioSelectorPool pool) {
- this.pool = pool;
- }
-
- public NioSelectorPool getSelectorPool() {
- return pool;
- }
-
// --------------------------------------------------------- Public Methods
- /**
- * Issues a non blocking read
- * @return int
- * @throws IOException
- */
- public int nbRead() throws IOException {
- return readSocket(true,false);
- }
/**
* Recycle the input buffer. This should be called when closing the
if ( block ) {
Selector selector = null;
try {
- selector = getSelectorPool().get();
+ selector = pool.get();
} catch ( IOException x ) {
// Ignore
}
try {
NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
if ( att == null ) throw new IOException("Key must be cancelled.");
- nRead = getSelectorPool().read(socket.getBufHandler().getReadBuffer(),socket,selector,att.getTimeout());
+ nRead = pool.read(socket.getBufHandler().getReadBuffer(),socket,selector,att.getTimeout());
} catch ( EOFException eof ) {
nRead = -1;
} finally {
- if ( selector != null ) getSelectorPool().put(selector);
+ if ( selector != null ) pool.put(selector);
}
} else {
nRead = socket.read(socket.getBufHandler().getReadBuffer());
* @return false after reading a blank line (which indicates that the
* HTTP header parsing is done
*/
- public HeaderParseStatus parseHeader()
+ private HeaderParseStatus parseHeader()
throws IOException {
//
return HeaderParseStatus.HAVE_MORE_HEADERS;
}
+ public int getParsingRequestLinePhase() {
+ return parsingRequestLinePhase;
+ }
+
private HeaderParseStatus skipLine() throws IOException {
headerParsePos = HeaderParsePosition.HEADER_SKIPLINE;
boolean eol = false;
return HeaderParseStatus.HAVE_MORE_HEADERS;
}
- protected HeaderParseData headerData = new HeaderParseData();
+ private HeaderParseData headerData = new HeaderParseData();
public static class HeaderParseData {
int start = 0;
int realPos = 0;
// ------------------------------------------------------ Protected Methods
+ @Override
+ protected void init(SocketWrapper<NioChannel> socketWrapper,
+ AbstractEndpoint endpoint) throws IOException {
+
+ socket = socketWrapper.getSocket();
+ socketReadBufferSize =
+ socket.getBufHandler().getReadBuffer().capacity();
+
+ int bufLength = skipBlankLinesSize + headerBufferSize
+ + socketReadBufferSize;
+ if (buf == null || buf.length < bufLength) {
+ buf = new byte[bufLength];
+ }
+
+ pool = ((NioEndpoint)endpoint).getSelectorPool();
+ }
+
+
/**
* Fill the internal buffer using data from the underlying input stream.
*
pos = lastValid;
return (length);
-
}
-
-
- }
-
-
- public int getParsingRequestLinePhase() {
- return parsingRequestLinePhase;
}
-
-
}