Package org.jgrapes.http
Class StaticContentDispatcher
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.http.StaticContentDispatcher
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
A dispatcher for requests for static content, usually files.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
-
Constructor Summary
ConstructorDescriptionStaticContentDispatcher
(String resourcePattern, URI contentRoot) Creates a new component base with its channel set to itself.StaticContentDispatcher
(Channel componentChannel, String resourcePattern, URI contentRoot) Creates new dispatcher that tries to fulfill requests matching the given resource pattern from the given content root. -
Method Summary
Modifier and TypeMethodDescriptionvoid
onGet
(Request.In.Get event, IOSubchannel channel) Handles aGET
request.void
setMaxAgeCalculator
(ResponseCreationSupport.MaxAgeCalculator maxAgeCalculator) Sets theResponseCreationSupport.MaxAgeCalculator
for generating theCache-Control
(max-age
) header of the response.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
StaticContentDispatcher
Creates new dispatcher that tries to fulfill requests matching the given resource pattern from the given content root.An attempt is made to convert the content root to a
Path
in aFileSystem
. If this fails, the content root is used as a URL against which requests are resolved and data is obtained by open an input stream from the resulting URL. In the latter case modification times aren’t available.- Parameters:
componentChannel
- this component’s channelresourcePattern
- the pattern that requests must match in order to be handled by this component (seeResourcePattern
)contentRoot
- the location with content to serve- See Also:
-
StaticContentDispatcher
Creates a new component base with its channel set to itself.- Parameters:
resourcePattern
- the pattern that requests must match with to be handled by this component (seeResourcePattern.matches(String, java.net.URI)
)contentRoot
- the location with content to serve- See Also:
-
-
Method Details
-
maxAgeCalculator
- Returns:
- the maxAgeCalculator
-
setMaxAgeCalculator
Sets theResponseCreationSupport.MaxAgeCalculator
for generating theCache-Control
(max-age
) header of the response.The default max age calculator used simply returns a max age of one year, since this component is intended to serve static content.
- Parameters:
maxAgeCalculator
- the maxAgeCalculator to set
-
onGet
@RequestHandler(dynamic=true) public void onGet(Request.In.Get event, IOSubchannel channel) throws ParseException, IOException Handles aGET
request.- Parameters:
event
- the eventchannel
- the channel- Throws:
ParseException
- the parse exceptionIOException
- Signals that an I/O exception has occurred.
-