Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.http.server

public abstract Class StaticHttpHandlerBase

extends HttpHandler
Class Inheritance
Known Direct Subclasses
org.glassfish.grizzly.http.server.CLStaticHttpHandler, org.glassfish.grizzly.http.server.StaticHttpHandler
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .IOException, java.nio.channels.FileChannel, java.util.logging.Level, .Logger, org.glassfish.grizzly.Buffer, .Grizzly, .WriteHandler, org.glassfish.grizzly.filterchain.Filter, .FilterChain, .FilterChainContext, org.glassfish.grizzly.http.io.NIOOutputStream, .OutputBuffer, org.glassfish.grizzly.http.server.filecache.FileCache, org.glassfish.grizzly.http.util.Header, .HttpStatus, .MimeType, org.glassfish.grizzly.memory.Buffers, .MemoryManager

The basic class for HttpHandler implementations, which processes requests to a static resources.
Authors
Jeanfrancois Arcand, Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private volatile int
private volatile boolean
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static void
addCachingHeaders(final Response response, final File file)

public final boolean
addToFileCache(final Request req, final Response res, final File resource)

protected String
getRelativeURI(final Request request)

protected abstract boolean

Returns:

true, if the static resource has been found and processed, or false, if the static resource hasn't been found
handle
(final String
The request URI
uri
,
final Request request, final Response response)

Lookup a resource based on the request URI, and process it.

public boolean

Returns:

true if this StaticHttpHandler has been configured to use file cache to serve static resources, or false otherwise.
isFileCacheEnabled
()

Returns true if this StaticHttpHandler has been configured to use file cache to serve static resources, or false otherwise.

protected FileCacheFilter
protected void
onMissingResource(final Request request, final Response response)

The method will be called, if the static resource requested by the Request wasn't found, so StaticHttpHandler implementation may try to workaround this situation.

protected static void
pickupContentType(final Response response, final String path)

public static void
sendFile(final Response response, final File file)

private static void
sendUsingBuffers(final Response response, final File file)

private static void
sendZeroCopy(final Response response, final File file)

public void
service(final Request request, final Response response)

Implements abstract org.glassfish.grizzly.http.server.HttpHandler.service.

Based on the Request URI, try to map the file from the getDocRoots(), and send it back to a client.

public void
setFileCacheEnabled(boolean
true to configure this StaticHttpHandler to use file cache to serve static resources, or false otherwise.
isFileCacheEnabled
)

Set true to configure this StaticHttpHandler to use file cache to serve static resources, or false otherwise.

Inherited from org.glassfish.grizzly.http.server.HttpHandler:
destroydoHandlegetErrorPageGeneratorgetNamegetRequestExecutorProvidergetRequestURIEncodinggetSessionCookieNamegetSessionManagerisAllowCustomStatusMessageisAllowEncodedSlashsendAcknowledgmentsetAllowCustomStatusMessagesetAllowEncodedSlashsetDecodeUrlsetDispatcherHelpersetRequestURIEncodingsetRequestURIEncodingstartupdatePaths

Field Detail

fileCacheFilterIdxback to summary
private volatile int fileCacheFilterIdx
isFileCacheEnabledback to summary
private volatile boolean isFileCacheEnabled
LOGGERback to summary
private static final Logger LOGGER

Hides org.glassfish.grizzly.http.server.HttpHandler.LOGGER.

Constructor Detail

StaticHttpHandlerBaseback to summary
public StaticHttpHandlerBase()

Method Detail

addCachingHeadersback to summary
protected static void addCachingHeaders(final Response response, final File file)
addToFileCacheback to summary
public final boolean addToFileCache(final Request req, final Response res, final File resource)
getRelativeURIback to summary
protected String getRelativeURI(final Request request) throws Exception
handleback to summary
protected abstract boolean handle(final String uri, final Request request, final Response response) throws Exception

Lookup a resource based on the request URI, and process it.

Parameters
uri:String

The request URI

request:Request

the Request

response:Response

the Response

Returns:boolean

true, if the static resource has been found and processed, or false, if the static resource hasn't been found

isFileCacheEnabledback to summary
public boolean isFileCacheEnabled()

Returns true if this StaticHttpHandler has been configured to use file cache to serve static resources, or false otherwise. Please note, even though this StaticHttpHandler might be configured to use file cache, file cache itself might be disabled FileCache#isEnabled(). In this case StaticHttpHandler will operate as if file cache was disabled.

Returns:boolean

