public class ApiGateway extends services.moleculer.service.Service implements RequestProcessor
| Modifier and Type | Field and Description |
|---|---|
protected CallProcessor |
afterCall
Custom message post-processor.
|
protected CallProcessor |
beforeCall
Custom message pre-processor.
|
protected int |
cachedRoutes
Maximum number of cached routes.
|
protected java.util.Set<java.lang.String> |
checkedNames
Checked services with @HttpAlias annotations.
|
protected boolean |
debug
Print more debug messages.
|
protected java.util.LinkedList<Mapping> |
dynamicMappings
Dynamic mappings.
|
protected java.util.concurrent.ExecutorService |
executor
Custom Action Executor (null = use the shared ExecutorService of the
MessageBroker).
|
protected java.util.Set<HttpMiddleware> |
globalMiddlewares
Global middlewares.
|
protected HttpMiddleware |
lastMiddleware
Last middleware (custom error pages, HTTP-redirector, etc.)
|
protected Route |
lastRoute
Last route (for the last middleware)
|
protected java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
readLock |
protected Route[] |
routes |
protected java.util.LinkedHashMap<java.lang.String,Mapping> |
staticMappings
Static mappings.
|
protected AbstractTemplateEngine |
templateEngine
HTML template engine.
|
protected WebSocketFilter |
webSocketFilter
WebSocket filter (access control)
|
services.moleculer.eventbus.Listener |
webSocketListener
Send WebSocket via broadcasted Moleculer Event.
|
protected WebSocketRegistry |
webSocketRegistry
WebSocket registry (Netty or J2EE)
|
protected java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
writeLock |
| Constructor and Description |
|---|
ApiGateway() |
ApiGateway(java.lang.String... whiteListEntries) |
| Modifier and Type | Method and Description |
|---|---|
Route |
addRoute() |
Route |
addRoute(Route route)
Adds a route to the list of routes.
|
Route |
addRoute(java.lang.String path,
java.lang.String serviceList,
HttpMiddleware... middlewares)
Define a route for a list of Service (eg. in the "service" the service's
"action" action will available on
"http://host:port/path/service/action").
|
protected void |
clearMappings() |
CallProcessor |
getAfterCall() |
CallProcessor |
getBeforeCall() |
int |
getCachedRoutes() |
java.util.concurrent.ExecutorService |
getExecutor() |
HttpMiddleware |
getLastMiddleware() |
RequestProcessor |
getParent()
Returns the next RequestProcessor in the invocation chain.
|
Route[] |
getRoutes() |
AbstractTemplateEngine |
getTemplateEngine() |
WebSocketFilter |
getWebSocketFilter() |
WebSocketRegistry |
getWebSocketRegistry() |
boolean |
isDebug() |
protected void |
logAlias(java.lang.StringBuilder msg,
Route route,
Alias alias) |
protected void |
logRoute(Route route) |
void |
service(WebRequest req,
WebResponse rsp)
Handles request of the HTTP client.
|
void |
setAfterCall(CallProcessor afterCall) |
void |
setBeforeCall(CallProcessor beforeCall) |
void |
setCachedRoutes(int cacheSize) |
void |
setDebug(boolean debug) |
void |
setExecutor(java.util.concurrent.ExecutorService executor) |
void |
setLastMiddleware(HttpMiddleware lastMiddleware) |
void |
setRoutes(Route[] routes) |
void |
setTemplateEngine(AbstractTemplateEngine templateEngine) |
void |
setWebSocketFilter(WebSocketFilter webSocketFilter) |
void |
setWebSocketRegistry(WebSocketRegistry webSocketRegistry) |
void |
started(services.moleculer.ServiceBroker broker)
Initializes gateway instance.
|
void |
stopped()
Closes gateway.
|
void |
use(java.util.Collection<HttpMiddleware> middlewares) |
void |
use(HttpMiddleware... middlewares) |
protected Route[] routes
protected Route lastRoute
protected HttpMiddleware lastMiddleware
protected boolean debug
protected int cachedRoutes
protected java.util.LinkedHashMap<java.lang.String,Mapping> staticMappings
protected final java.util.LinkedList<Mapping> dynamicMappings
protected java.util.Set<HttpMiddleware> globalMiddlewares
protected java.util.Set<java.lang.String> checkedNames
protected AbstractTemplateEngine templateEngine
protected WebSocketRegistry webSocketRegistry
protected WebSocketFilter webSocketFilter
protected CallProcessor beforeCall
protected CallProcessor afterCall
protected java.util.concurrent.ExecutorService executor
protected final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock readLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock writeLock
public services.moleculer.eventbus.Listener webSocketListener
public ApiGateway()
public ApiGateway(java.lang.String... whiteListEntries)
public void started(services.moleculer.ServiceBroker broker)
throws java.lang.Exception
started in interface services.moleculer.service.MoleculerLifecyclestarted in class services.moleculer.service.MoleculerComponentbroker - parent ServiceBrokerjava.lang.Exceptionprotected void logRoute(Route route)
public void stopped()
stopped in interface services.moleculer.service.MoleculerLifecyclestopped in class services.moleculer.service.MoleculerComponentprotected void clearMappings()
public void service(WebRequest req, WebResponse rsp) throws java.lang.Exception
service in interface RequestProcessorreq - WebRequest object that contains the request the client made of
the ApiGatewayrsp - WebResponse object that contains the response the ApiGateway
returns to the clientjava.lang.Exception - if an input or output error occurs while the ApiGateway is
handling the HTTP requestpublic void use(HttpMiddleware... middlewares)
public void use(java.util.Collection<HttpMiddleware> middlewares)
public Route addRoute()
public Route addRoute(java.lang.String path, java.lang.String serviceList, HttpMiddleware... middlewares)
path - root path to services (can be null or empty)serviceList - list of services and/or actions (eg.
"service1, service2.action, service3, service4.action")middlewares - optional middlewares (eg. CorsHeaders)public Route addRoute(Route route)
route - the new routepublic Route[] getRoutes()
public void setRoutes(Route[] routes)
public int getCachedRoutes()
public void setCachedRoutes(int cacheSize)
public HttpMiddleware getLastMiddleware()
public void setLastMiddleware(HttpMiddleware lastMiddleware)
public boolean isDebug()
public void setDebug(boolean debug)
public AbstractTemplateEngine getTemplateEngine()
public void setTemplateEngine(AbstractTemplateEngine templateEngine)
public CallProcessor getBeforeCall()
public void setBeforeCall(CallProcessor beforeCall)
public CallProcessor getAfterCall()
public void setAfterCall(CallProcessor afterCall)
public WebSocketRegistry getWebSocketRegistry()
public void setWebSocketRegistry(WebSocketRegistry webSocketRegistry)
public WebSocketFilter getWebSocketFilter()
public void setWebSocketFilter(WebSocketFilter webSocketFilter)
public java.util.concurrent.ExecutorService getExecutor()
public void setExecutor(java.util.concurrent.ExecutorService executor)
public RequestProcessor getParent()
RequestProcessorgetParent in interface RequestProcessor