StaticHandlerpublic class StaticHandler extends Object implements com.sun.enterprise.web.connector.grizzly.HandlerThis Handler is invoked after the request line has been parsed. |
Fields Summary |
---|
private SocketChannel | socketChannelThe SocketChannel used to send a static resources. | protected com.sun.enterprise.web.connector.grizzly.FileCache | fileCacheThe FileCache mechanism used to cache static resources. |
Constructors Summary |
---|
public StaticHandler()
|
Methods Summary |
---|
public void | attachChannel(java.nio.channels.SocketChannel socketChannel)Attach a SocketChannel to this object.
this.socketChannel = socketChannel;
if ( fileCache == null && socketChannel != null){
fileCache = FileCacheFactory.getFactory(
socketChannel.socket().getLocalPort()).getFileCache();
}
| protected int | findBytes(org.apache.tomcat.util.buf.ByteChunk bc, byte[] b)Specialized utility method: find a sequence of lower case bytes inside
a ByteChunk.
byte first = b[0];
byte[] buff = bc.getBuffer();
int start = bc.getStart();
int end = bc.getEnd();
// Look for first char
int srcEnd = b.length;
for (int i = start; i <= (end - srcEnd); i++) {
if (Ascii.toLower(buff[i]) != first) continue;
// found first char, now look for a match
int myPos = i+1;
for (int srcPos = 1; srcPos < srcEnd; ) {
if (Ascii.toLower(buff[myPos++]) != b[srcPos++])
break;
if (srcPos == srcEnd) return i - start; // found it
}
}
return -1;
| public int | handle(org.apache.coyote.Request req, int handlerCode)Intercept the request and decide if we cache the static resource. If the
static resource is already cached, return it.
if (fileCache == null) return Handler.CONTINUE;
if (handlerCode == Handler.RESPONSE_PROCEEDED && fileCache.isEnabled()){
String docroot = SelectorThread.getWebAppRootPath();
MessageBytes mb = req.requestURI();
ByteChunk requestURI = mb.getByteChunk();
String uri = req.requestURI().toString();
fileCache.add(FileCache.DEFAULT_SERVLET_NAME,docroot,uri,
req.getResponse().getMimeHeaders(),false);
} else if (handlerCode == Handler.REQUEST_LINE_PARSED) {
ByteChunk requestURI = req.requestURI().getByteChunk();
if (fileCache.sendCache(requestURI.getBytes(), requestURI.getStart(),
requestURI.getLength(), socketChannel,
keepAlive(req))){
return Handler.BREAK;
}
}
return Handler.CONTINUE;
| private boolean | keepAlive(org.apache.coyote.Request request)Get the keep-alive header.
MimeHeaders headers = request.getMimeHeaders();
// Check connection header
MessageBytes connectionValueMB = headers.getValue("connection");
if (connectionValueMB != null) {
ByteChunk connectionValueBC = connectionValueMB.getByteChunk();
if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) {
return false;
} else if (findBytes(connectionValueBC,
Constants.KEEPALIVE_BYTES) != -1) {
return true;
}
}
return true;
|
|