NoParsingHandlerpublic class NoParsingHandler 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 NoParsingHandler()
|
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 request, int handlerCode)Intercept the request and decide if we cache the static resource. If the
static resource is already cached, return it.
if ( socketChannel == null || !FileCacheFactory.isEnabled())
return Handler.CONTINUE;
// If not initialized, dont' continue
if ( fileCache == null && handlerCode != Handler.RESPONSE_PROCEEDED){
return Handler.CONTINUE;
}
if ( handlerCode == Handler.RESPONSE_PROCEEDED ){
CoyoteRequest cr =
(CoyoteRequest)request.getNote(CoyoteAdapter.ADAPTER_NOTES);
// We can cache it only if no security constraint and no
// filter have been defined.
if ( cr != null && cr.getWrapper() != null){
String mappedServlet = cr.getWrapper().getName();
if ( !mappedServlet.equals(FileCache.DEFAULT_SERVLET_NAME) )
return Handler.CONTINUE;
if ( cr.getContext().findConstraints().length == 0
&& cr.getContext().findFilterDefs().length == 0 ){
if (!fileCache.isEnabled()) return Handler.CONTINUE;
String docroot;
if ( cr.getContextPath().equals("") ){
docroot = cr.getContext().getDocBase();
} else {
docroot = SelectorThread.getWebAppRootPath();
}
String requestURI = cr.getRequestURI();
Response response = cr.getCoyoteRequest().getResponse();
MimeHeaders headers = response.getMimeHeaders();
boolean xPoweredBy = (
(CoyoteConnector)cr.getConnector()).isXpoweredBy();
fileCache.add(mappedServlet,docroot,requestURI,headers,
xPoweredBy);
}
}
} else if ( handlerCode == Handler.REQUEST_LINE_PARSED ) {
ByteChunk bc = request.requestURI().getByteChunk();
if ( fileCache.sendCache(bc.getBytes(),bc.getStart(),
bc.getLength(),socketChannel,keepAlive(request)) ){
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;
|
|