Class PathPrefixServiceHandler
- java.lang.Object
-
- com.networknt.router.middleware.PathPrefixServiceHandler
-
- All Implemented Interfaces:
LightHttpHandler,MiddlewareHandler,io.undertow.server.HttpHandler
public class PathPrefixServiceHandler extends Object implements MiddlewareHandler
When using router, each request must have serviceId in the header in order to allow router to do the service discovery before invoke downstream service. The reason we have to do that is due to the unpredictable path between services. If you are sure that all the downstream services can be identified by a unique path prefix, then you can use this Path to ServiceId mapper handler to uniquely identify the serviceId and put it into the header. In this case, the client can invoke the service just the same way it is invoking the service directly.Please note that you cannot invoke /health or /server/info endpoints as these are the common endpoints injected by the framework and all services will have them on the same path. The router cannot figure out which service you want to invoke so an error message will be returned
Unlike
PathServiceHandler, this handler does not require OpenAPIHandler or SwaggerHandler but is also unable to do any validation beyond the path prefix. Previously, this handler will skip the logic when server_url is in the header. However, since we have updated the TokenHandler to support multiple downstream hosts with different OAuth 2.0 servers, we need to put the service_id into the header regardless if the server_url is in the header. Also, this handler work on the best effort basis, so it only works if the prefix is in the config. This is the simplest mapping with the prefix and all APIs behind the http-sidecar or light-router should have a unique prefix. All the services of light-router is following this convention.- Author:
- Logi Ragnarsson, Steve Hu
-
-
Field Summary
Fields Modifier and Type Field Description protected static PathPrefixServiceConfigconfigprotected io.undertow.server.HttpHandlernext-
Fields inherited from interface com.networknt.handler.LightHttpHandler
AUDIT_CONFIG_NAME, AUDIT_ON_ERROR, AUDIT_STACK_TRACE, auditConfig, auditOnError, auditStackTrace, CONFIG_NAME, ERROR_NOT_DEFINED
-
-
Constructor Summary
Constructors Constructor Description PathPrefixServiceHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.undertow.server.HttpHandlergetNext()voidhandleRequest(io.undertow.server.HttpServerExchange exchange)booleanisEnabled()voidregister()voidreload()MiddlewareHandlersetNext(io.undertow.server.HttpHandler next)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.networknt.handler.LightHttpHandler
setExchangeStatus, setExchangeStatus, setExchangeStatus
-
-
-
-
Field Detail
-
next
protected volatile io.undertow.server.HttpHandler next
-
config
protected static PathPrefixServiceConfig config
-
-
Method Detail
-
handleRequest
public void handleRequest(io.undertow.server.HttpServerExchange exchange) throws Exception- Specified by:
handleRequestin interfaceio.undertow.server.HttpHandler- Throws:
Exception
-
getNext
public io.undertow.server.HttpHandler getNext()
- Specified by:
getNextin interfaceMiddlewareHandler
-
setNext
public MiddlewareHandler setNext(io.undertow.server.HttpHandler next)
- Specified by:
setNextin interfaceMiddlewareHandler
-
isEnabled
public boolean isEnabled()
- Specified by:
isEnabledin interfaceMiddlewareHandler
-
register
public void register()
- Specified by:
registerin interfaceMiddlewareHandler
-
reload
public void reload()
- Specified by:
reloadin interfaceMiddlewareHandler
-
-