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

public Class CLStaticHttpHandler

extends StaticHttpHandlerBase
Class Inheritance
Imports
java.io.File, .FileNotFoundException, .IOException, .InputStream, java.net.JarURLConnection, .MalformedURLException, .URI, .URL, .URLConnection, java.util.jar.JarEntry, .JarFile, java.util.logging.Level, .Logger, org.glassfish.grizzly.Buffer, .Grizzly, .WriteHandler, org.glassfish.grizzly.filterchain.FilterChainContext, org.glassfish.grizzly.http.Method, org.glassfish.grizzly.http.io.NIOOutputStream, org.glassfish.grizzly.http.server.filecache.FileCache, org.glassfish.grizzly.http.util.Header, .HttpStatus, org.glassfish.grizzly.memory.BufferArray, .MemoryManager, org.glassfish.grizzly.utils.ArraySet

HttpHandler, which processes requests to a static resources resolved by a given ClassLoader.
Author
Grizzly Team

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class

Field Summary

Modifier and TypeField and Description
private static final boolean
CHECK_NON_SLASH_TERMINATED_FOLDERS

true (default) if we want to double-check the resource requests, that don't have terminating slash if they represent a folder and try to retrieve a welcome resource from the folder.

protected static final String
private final ClassLoader
private final ArraySet<String>
private static final String
private static final Logger
private static final String

Constructor Summary

AccessConstructor and Description
public
CLStaticHttpHandler(final ClassLoader
ClassLoader to be used to resolve the resources
classLoader
,
final String...
the doc roots (path prefixes), which will be used to find resources. Effectively each docRoot will be prepended to a resource path before passing it to ClassLoader#getResource(java.lang.String). If no docRoots are set - the resources will be searched starting from ClassLoader's root.
docRoots
)

Create HttpHandler, which will handle requests to the static resources resolved by the given class loader.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this docroot hasn't been registered before, or false otherwise.
addDocRoot
(final String docRoot)

Adds doc root (path prefix), which will be used to look up resources.

private boolean
addTimeStampEntryToFileCache(final Request req, final Response res, final File archive)

private static void
closeJarFileIfNeeded(final JarURLConnection jarConnection, final JarFile jarFile)

public ClassLoader
getClassLoader()

Returns the ClassLoader used to resolve the requested HTTP resources.

private File
getJarFile(final String path)

protected boolean
handle(String resourcePath, final Request request, final Response response)

Implements abstract org.glassfish.grizzly.http.server.StaticHttpHandlerBase.handle.

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

private URL
lookupResource(String resourcePath)

public boolean

Returns:

true if this docroot was found and removed from the list, or or false if this docroot was not found in the list.
removeDocRoot
(final String docRoot)

Removes docRoot from the doc root list.

private static void
sendResource(final Response response, final InputStream input)

Inherited from org.glassfish.grizzly.http.server.StaticHttpHandlerBase:
addCachingHeadersaddToFileCachegetRelativeURIisFileCacheEnabledlookupFileCacheonMissingResourcepickupContentTypesendFileservicesetFileCacheEnabled

Field Detail

CHECK_NON_SLASH_TERMINATED_FOLDERSback to summary
private static final boolean CHECK_NON_SLASH_TERMINATED_FOLDERS

true (default) if we want to double-check the resource requests, that don't have terminating slash if they represent a folder and try to retrieve a welcome resource from the folder.

CHECK_NON_SLASH_TERMINATED_FOLDERS_PROPback to summary
protected static final String CHECK_NON_SLASH_TERMINATED_FOLDERS_PROP
classLoaderback to summary
private final ClassLoader classLoader
docRootsback to summary
private final ArraySet<String> docRoots
EMPTY_STRback to summary
private static final String EMPTY_STR
LOGGERback to summary
private static final Logger LOGGER

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

SLASH_STRback to summary
private static final String SLASH_STR

Constructor Detail

