T
- public abstract class AbstractAPIHandler<T>
extends io.vertx.ext.web.handler.impl.BodyHandlerImpl
The AbstractAPIHandler implements convenience methods to minimize the code required in an actual handler. A handler only needs to provide
Modifier and Type | Field and Description |
---|---|
protected KeepApiInfo |
apiInfo |
protected io.vertx.core.json.JsonObject |
config |
protected java.lang.String |
eventBusId |
protected static org.slf4j.Logger |
logger |
protected java.lang.String |
operationId |
protected io.vertx.core.Vertx |
vertx |
Constructor and Description |
---|
AbstractAPIHandler() |
Modifier and Type | Method and Description |
---|---|
protected void |
endWithError(io.vertx.ext.web.RoutingContext ctx,
ErrorMessage errorMessage)
Ends a request by sending an error code
|
protected void |
endWithError(io.vertx.ext.web.RoutingContext ctx,
ErrorMessage errorMessage,
boolean closeArray)
Ends a request by sending an error code
|
protected void |
endWithError(io.vertx.ext.web.RoutingContext ctx,
java.lang.Exception exception) |
protected void |
endWithError(io.vertx.ext.web.RoutingContext ctx,
java.lang.Exception exception,
boolean closeArray) |
EventBusRequestObservable |
getObservable(java.lang.String address,
io.vertx.core.MultiMap headers,
io.vertx.core.json.JsonObject incoming) |
protected java.util.EnumSet<RequestOptionFlags> |
getReqOptions()
Options to check when looking at header and parameters
|
void |
handle(io.vertx.ext.web.RoutingContext ctx) |
protected void |
handleErrorWhileListening(io.vertx.ext.web.RoutingContext ctx,
java.lang.Throwable error,
boolean happenedMidFlight)
Standard Error when things go wrong.
|
protected static void |
incrementRequestCounter(java.lang.String counterName,
java.lang.String apiInfoName) |
void |
initHandler(io.vertx.core.Vertx newVertx,
io.vertx.core.json.JsonObject newConfig,
KeepApiInfo newApiInfo) |
protected io.vertx.core.json.JsonArray |
injectIntoObservableValue(io.vertx.core.json.JsonArray value)
Allows us to modify the response value based on the handler.
|
protected void |
listenForBufferResponse(EventBusRequestObservable<io.vertx.core.buffer.Buffer> incomingObservable,
io.vertx.ext.web.RoutingContext ctx)
Default implementation of a Buffer listener -> usable for any type of binary data
|
protected void |
listenForJsonResponse(EventBusRequestObservable<io.vertx.core.json.JsonArray> incomingObservable,
io.vertx.ext.web.RoutingContext ctx)
Default implementation of a JSON listener allows multiple packages delivered
|
protected abstract void |
listenForResponse(EventBusRequestObservable<T> incomingObservable,
io.vertx.ext.web.RoutingContext ctx) |
protected abstract io.vertx.core.Future<io.vertx.core.json.JsonObject> |
prepareRequestBody(io.vertx.ext.web.RoutingContext ctx,
io.vertx.core.MultiMap header) |
protected io.vertx.core.Future<io.vertx.core.json.JsonObject> |
requestBodyFromAllParams(io.vertx.ext.web.RoutingContext ctx,
io.vertx.core.MultiMap headers)
Copies all parameters into the JsonObject for processing
|
void |
setObservable(EventBusRequestObservable<T> observable) |
setBodyLimit, setDeleteUploadedFilesOnEnd, setHandleFileUploads, setMergeFormAttributes, setPreallocateBodyBuffer, setUploadsDirectory
protected static final org.slf4j.Logger logger
protected io.vertx.core.Vertx vertx
protected io.vertx.core.json.JsonObject config
protected java.lang.String operationId
protected java.lang.String eventBusId
protected KeepApiInfo apiInfo
public EventBusRequestObservable getObservable(java.lang.String address, io.vertx.core.MultiMap headers, io.vertx.core.json.JsonObject incoming)
address
- headers
- incoming
- public void handle(io.vertx.ext.web.RoutingContext ctx)
handle
in interface io.vertx.core.Handler<io.vertx.ext.web.RoutingContext>
handle
in class io.vertx.ext.web.handler.impl.BodyHandlerImpl
public void initHandler(@Nonnull io.vertx.core.Vertx newVertx, @Nonnull io.vertx.core.json.JsonObject newConfig, @Nonnull KeepApiInfo newApiInfo) throws KeepExceptionMissingParameters
newVertx
- newConfig
- newApiInfo
- KeepExceptionMissingParameters
public void setObservable(EventBusRequestObservable<T> observable)
observable
- the observable to setprotected void endWithError(io.vertx.ext.web.RoutingContext ctx, ErrorMessage errorMessage)
Ends a request by sending an error code
ctx
- ContexterrorMessage
- Statuscode 50x, 40xprotected void endWithError(io.vertx.ext.web.RoutingContext ctx, ErrorMessage errorMessage, boolean closeArray)
Ends a request by sending an error code
ctx
- ContexterrorMessage
- closeArray
- protected void endWithError(io.vertx.ext.web.RoutingContext ctx, java.lang.Exception exception)
protected void endWithError(io.vertx.ext.web.RoutingContext ctx, java.lang.Exception exception, boolean closeArray)
protected java.util.EnumSet<RequestOptionFlags> getReqOptions()
Options to check when looking at header and parameters
protected void handleErrorWhileListening(io.vertx.ext.web.RoutingContext ctx, java.lang.Throwable error, boolean happenedMidFlight)
Standard Error when things go wrong. If a KeepException is thrown, We get the HTTP error code type, to forward Error classes 4xx, 5xx
ctx
- error
- happenedMidFlight
- protected static void incrementRequestCounter(java.lang.String counterName, java.lang.String apiInfoName)
protected io.vertx.core.json.JsonArray injectIntoObservableValue(io.vertx.core.json.JsonArray value)
Allows us to modify the response value based on the handler. This enables generating content in the handler, not passing it over the event bus, but including it in the response.
value
- protected void listenForBufferResponse(EventBusRequestObservable<io.vertx.core.buffer.Buffer> incomingObservable, io.vertx.ext.web.RoutingContext ctx)
Default implementation of a Buffer listener -> usable for any type of binary data
incomingObservable
- The observable that comes with JsonObjectctx
- Request contextprotected void listenForJsonResponse(EventBusRequestObservable<io.vertx.core.json.JsonArray> incomingObservable, io.vertx.ext.web.RoutingContext ctx)
Default implementation of a JSON listener allows multiple packages delivered
incomingObservable
- The observable that comes with JsonObjectctx
- Request contextprotected abstract void listenForResponse(EventBusRequestObservable<T> incomingObservable, io.vertx.ext.web.RoutingContext ctx)
incomingObservable
- The Observable runningprotected abstract io.vertx.core.Future<io.vertx.core.json.JsonObject> prepareRequestBody(io.vertx.ext.web.RoutingContext ctx, io.vertx.core.MultiMap header)
ctx
- header
- The header for the EventBusprotected io.vertx.core.Future<io.vertx.core.json.JsonObject> requestBodyFromAllParams(io.vertx.ext.web.RoutingContext ctx, io.vertx.core.MultiMap headers)
Copies all parameters into the JsonObject for processing
ctx
- Request contextheaders
-