Package com.mastfrog.acteur
Class Application
java.lang.Object
com.mastfrog.acteur.Application
- Direct Known Subclasses:
GenericApplication
A web application. Principally, the application is a collection of Page
types, which are instantiated per-request and offered the request, in the
order they are added, until one accepts it and takes responsibility for
responding.
- Author:
- Tim Boudreau
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedApplication(Class<?>... types) Create an application, optionally passing in an array of page types (you can also calladd()to add them). -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidprotected final voidAdd a subtype of Page which should be instantiated on demand when responding to requestsstatic ApplicationCreate an applicationprotected io.netty.handler.codec.http.HttpResponsecreateNotFoundResponse(Event<?> event) Create a 404 responseprotected io.netty.handler.codec.http.HttpResponsedecorateResponse(Event<?> event, Page page, Acteur action, io.netty.handler.codec.http.HttpResponse response) Deprecated.Use onBeforeSendResponse insteadprotected final voidgetName()com.mastfrog.giulius.scope.ReentrantScopeGet theScopewhich is holds per-request state.booleanGet the type of the built in help page class, which uses Acteur.describeYourself() and annotations to generate a JSON description of all URLs the application responds tofinal booleanbooleanisEarlyPageMatch(io.netty.handler.codec.http.HttpRequest req) iterator()Get the set of page instances, constructing them dynamically.protected voidonAfterRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, Acteur acteur, Page page, State state, io.netty.handler.codec.http.HttpResponseStatus status, io.netty.handler.codec.http.HttpResponse resp) Override to do any post-response tasksprotected voidonBeforeEvent(com.mastfrog.acteur.util.RequestID id, Event<?> event) Called before an event is processedprotected voidonBeforeRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, io.netty.handler.codec.http.HttpResponseStatus status) Called before the response is sent RequestIDprotected voidonBeforeSendResponse(io.netty.handler.codec.http.HttpResponseStatus status, Event<?> event, Response response, Acteur acteur, Page page) voidDeprecated.Implement ErrorHandler and bind it as an eager singletonprotected voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Application
Create an application, optionally passing in an array of page types (you can also calladd()to add them).- Parameters:
types-
-
Application
protected Application()
-
-
Method Details
-
hasEarlyPages
public boolean hasEarlyPages() -
isEarlyPageMatch
public boolean isEarlyPageMatch(io.netty.handler.codec.http.HttpRequest req) -
helpPageType
Get the type of the built in help page class, which uses Acteur.describeYourself() and annotations to generate a JSON description of all URLs the application responds to- Returns:
- A page type
-
isDefaultCorsHandlingEnabled
public final boolean isDefaultCorsHandlingEnabled() -
enableDefaultCorsHandling
protected final void enableDefaultCorsHandling() -
create
Create an application- Parameters:
types-- Returns:
-
getRequestScope
public com.mastfrog.giulius.scope.ReentrantScope getRequestScope()Get theScopewhich is holds per-request state.- Returns:
-
add
Add a subtype of Page which should be instantiated on demand when responding to requests- Parameters:
page- A page
-
add
-
getName
-
decorateResponse
@Deprecated protected io.netty.handler.codec.http.HttpResponse decorateResponse(Event<?> event, Page page, Acteur action, io.netty.handler.codec.http.HttpResponse response) Deprecated.Use onBeforeSendResponse insteadAdd any custom headers or other attributes - override to intercept all requests.- Parameters:
event-page-action-response-- Returns:
-
createNotFoundResponse
Create a 404 response- Parameters:
event-- Returns:
-
onAfterRespond
protected void onAfterRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, Acteur acteur, Page page, State state, io.netty.handler.codec.http.HttpResponseStatus status, io.netty.handler.codec.http.HttpResponse resp) Override to do any post-response tasks- Parameters:
id- The incrementing ID of the request, for logging purposesevent- The event, usually HttpEventacteur- The final acteur in the chainpage- The page which took responsibility for answering the requeststate- The state produced by the last acteurstatus- The status code for the HTTP responseresp- The HTTP response, from Netty's HTTP codec
-
onBeforeRespond
protected void onBeforeRespond(com.mastfrog.acteur.util.RequestID id, Event<?> event, io.netty.handler.codec.http.HttpResponseStatus status) Called before the response is sent RequestID- Parameters:
id-event-status-
-
onBeforeEvent
Called before an event is processed- Parameters:
id- The request idevent- The event
-
onError
Deprecated.Implement ErrorHandler and bind it as an eager singletonCalled when an exception is thrown- Parameters:
err-
-
iterator
Get the set of page instances, constructing them dynamically. Note that this should be called inside the application scope, with any objects which need to be available for injection available in the scope. -
send404
protected void send404(com.mastfrog.acteur.util.RequestID id, Event<?> event, io.netty.channel.Channel channel) -
onBeforeSendResponse
-