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

public Class HttpHandlerChain

extends HttpHandler
implements JmxEventListener
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.http.server.jmxbase.JmxEventListener
Imports
java.io.CharConversionException, .IOException, java.util.HashMap, .Map, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.locks.ReentrantReadWriteLock, java.util.logging.Level, .Logger, org.glassfish.grizzly.Grizzly, org.glassfish.grizzly.http.HttpRequestPacket, org.glassfish.grizzly.http.server.jmxbase.JmxEventListener, .Monitorable, org.glassfish.grizzly.http.server.util.DispatcherHelper, .Mapper, .MappingData, org.glassfish.grizzly.http.util.DataChunk, .HttpStatus, .RequestURIRef, org.glassfish.grizzly.localization.LogMessages

The HttpHandlerChain class allows the invocation of multiple HttpHandlers every time a new HTTP request is ready to be handled. Requests are mapped to their associated HttpHandler at runtime using the mapping information configured when invoking the (org.glassfish.grizzly.http.server.HttpHandler, java.lang.String[])
Author
Jeanfrancois Arcand

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
private static class
private static interface
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final DispatcherHelper
dispatchHelper

DispatchHelper, which maps path or name to the Mapper entry

private final HttpHandlerChain.FullUrlPathResolver
private final ConcurrentMap<HttpHandler, HttpHandlerRegistration[]>
handlers

The list of HttpHandler instance.

private final ConcurrentMap<String, HttpHandler>
handlersByName

The name -> HttpHandler map.

private int
handlersCount

Number of registered HttpHandlers

private final HttpServer
private boolean
isRootConfigured

Is the root context configured?

private static final String
LOCAL_HOST

The default host.

private static final Logger
private final Mapper
mapper

Internal Mapper used to Map request to their associated HttpHandler

private final ReentrantReadWriteLock
private final ConcurrentMap<HttpHandler, Object>
private static final Map<HttpHandlerRegistration, HttpHandlerChain.PathUpdater>
private volatile HttpHandlerChain.RootHttpHandler
rootHttpHandler

The root HttpHandler, used in cases when HttpHandlerChain has only one HttpHandler registered and this HttpHandler is registered as root resource.

private boolean
started

Flag indicating this HttpHandler has been started.

Constructor Summary

AccessConstructor and Description
public
HttpHandlerChain(final HttpServer httpServer)

Method Summary

Modifier and TypeMethod and Description
public void
addHandler(final HttpHandler
HttpHandler instance
httpHandler
,
final String[]
an array of mapping.
mappings
)

Add a HttpHandler and its associated array of mapping.

public void
addHandler(final HttpHandler
HttpHandler instance
httpHandler
,
final HttpHandlerRegistration[]
an array of mapping.
mappings
)

Add a HttpHandler and its associated array of mapping.

private void
public synchronized void
destroy()

Overrides org.glassfish.grizzly.http.server.HttpHandler.destroy.

Invoked when the HttpServer and may be overridden by custom implementations to perform implementation specific resource reclaimation tasks.

pack-priv boolean
doHandle(final Request request, final Response response)

Overrides org.glassfish.grizzly.http.server.HttpHandler.doHandle.

Pre-processes HttpHandler Request and Response, checks the HTTP acknowledgment and decodes URL if required.

public void
public void
private void
public void
public boolean

Returns:

true if removed
removeHttpHandler
(final HttpHandler
HttpHandler to remove
httpHandler
)

Remove a HttpHandler

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

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

Map the Request to the proper HttpHandler

public synchronized void
start()

Overrides org.glassfish.grizzly.http.server.HttpHandler.start.

Called when the HttpHandler's container is started by invoking HttpServer#start.

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

Field Detail

dispatchHelperback to summary
private final DispatcherHelper dispatchHelper

DispatchHelper, which maps path or name to the Mapper entry

fullUrlPathResolverback to summary
private final HttpHandlerChain.FullUrlPathResolver fullUrlPathResolver
handlersback to summary
private final ConcurrentMap<HttpHandler, HttpHandlerRegistration[]> handlers

The list of HttpHandler instance.

handlersByNameback to summary
private final ConcurrentMap<String, HttpHandler> handlersByName

The name -> HttpHandler map.

handlersCountback to summary
private int handlersCount

Number of registered HttpHandlers

httpServerback to summary
private final HttpServer httpServer
isRootConfiguredback to summary
private boolean isRootConfigured

Is the root context configured?

LOCAL_HOSTback to summary
private static final String LOCAL_HOST

The default host.

LOGGERback to summary
private static final Logger LOGGER

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

mapperback to summary
private final Mapper mapper