CLStaticHttpHandlerback to summary
public CLStaticHttpHandler(final ClassLoader classLoader, final String... docRoots)

Create HttpHandler, which will handle requests to the static resources resolved by the given class loader.

Parameters
classLoader:ClassLoader

ClassLoader to be used to resolve the resources

docRoots:String[]

the doc roots (path prefixes), which will be used to find resources. Effectively each docRoot will be prepended to a resource path before passing it to ClassLoader#getResource(java.lang.String). If no docRoots are set - the resources will be searched starting from ClassLoader's root.

Exceptions
IllegalArgumentException:
if one of the docRoots doesn't end with slash ('/')

Method Detail

addDocRootback to summary
public boolean addDocRoot(final String docRoot)

Adds doc root (path prefix), which will be used to look up resources. Effectively each registered docRoot will be prepended to a resource path before passing it to ClassLoader#getResource(java.lang.String).

Returns:boolean

true if this docroot hasn't been registered before, or false otherwise.

Exceptions
IllegalArgumentException:
if one of the docRoots doesn't end with slash ('/')
addTimeStampEntryToFileCacheback to summary
private boolean addTimeStampEntryToFileCache(final Request req, final Response res, final File archive)
closeJarFileIfNeededback to summary
private static void closeJarFileIfNeeded(final JarURLConnection jarConnection, final JarFile jarFile) throws IOException
getClassLoaderback to summary
public ClassLoader getClassLoader()

Returns the ClassLoader used to resolve the requested HTTP resources.

getJarFileback to summary
private File getJarFile(final String path) throws MalformedURLException, FileNotFoundException
handleback to summary
protected boolean handle(String resourcePath, final Request request, final Response response) throws Exception

Implements abstract org.glassfish.grizzly.http.server.StaticHttpHandlerBase.handle.

Doc from org.glassfish.grizzly.http.server.StaticHttpHandlerBase.handle.

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

Annotations
@Override
lookupResourceback to summary
private URL lookupResource(String resourcePath)
removeDocRootback to summary
public boolean removeDocRoot(final String docRoot)

Removes docRoot from the doc root list.

Returns:boolean

true if this docroot was found and removed from the list, or or false if this docroot was not found in the list.

sendResourceback to summary
private static void sendResource(final Response response, final InputStream input) throws IOException
org.glassfish.grizzly.http.server back to summary

pack-priv Class CLStaticHttpHandler.JarURLInputStream

extends FilterInputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final JarURLConnection
private final JarFile
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
pack-priv
JarURLInputStream(final JarURLConnection jarConnection, final JarFile jarFile, final InputStream src)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

Inherited from java.io.FilterInputStream:
availablemarkmarkSupportedreadreadreadresetskip

Field Detail

jarConnectionback to summary
private final JarURLConnection jarConnection
jarFileback to summary
private final JarFile jarFile

Constructor Detail

JarURLInputStreamback to summary
pack-priv JarURLInputStream(final JarURLConnection jarConnection, final JarFile jarFile, final InputStream src)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterInputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
org.glassfish.grizzly.http.server back to summary

private Class CLStaticHttpHandler.NonBlockingDownloadHandler

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

Field Summary

Modifier and TypeField and Description
private final int
private final InputStream
private final MemoryManager<E extends Buffer>
private final NIOOutputStream
private final Response

Constructor Summary

AccessConstructor and Description
pack-priv
NonBlockingDownloadHandler(final Response response, final NIOOutputStream outputStream, final InputStream inputStream, 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
inputStreamback to summary
private final InputStream inputStream
mmback to summary
private final MemoryManager<E extends Buffer> mm
outputStreamback to summary
private final NIOOutputStream outputStream
responseback to summary
private final Response response

Constructor Detail

NonBlockingDownloadHandlerback to summary
pack-priv NonBlockingDownloadHandler(final Response response, final NIOOutputStream outputStream, final InputStream inputStream, 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