true if this StaticHttpHandler has been configured to use file cache to serve static resources, or false otherwise.

Annotations
@SuppressWarnings:UnusedDeclaration
lookupFileCacheback to summary
protected FileCacheFilter lookupFileCache(final FilterChainContext fcContext)
onMissingResourceback to summary
protected void onMissingResource(final Request request, final Response response) throws Exception

The method will be called, if the static resource requested by the Request wasn't found, so StaticHttpHandler implementation may try to workaround this situation. The default implementation - sends a 404 response page by calling customizedErrorPage(Request, Response).

Parameters
request:Request

the Request

response:Response

the Response

pickupContentTypeback to summary
protected static void pickupContentType(final Response response, final String path)
sendFileback to summary
public static void sendFile(final Response response, final File file) throws IOException
sendUsingBuffersback to summary
private static void sendUsingBuffers(final Response response, final File file) throws FileNotFoundException, IOException
sendZeroCopyback to summary
private static void sendZeroCopy(final Response response, final File file) throws IOException
serviceback to summary
public void service(final Request request, final Response response) throws Exception

Implements abstract org.glassfish.grizzly.http.server.HttpHandler.service.

Based on the Request URI, try to map the file from the getDocRoots(), and send it back to a client.

Parameters
request:Request

the Request

response:Response

the Response

Annotations
@Override
setFileCacheEnabledback to summary
public void setFileCacheEnabled(boolean isFileCacheEnabled)

Set true to configure this StaticHttpHandler to use file cache to serve static resources, or false otherwise. Please note, even though this StaticHttpHandler might be configured to use file cache, file cache itself might be disabled FileCache#isEnabled(). In this case StaticHttpHandler will operate as if file cache was disabled.

Parameters
isFileCacheEnabled:boolean

true to configure this StaticHttpHandler to use file cache to serve static resources, or false otherwise.

Annotations
@SuppressWarnings:UnusedDeclaration
org.glassfish.grizzly.http.server back to summary

private Class StaticHttpHandlerBase.NonBlockingDownloadHandler

extends Object
implements WriteHandler
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.server.StaticHttpHandlerBase.NonBlockingDownloadHandler
All Implemented Interfaces
org.glassfish.grizzly.WriteHandler

Field Summary

Modifier and TypeField and Description
private final int
private final FileChannel
private final MemoryManager<E extends Buffer>
private final NIOOutputStream
private final Response
private volatile long

Constructor Summary

AccessConstructor and Description
pack-priv
NonBlockingDownloadHandler(final Response response, final NIOOutputStream outputStream, final File file, final int chunkSize)

Method Summary

Modifier and TypeMethod and Description
private void
complete(final boolean isError)

Complete the download

public void
onError(Throwable t)

Implements org.glassfish.grizzly.WriteHandler.onError.

Invoked when an error occurs processing the request asynchronously.

public void
onWritePossible()

Implements org.glassfish.grizzly.WriteHandler.onWritePossible.

This callback will be invoked when the requirements as dictated by writer are met.

private boolean
sendChunk()

Send next CHUNK_SIZE of file

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chunkSizeback to summary
private final int chunkSize
fileChannelback to summary
private final FileChannel fileChannel
mmback to summary
private final MemoryManager<E extends Buffer> mm
outputStreamback to summary
private final NIOOutputStream outputStream
responseback to summary
private final Response response
sizeback to summary
private volatile long size

Constructor Detail

NonBlockingDownloadHandlerback to summary
pack-priv NonBlockingDownloadHandler(final Response response, final NIOOutputStream outputStream, final File file, final int chunkSize)

Method Detail

completeback to summary
private void complete(final boolean isError)

Complete the download

onErrorback to summary
public void onError(Throwable t)

Implements org.glassfish.grizzly.WriteHandler.onError.

Doc from org.glassfish.grizzly.WriteHandler.onError.

Invoked when an error occurs processing the request asynchronously.

Annotations
@Override
onWritePossibleback to summary
public void onWritePossible() throws Exception

Implements org.glassfish.grizzly.WriteHandler.onWritePossible.

Doc from org.glassfish.grizzly.WriteHandler.onWritePossible.

This callback will be invoked when the requirements as dictated by writer are met.

Annotations
@Override
Exceptions
Exception:
Exception might be thrown by the custom handler code. This exception will be delegated for processing to onError(java.lang.Throwable).
sendChunkback to summary
private boolean sendChunk() throws IOException

Send next CHUNK_SIZE of file