Class Action<A extends Action>
- java.lang.Object
-
- io.inversion.Rule<A>
-
- io.inversion.Action<A>
-
- All Implemented Interfaces:
java.lang.Comparable<A>
- Direct Known Subclasses:
BatchAction,DbAction,DbDeleteAction,DbGetAction,FileAction,Filter,MockAction
public class Action<A extends Action> extends Rule<A>
Actions perform some work when matched to a Request and potentially contribute to the content of the Response.The Action Sandwich
Nearly the entire job of the Engine and Api Endpoint configuration is to match one or more Action subclass instances to a Request. All matched actions are sorted by their
orderproperty and executed in sequence as a Chain of Responsibility pattern. Colloquially, at Rocket Partners we somehow started to call this the 'action sandwich'.If an Action should be run across multiple Endpoints, a logging or security Action for example, it can be added directly to an Api via Api.withAction.
In most cases however, you will group sets of related actions under an Endpoint and add the Endpoint to the Api.
Both Api registered Actions and Endpoint registered Actions can be selected into the 'action sandwich' for a particular Request.
One big difference however is that
includesPathsandexcludePathsare relative to the Api path forApi registered Actions and relative to the Endpoint path for Endpoint registered actions. They are all sorted togeter in one big group according to order.
Handling Requests
Once the Engine has selected the Actions to run for a given request (creating the 'action sandwich'), they are all loaded into a Chain object which is responsible for invoking
run(Request, Response)on each one in sequence.You can override
runto process all Requests this Action is selected for, or you can override any of the HTTP method specific doGet/Post/Put/Patch/Delete() handlers if you want to segregate your business logic by HTTP method.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.inversion.Rule
Rule.RuleMatcher
-
-
Field Summary
-
Fields inherited from class io.inversion.Rule
ALL_METHODS, configMap, description, excludeMatchers, excludeOn, includeMatchers, includeOn, log, name, order, params
-
-
Constructor Summary
Constructors Constructor Description Action()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureOp(io.inversion.utils.Task task, Op op)This task has been selected to run as part of the supplied operation, this callback allows actions to perform any custom configuration on the op.voiddoDelete(Request req, Response res)Handle an HTTP DELETE.voiddoGet(Request req, Response res)Handle an HTTP GET.voiddoPatch(Request req, Response res)Handle an HTTP PATCH.voiddoPost(Request req, Response res)Handle an HTTP POST.voiddoPut(Request req, Response res)Handle an HTTP PUT.java.util.List<io.inversion.utils.Path>getFullIncludePaths(Api api, Db db, java.lang.String method, io.inversion.utils.Path endpointPath, boolean relative)protected java.util.LinkedHashSet<io.inversion.utils.Path>getIncludePaths(Api api, Db db, java.lang.String method)booleanisDecoration()static io.inversion.utils.PathjoinPaths(io.inversion.utils.Path endpointPath, io.inversion.utils.Path actionPath, boolean relative)static io.inversion.utils.PathjoinPaths0(io.inversion.utils.Path endpointPath, io.inversion.utils.Path actionPath, boolean relative)voidrun(Request req, Response res)Override this method with your custom business logic or override one of the http method "doMETHOD" specific handlers.protected voidrun0(Request req, Response res)AwithDecoration(boolean decoration)-
Methods inherited from class io.inversion.Rule
afterWiringComplete, checkLazyConfig, compareTo, doLazyConfig, getAllExcludePaths, getAllIncludeMethods, getAllIncludePaths, getDefaultIncludeMatchers, getDescription, getExcludeMatchers, getIncludeMatchers, getName, getOrder, getParams, match, match, matches, matches, toString, withDescription, withExcludeOn, withExcludeOn, withIncludeOn, withIncludeOn, withName, withOrder, withParam, withParams
-
-
-
-
Method Detail
-
getFullIncludePaths
public java.util.List<io.inversion.utils.Path> getFullIncludePaths(Api api, Db db, java.lang.String method, io.inversion.utils.Path endpointPath, boolean relative)
-
getIncludePaths
protected java.util.LinkedHashSet<io.inversion.utils.Path> getIncludePaths(Api api, Db db, java.lang.String method)
-
joinPaths
public static io.inversion.utils.Path joinPaths(io.inversion.utils.Path endpointPath, io.inversion.utils.Path actionPath, boolean relative)
-
joinPaths0
public static io.inversion.utils.Path joinPaths0(io.inversion.utils.Path endpointPath, io.inversion.utils.Path actionPath, boolean relative)
-
configureOp
public void configureOp(io.inversion.utils.Task task, Op op)This task has been selected to run as part of the supplied operation, this callback allows actions to perform any custom configuration on the op.- Parameters:
task-op-
-
run
public void run(Request req, Response res) throws ApiException
Override this method with your custom business logic or override one of the http method "doMETHOD" specific handlers.- Parameters:
req- the Request being servicedres- the Reponse being generated- Throws:
ApiException
-
run0
protected void run0(Request req, Response res) throws ApiException
- Throws:
ApiException
-
doGet
public void doGet(Request req, Response res) throws ApiException
Handle an HTTP GET.Override run() to handle all requests or override this method with your business logic specifically for a GET request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doPost
public void doPost(Request req, Response res) throws ApiException
Handle an HTTP POST.Override run() to handle all requests or override this method with your business logic for a POST request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doPut
public void doPut(Request req, Response res) throws ApiException
Handle an HTTP PUT.Override run() to handle all requests or override this method with your business logic for a PUT request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doPatch
public void doPatch(Request req, Response res) throws ApiException
Handle an HTTP PATCH.Override run() to handle all requests or override this method with your business logic for a PATCH request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
doDelete
public void doDelete(Request req, Response res) throws ApiException
Handle an HTTP DELETE.Override run() to handle all requests or override this method with your business logic for a DELETE request
- Parameters:
req- the request to runres- the response to populate- Throws:
ApiException
-
isDecoration
public boolean isDecoration()
-
withDecoration
public A withDecoration(boolean decoration)
-
-