Internal Mapper used to Map request to their associated HttpHandler

mapperUpdateLockback to summary
private final ReentrantReadWriteLock mapperUpdateLock
monitorsback to summary
private final ConcurrentMap<HttpHandler, Object> monitors
ROOT_URLSback to summary
private static final Map<HttpHandlerRegistration, HttpHandlerChain.PathUpdater> ROOT_URLS
rootHttpHandlerback to summary
private volatile HttpHandlerChain.RootHttpHandler rootHttpHandler

The root HttpHandler, used in cases when HttpHandlerChain has only one HttpHandler registered and this HttpHandler is registered as root resource.

startedback to summary
private boolean started

Flag indicating this HttpHandler has been started. Any subsequent HttpHandler instances added to this chain after is has been started will have their start() method invoked.

Constructor Detail

HttpHandlerChainback to summary
public HttpHandlerChain(final HttpServer httpServer)

Method Detail

addHandlerback to summary
public void addHandler(final HttpHandler httpHandler, final String[] mappings)

Add a HttpHandler and its associated array of mapping. The mapping data will be used to map incoming request to its associated HttpHandler.

Parameters
httpHandler:HttpHandler

HttpHandler instance

mappings:String[]

an array of mapping.

addHandlerback to summary
public void addHandler(final HttpHandler httpHandler, final HttpHandlerRegistration[] mappings)

Add a HttpHandler and its associated array of mapping. The mapping data will be used to map incoming request to its associated HttpHandler.

Parameters
httpHandler:HttpHandler

HttpHandler instance

mappings:HttpHandlerRegistration[]

an array of mapping.

deregisterJmxForHandlerback to summary
private void deregisterJmxForHandler(final HttpHandler httpHandler)
destroyback to summary
public synchronized void destroy()

Overrides org.glassfish.grizzly.http.server.HttpHandler.destroy.

Doc from org.glassfish.grizzly.http.server.HttpHandler.destroy.

Invoked when the HttpServer and may be overridden by custom implementations to perform implementation specific resource reclaimation tasks. By default, this method does nothing.

Annotations
@Override
doHandleback to summary
pack-priv boolean doHandle(final Request request, final Response response) throws Exception

Overrides org.glassfish.grizzly.http.server.HttpHandler.doHandle.

Doc from org.glassfish.grizzly.http.server.HttpHandler.doHandle.

Pre-processes HttpHandler Request and Response, checks the HTTP acknowledgment and decodes URL if required. Then passes control to service(Request, Response).

Annotations
@Override
Exceptions
Exception:
if an error occurs serving a static resource or from the invocation of service(Request, Response)
jmxDisabledback to summary
public void jmxDisabled()

Implements org.glassfish.grizzly.http.server.jmxbase.JmxEventListener.jmxDisabled.

Doc from org.glassfish.grizzly.http.server.jmxbase.JmxEventListener.jmxDisabled.

Invoked when JMX has been disabled.

Annotations
@Override
jmxEnabledback to summary
public void jmxEnabled()

Implements org.glassfish.grizzly.http.server.jmxbase.JmxEventListener.jmxEnabled.

Doc from org.glassfish.grizzly.http.server.jmxbase.JmxEventListener.jmxEnabled.

Invoked when JMX has been enabled.

Annotations
@Override
registerJmxForHandlerback to summary
private void registerJmxForHandler(final HttpHandler httpHandler)
removeAllHttpHandlersback to summary
public void removeAllHttpHandlers()
removeHttpHandlerback to summary
public boolean removeHttpHandler(final HttpHandler httpHandler)

Remove a HttpHandler

Parameters
httpHandler:HttpHandler

HttpHandler to remove

Returns:boolean

true if removed

serviceback to summary
public void service(final Request request, final Response response) throws Exception

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

Map the Request to the proper HttpHandler

Parameters
request:Request

The Request

response:Response

The Response

Annotations
@Override
startback to summary
public synchronized void start()

Overrides org.glassfish.grizzly.http.server.HttpHandler.start.

Doc from org.glassfish.grizzly.http.server.HttpHandler.start.

Called when the HttpHandler's container is started by invoking HttpServer#start. By default, it does nothing.

Annotations
@Override
org.glassfish.grizzly.http.server back to summary

private final Class HttpHandlerChain.DispatchHelperImpl

extends Object
implements DispatcherHelper
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.server.HttpHandlerChain.DispatchHelperImpl
All Implemented Interfaces
org.glassfish.grizzly.http.server.util.DispatcherHelper

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DispatchHelperImplback to summary
private DispatchHelperImpl()

Method Detail

