Class Engine
- All Implemented Interfaces:
Comparable<Engine>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceReceivesEngineandApilifecycle, per request and per error callback notifications.Nested classes/interfaces inherited from class io.inversion.Rule
Rule.RuleMatcher -
Field Summary
FieldsModifier and TypeFieldDescriptionTheApis being service by this Engineprotected StringOptional override for the configPath sys/env prop used by Config to locate configuration property filesprotected StringOptional override for the sys/env prop used by Config to determine which profile specific configuration property files to loadprotected StringBase value for the CORS "Access-Control-Allow-Headers" response header.protected ResponseThe lastResponseserved by this Engine, primarily used for writing test cases.protected final List<Engine.EngineListener>Listeners that will receive Engine and Api lifecycle, request, and error callbacks.Fields inherited from class io.inversion.Rule
configMap, configStr, excludeMatchers, excludeOn, includeMatchers, includeOn, log, name, order -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvenience overloading of#service(Request, Response)to run a REST DELETE Request on this Engine.Convenience overloading of#service(Request, Response)to run a REST DELETE Request on this Engine.Convenience overloading of#service(Request, Response)to run a REST GET Request on this Engine.Convenience overloading of#service(Request, Response)to run a REST GET Request on this Engine.Convenience overloading of#service(Request, Response)to run a REST GET Request on this Engine.getApis()getResource(String name) booleanConvenience overloading of#service(Request, Response)to run a REST PATCH Request on this Engine.Convenience overloading of#service(Request, Response)to run a REST POST Request on this Engine.Convenience overloading of#service(Request, Response)to run a REST PUT Request on this Engine.voidRemoves the api, notifies EngineListeners and calls api.shutdown().The main entry point for processing a Request and generating Response content.Convenience overloading of#service(Request, Response)Convenience overloading of#service(Request, Response)Convenience overloading of#service(Request, Response)voidshutdown()Removes all Apis and notifies listeners.onShutdownprotected voidshutdownApi(Api api) startup()Runs theConfiguratorand callsstartupApifor each Api.protected voidstartup0()Convenient pre-startup hook for subclasses guaranteed to only be called once.protected voidstartupApi(Api api) withAllowHeaders(String allowHeaders) withConfigPath(String configPath) withConfigProfile(String configProfile) withEngineListener(Engine.EngineListener listener) Registerslistenerto receive Engine, Api, request and error callbacks.Methods inherited from class io.inversion.Rule
checkLazyConfig, compareTo, doLazyConfig, getAllExcludePaths, getAllIncludePaths, getConfig, getConfig, getConfigKeys, getDefaultIncludeMatch, getExcludeMatchers, getIncludeMatchers, getName, getOrder, match, matches, matches, toString, withConfig, withExcludeOn, withExcludeOn, withExcludeOn, withIncludeOn, withIncludeOn, withIncludeOn, withName, withOrder
-
Field Details
-
listeners
Listeners that will receive Engine and Api lifecycle, request, and error callbacks. -
lastResponse
The lastResponseserved by this Engine, primarily used for writing test cases. -
apis
TheApis being service by this Engine -
corsAllowHeaders
Base value for the CORS "Access-Control-Allow-Headers" response header.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.
-
configPath
Optional override for the configPath sys/env prop used by Config to locate configuration property files- See Also:
-
configProfile
Optional override for the sys/env prop used by Config to determine which profile specific configuration property files to load- See Also:
-
-
Constructor Details
-
Engine
public Engine() -
Engine
-
-
Method Details
-
startup0
protected void startup0()Convenient pre-startup hook for subclasses guaranteed to only be called once.Called after
startinghas been set to true but before theConfiguratoris run or anyApis have been started. -
startup
Runs theConfiguratorand callsstartupApifor each Api.An Engine can only be started once. Any calls to
startupafter the initial call will not have any affect.- Returns:
- this Engine
-
shutdown
public void shutdown()Removes all Apis and notifies listeners.onShutdown -
get
Convenience overloading of#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
RestClient.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.
- Parameters:
url- the url that will be serviced by this Engine- Returns:
- the Response generated by handling the Request
- See Also:
-
get
Convenience overloading of#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
RestClient.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.
- Parameters:
url- the url that will be serviced by this Engineparams- additional key/value pairs to add to the url query string- Returns:
- the Response generated by handling the Request
- See Also:
-
get
Convenience overloading of#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
RestClient.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.
- Parameters:
url- the url that will be serviced by this EnginequeryTerms- additional keys (no values) to add to the url query string- Returns:
- the Response generated by handling the Request
- See Also:
-
post
Convenience overloading of#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
RestClient.Successful POSTs that create a new resource should return a 201.
- Parameters:
url- the url that will be serviced by this Enginebody- the JSON body to POST which will be stringified first- Returns:
- the Response generated by handling the Request
- See Also:
-
put
Convenience overloading of#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
RestClient.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.
- Parameters:
url- the url that will be serviced by this Enginebody- the JSON body to POST which will be stringified first- Returns:
- the Response generated by handling the Request
- See Also:
-
patch
Convenience overloading of#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
RestClient.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.
- Parameters:
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 first- Returns:
- the Response generated by handling the Request
- See Also:
-
delete
Convenience overloading of#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
RestClient.- Parameters:
url- the url of the resource to be DELETED- Returns:
- the Response generated by handling the Request with status 204 if the delete was successful or 404 if the resource was not found
- See Also:
-
delete
Convenience overloading of#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
RestClient.- Parameters:
url- the url of the resource to be DELETEDhrefs- the hrefs of the resource to delete- Returns:
- the Response generated by handling the Request with status 204 if the delete was successful or 404 if the resource was not found
- See Also:
-
service
Convenience overloading of#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
RestClient.- Parameters:
method- the http method of the requested operationurl- the url that will be serviced by this Engine- Returns:
- the Response generated by handling the Request
- See Also:
-
service
Convenience overloading of#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
RestClient.- Parameters:
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/PATCH- Returns:
- the Response generated by handling the Request
- See Also:
-
service
Convenience overloading of#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
RestClient.- Parameters:
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 string- Returns:
- the Response generated by handling the Request
- See Also:
-
service
The main entry point for processing a Request and generating Response content.This method is designed to be called by integrating runtimes such as
EngineServletor byActions 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:
- https://library.com/v1/library/books?ISBN=1234567890
- https://library.com:8080/v1/library/books?ISBN=1234567890
- https://localhost/v1/library/books?ISBN=1234567890
- /v1/library/books?ISBN=1234567890
- v1/library/books?ISBN=1234567890
- Parameters:
req- the api Requestres- the api Response- Returns:
- the Chain representing all of the actions executed in populating the Response
-
isStarted
public boolean isStarted() -
withEngineListener
Registerslistenerto receive Engine, Api, request and error callbacks.- Parameters:
listener- the listener to add- Returns:
- this
-
getApis
-
getApi
-
withApi
-
startupApi
-
removeApi
Removes the api, notifies EngineListeners and calls api.shutdown().- Parameters:
api- the api to be removed
-
shutdownApi
-
withAllowHeaders
-
getLastResponse
- Returns:
- the last response serviced by this Engine.
-
getResource
-
getConfigPath
-
withConfigPath
-
getConfigProfile
-
withConfigProfile
-