public class Engine
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Engine.EngineListener
Receives
Engine and Api lifecycle,
per request and per error callback notifications. |
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<Api> |
apis
The
Apis being service by this Engine |
protected io.inversion.config.Config |
config |
protected java.lang.String |
configPath
Optional override for the configPath sys/env prop used by Config to locate configuration property files
|
protected java.lang.String |
configProfile
Optional override for the sys/env prop used by Config to determine which profile specific configuration property files to load
|
protected io.inversion.context.Context |
context |
protected java.lang.String |
corsAllowHeaders
Base value for the CORS "Access-Control-Allow-Headers" response header.
|
protected java.util.List<Action> |
filters |
protected Response |
lastResponse
The last
Response served by this Engine, primarily used for writing test cases. |
protected java.util.List<Engine.EngineListener> |
listeners
Listeners that will receive Engine and Api lifecycle, request, and error callbacks.
|
protected org.slf4j.Logger |
log |
| Constructor and Description |
|---|
Engine() |
Engine(Api... apis) |
Engine(java.lang.String configPath,
java.lang.String configProfile) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
autowire(io.inversion.context.Context context) |
static io.inversion.json.JSNode |
buildErrorJson(java.lang.Throwable ex) |
Response |
delete(java.lang.String url)
Convenience overloading of
#service(Request, Response) to run a REST DELETE Request on this Engine. |
Response |
delete(java.lang.String url,
io.inversion.json.JSList hrefs)
Convenience overloading of
#service(Request, Response) to run a REST DELETE Request on this Engine. |
protected static void |
exclude(io.inversion.json.JSMap node,
java.util.Set<java.lang.String> includes,
java.util.Set<java.lang.String> excludes,
java.lang.String path) |
protected static void |
exclude(Request req,
Response res) |
protected static boolean |
exclude(java.lang.String path,
java.util.Set<java.lang.String> includes,
java.util.Set<java.lang.String> excludes) |
protected static boolean |
find(java.util.Collection<java.lang.String> paths,
java.lang.String path,
boolean matchStart) |
Response |
get(java.lang.String url)
Convenience overloading of
#service(Request, Response) to run a REST GET Request on this Engine. |
Response |
get(java.lang.String url,
java.util.List queryTerms)
Convenience overloading of
#service(Request, Response) to run a REST GET Request on this Engine. |
Response |
get(java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> params)
Convenience overloading of
#service(Request, Response) to run a REST GET Request on this Engine. |
Api |
getApi(java.lang.String apiName) |
java.util.List<Api> |
getApis() |
io.inversion.config.Config |
getConfig() |
java.lang.String |
getConfigPath() |
java.lang.String |
getConfigProfile() |
io.inversion.context.Context |
getContext() |
java.util.List<Action> |
getFilters() |
Response |
getLastResponse() |
java.net.URL |
getResource(java.lang.String name) |
boolean |
isStarted() |
boolean |
matchApi(Request req) |
Response |
patch(java.lang.String url,
io.inversion.json.JSNode body)
Convenience overloading of
#service(Request, Response) to run a REST PATCH Request on this Engine. |
Response |
post(java.lang.String url,
io.inversion.json.JSNode body)
Convenience overloading of
#service(Request, Response) to run a REST POST Request on this Engine. |
Response |
put(java.lang.String url,
io.inversion.json.JSNode body)
Convenience overloading of
#service(Request, Response) to run a REST PUT Request on this Engine. |
void |
removeApi(Api api)
Removes the api, notifies EngineListeners and calls api.shutdown().
|
Chain |
service(Request req,
Response res)
The main entry point for processing a Request and generating Response content.
|
Response |
service(java.lang.String method,
java.lang.String url)
Convenience overloading of
#service(Request, Response) |
Response |
service(java.lang.String method,
java.lang.String url,
java.lang.String body)
Convenience overloading of
#service(Request, Response) |
Response |
service(java.lang.String method,
java.lang.String url,
java.lang.String body,
java.util.Map<java.lang.String,java.lang.String> params)
Convenience overloading of
#service(Request, Response) |
void |
shutdown()
Removes all Apis and notifies listeners.onShutdown
|
protected void |
shutdownApi(Api api) |
Engine |
startup()
Runs the
Wirer and calls startupApi for each Api. |
protected void |
startup0()
Convenient pre-startup hook for subclasses guaranteed to only be called once.
|
protected void |
startupApi(Api api) |
Engine |
withAllowHeaders(java.lang.String allowHeaders) |
Engine |
withApi(Api api) |
Engine |
withConfig(io.inversion.config.Config config) |
Engine |
withConfigPath(java.lang.String configPath) |
Engine |
withConfigProfile(java.lang.String configProfile) |
Engine |
withContext(io.inversion.context.Context context) |
Engine |
withEngineListener(Engine.EngineListener listener)
Registers
listener to receive Engine, Api, request and error callbacks. |
Engine |
withFilters(Action... filters) |
protected final transient org.slf4j.Logger log
protected transient java.lang.String configPath
protected transient java.lang.String configProfile
protected transient io.inversion.context.Context context
protected transient io.inversion.config.Config config
protected final transient java.util.List<Engine.EngineListener> listeners
protected transient volatile Response lastResponse
Response served by this Engine, primarily used for writing test cases.protected java.util.List<Api> apis
Apis being service by this Engineprotected final java.util.List<Action> filters
protected java.lang.String corsAllowHeaders
Values from the request "Access-Control-Request-Header" header are concatenated to this resulting in the final value of "Access-Control-Allow-Headers" sent in the response.
Unless you are really doing something specific with browser security you probably won't need to customize this list.
public Engine()
public Engine(java.lang.String configPath,
java.lang.String configProfile)
public Engine(Api... apis)
protected void startup0()
Called after starting has been set to true but before the Wirer is run or any Apis have been started.
public Engine startup()
Wirer and calls startupApi for each Api.
An Engine can only be started once.
Any calls to startup after the initial call will not have any affect.
public void shutdown()
public Response get(java.lang.String url)
#service(Request, Response) to run a REST GET Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
GET requests for a specific resource should return 200 of 404. GET requests with query string search conditions should return 200 even if the search did not yield any results.
url - the url that will be serviced by this Engineservice(Request, Response)public Response get(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params)
#service(Request, Response) to run a REST GET Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
GET requests for a specific resource should return 200 of 404. GET requests with query string search conditions should return 200 even if the search did not yield any results.
url - the url that will be serviced by this Engineparams - additional key/value pairs to add to the url query stringservice(Request, Response)public Response get(java.lang.String url, java.util.List queryTerms)
#service(Request, Response) to run a REST GET Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
GET requests for a specific resource should return 200 of 404. GET requests with query string search conditions should return 200 even if the search did not yield any results.
url - the url that will be serviced by this EnginequeryTerms - additional keys (no values) to add to the url query stringservice(Request, Response)public Response post(java.lang.String url, io.inversion.json.JSNode body)
#service(Request, Response) to run a REST POST Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
Successful POSTs that create a new resource should return a 201.
url - the url that will be serviced by this Enginebody - the JSON body to POST which will be stringified firstservice(Request, Response)public Response put(java.lang.String url, io.inversion.json.JSNode body)
#service(Request, Response) to run a REST PUT Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
Successful PUTs that update an existing resource should return a 204. If the PUT references a resource that does not exist, a 404 will be returned.
url - the url that will be serviced by this Enginebody - the JSON body to POST which will be stringified firstservice(Request, Response)public Response patch(java.lang.String url, io.inversion.json.JSNode body)
#service(Request, Response) to run a REST PATCH Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
Successful PATCHes that update an existing resource should return a 204. If the PATCH references a resource that does not exist, a 404 will be returned.
url - the url for a specific resource that should be PATCHed that will be serviced by this Enginebody - the JSON body to POST which will be stringified firstservice(Request, Response)public Response delete(java.lang.String url)
#service(Request, Response) to run a REST DELETE Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
url - the url of the resource to be DELETEDservice(Request, Response)public Response delete(java.lang.String url, io.inversion.json.JSList hrefs)
#service(Request, Response) to run a REST DELETE Request on this Engine.
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
url - the url of the resource to be DELETEDhrefs - the hrefs of the resource to deleteservice(Request, Response)public Response service(java.lang.String method, java.lang.String url)
#service(Request, Response)
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
method - the http method of the requested operationurl - the url that will be serviced by this Engineservice(Request, Response)public Response service(java.lang.String method, java.lang.String url, java.lang.String body)
#service(Request, Response)
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
method - the http method of the requested operationurl - the url that will be serviced by this Engine.body - a stringified JSON body presumably to PUT/POST/PATCHservice(Request, Response)public Response service(java.lang.String method, java.lang.String url, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> params)
#service(Request, Response)
IMPORTANT: This method does not make an external HTTP request, it runs the request on this Engine.
If you want to make an external HTTP request see ApiClient.
method - the http method of the requested operationurl - the url that will be serviced by this Engine.body - a stringified JSON body presumably to PUT/POST/PATCHparams - additional key/value pairs to add to the url query stringservice(Request, Response)public Chain service(Request req, Response res)
This method is designed to be called by integrating runtimes such as EngineServlet or by Actions that
need to make recursive calls to the Engine when performing composite operations.
The host and port component of the Request url are ignored assuming that this Engine instance is supposed to be servicing the request. The url does not have to start with "http[s]://". If it does not, urls that start with "/" or not are handled the same.
All of the following would be processed the same way:
req - the api Requestres - the api Responsepublic boolean matchApi(Request req)
public static io.inversion.json.JSNode buildErrorJson(java.lang.Throwable ex)
public boolean isStarted()
public Engine withEngineListener(Engine.EngineListener listener)
listener to receive Engine, Api, request and error callbacks.listener - the listener to addpublic java.util.List<Api> getApis()
public Api getApi(java.lang.String apiName)
protected void startupApi(Api api)
public void removeApi(Api api)
api - the api to be removedprotected void shutdownApi(Api api)
public Engine withAllowHeaders(java.lang.String allowHeaders)
public Response getLastResponse()
public java.net.URL getResource(java.lang.String name)
public java.lang.String getConfigPath()
public Engine withConfigPath(java.lang.String configPath)
public java.lang.String getConfigProfile()
public Engine withConfigProfile(java.lang.String configProfile)
public io.inversion.config.Config getConfig()
public Engine withConfig(io.inversion.config.Config config)
public io.inversion.context.Context getContext()
public Engine withContext(io.inversion.context.Context context)
public java.util.List<Action> getFilters()
protected static void exclude(io.inversion.json.JSMap node,
java.util.Set<java.lang.String> includes,
java.util.Set<java.lang.String> excludes,
java.lang.String path)
protected static boolean exclude(java.lang.String path,
java.util.Set<java.lang.String> includes,
java.util.Set<java.lang.String> excludes)
protected static boolean find(java.util.Collection<java.lang.String> paths,
java.lang.String path,
boolean matchStart)
protected void autowire(io.inversion.context.Context context)
Copyright © 2023 Rocket Partners, LLC. All rights reserved.