mapNameback to summary
public void mapName(final DataChunk name, final MappingData mappingData)

Implements org.glassfish.grizzly.http.server.util.DispatcherHelper.mapName.

Annotations
@Override
mapPathback to summary
public void mapPath(final HttpRequestPacket requestPacket, final DataChunk path, final MappingData mappingData) throws Exception

Implements org.glassfish.grizzly.http.server.util.DispatcherHelper.mapPath.

Annotations
@Override
org.glassfish.grizzly.http.server back to summary

private Class HttpHandlerChain.EmptyPathUpdater

extends Object
implements PathUpdater
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.server.HttpHandlerChain.EmptyPathUpdater
All Implemented Interfaces
org.glassfish.grizzly.http.server.HttpHandlerChain.PathUpdater

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EmptyPathUpdaterback to summary
private EmptyPathUpdater()

Method Detail

updateback to summary
public void update(final HttpHandlerChain handlerChain, final HttpHandler httpHandler, final Request request)

Implements org.glassfish.grizzly.http.server.HttpHandlerChain.PathUpdater.update.

Annotations
@Override
org.glassfish.grizzly.http.server back to summary

private Class HttpHandlerChain.FullUrlPathResolver

extends Object
implements PathResolver
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.server.HttpHandlerChain.FullUrlPathResolver
All Implemented Interfaces
org.glassfish.grizzly.http.server.Request.PathResolver

Field Summary

Modifier and TypeField and Description
private final HttpHandler

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

httpHandlerback to summary
private final HttpHandler httpHandler

Constructor Detail

FullUrlPathResolverback to summary
public FullUrlPathResolver(HttpHandler httpHandler)

Method Detail

resolveback to summary
public String resolve(final Request request)

Implements org.glassfish.grizzly.http.server.Request.PathResolver.resolve.

Annotations
@Override
org.glassfish.grizzly.http.server back to summary

private Interface HttpHandlerChain.PathUpdater

Known Direct Implementers
org.glassfish.grizzly.http.server.HttpHandlerChain.SlashPathUpdater, org.glassfish.grizzly.http.server.HttpHandlerChain.SlashStarPathUpdater, org.glassfish.grizzly.http.server.HttpHandlerChain.EmptyPathUpdater

Method Summary

Modifier and TypeMethod and Description
public void
update(HttpHandlerChain handlerChain, HttpHandler httpHandler, Request request)

Method Detail

updateback to summary
public void update(HttpHandlerChain handlerChain, HttpHandler httpHandler, Request request)
org.glassfish.grizzly.http.server back to summary

private final Class HttpHandlerChain.RootHttpHandler

extends Object
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.server.HttpHandlerChain.RootHttpHandler

Field Summary

Modifier and TypeField and Description
private final HttpHandler
private final HttpHandlerChain.PathUpdater

Constructor Summary

AccessConstructor and Description
public
RootHttpHandler(final HttpHandler httpHandler, final HttpHandlerChain.PathUpdater pathUpdater)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

httpHandlerback to summary
private final HttpHandler httpHandler
pathUpdaterback to summary
private final HttpHandlerChain.PathUpdater pathUpdater

Constructor Detail

RootHttpHandlerback to summary
public RootHttpHandler(final HttpHandler httpHandler, final HttpHandlerChain.PathUpdater pathUpdater)
org.glassfish.grizzly.http.server back to summary

private Class HttpHandlerChain.SlashPathUpdater

extends Object
implements PathUpdater
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.server.HttpHandlerChain.SlashPathUpdater
All Implemented Interfaces
org.glassfish.grizzly.http.server.HttpHandlerChain.PathUpdater

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SlashPathUpdaterback to summary
private SlashPathUpdater()

Method Detail

updateback to summary
public void update(final HttpHandlerChain handlerChain, final HttpHandler httpHandler, final Request request)

Implements org.glassfish.grizzly.http.server.HttpHandlerChain.PathUpdater.update.

Annotations
@Override
org.glassfish.grizzly.http.server back to summary

private Class HttpHandlerChain.SlashStarPathUpdater

extends Object
implements PathUpdater
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.http.server.HttpHandlerChain.SlashStarPathUpdater
All Implemented Interfaces
org.glassfish.grizzly.http.server.HttpHandlerChain.PathUpdater

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SlashStarPathUpdaterback to summary
private SlashStarPathUpdater()

Method Detail

updateback to summary
public void update(final HttpHandlerChain handlerChain, final HttpHandler httpHandler, final Request request)

Implements org.glassfish.grizzly.http.server.HttpHandlerChain.PathUpdater.update.

Annotations
@Override