tock / ai.tock.shared.vertx / WebVerticle

WebVerticle

abstract class WebVerticle : AbstractVerticle (source)

Base class for web Tock io.vertx.core.Verticles. Provides utility methods.

Constructors

<init>

Base class for web Tock io.vertx.core.Verticles. Provides utility methods.

WebVerticle()

Properties

authenticatePath

open val authenticatePath: String

basePath

open val basePath: String

defaultCorsOrigin

Default cors origin (if tock_web_use_default_cors_handler property is set to true).

open val defaultCorsOrigin: String

defaultCorsWithCredentials

By default, allow credentials for cors origin (if tock_web_use_default_cors_handler property is set to true).

open val defaultCorsWithCredentials: Boolean

defaultPort

The default port of the verticle

open val defaultPort: Int

healthcheckPath

If not null, add a healthcheck for this verticle.

open val healthcheckPath: String?

livenesscheckPath

If not null, add a liveness for this verticle.

open val livenesscheckPath: String?

logger

open val logger: KLogger

logoutPath

open val logoutPath: String

organization

val RoutingContext.organization: String

readinesscheckPath

If not null, add a readiness for this verticle.

open val readinesscheckPath: String?

rootPath

open val rootPath: String

router

val router: Router

server

val server: HttpServer

user

val RoutingContext.user: TockUser?

userLogin

val RoutingContext.userLogin: String

Functions

addAuth

fun addAuth(authProvider: TockAuthProvider = defaultAuthProvider(), pathsToProtect: Set<String> = protectedPaths().map { "$it/*" }.toSet()): Unit

addDevCorsHandler

open fun addDevCorsHandler(): Unit

authProvider

By default there is no auth provider - ie nothing is protected.

open fun authProvider(): TockAuthProvider?

blocking

fun blocking(method: HttpMethod, path: String, role: TockUserRole? = defaultRole(), basePath: String = rootPath, handler: (RoutingContext) -> Unit): Unit

blockingDelete

fun blockingDelete(path: String, role: TockUserRole? = defaultRole(), logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext) -> Unit): Unit

blockingGet

fun blockingGet(path: String, role: TockUserRole? = defaultRole(), basePath: String = rootPath, handler: (RoutingContext) -> String): Unit

blockingJsonDelete

fun blockingJsonDelete(path: String, role: TockUserRole? = defaultRole(), logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext) -> Boolean): Unit

blockingJsonGet

fun <O> blockingJsonGet(path: String, role: TockUserRole? = defaultRole(), handler: (RoutingContext) -> O): Unit

blockingJsonPost

fun <I : Any, O> blockingJsonPost(path: String, role: TockUserRole? = defaultRole(), logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext, I) -> O): Unit

blockingJsonPut

fun <I : Any, O> blockingJsonPut(path: String, role: TockUserRole? = defaultRole(), logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext, I) -> O): Unit

blockingPost

fun blockingPost(path: String, role: TockUserRole? = defaultRole(), logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext) -> Unit): Unit

blockingUploadBinaryPost

fun <O> blockingUploadBinaryPost(path: String, role: TockUserRole? = defaultRole(), handler: (RoutingContext, Pair<String, ByteArray>) -> O): Unit

blockingUploadJsonPost

fun <F : Any, O> blockingUploadJsonPost(path: String, role: TockUserRole? = defaultRole(), logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext, F) -> O): Unit

blockingUploadPost

fun <O> blockingUploadPost(path: String, role: TockUserRole? = defaultRole(), logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext, String) -> O): Unit

blockingWithBodyJson

fun <I : Any, O> blockingWithBodyJson(method: HttpMethod, path: String, role: TockUserRole?, logger: RequestLogger = defaultRequestLogger, handler: (RoutingContext, I) -> O): Unit

bodyHandler

fun bodyHandler(): BodyHandler

configure

abstract fun configure(): Unit

corsHandler

fun corsHandler(origin: String = "*", allowCredentials: Boolean = false, allowedMethods: Set<HttpMethod> = EnumSet.of(GET, POST, PUT, DELETE), allowedHeaders: Set<String> = listOfNotNull( "X-Requested-With", "Access-Control-Allow-Origin", if (allowCredentials) "Authorization" else null, "Content-Type" ).toSet()): CorsHandler

defaultAuthProvider

The auth provider provided by default.

open fun defaultAuthProvider(): TockAuthProvider

defaultErrorHandler

The error handler for match failures. See https://vertx.io/docs/vertx-web/java/#_route_match_failures

open fun defaultErrorHandler(statusCode: Int): Handler<RoutingContext>

defaultHealthcheck

Provide basic health information: mainly through HTTP status code

open fun defaultHealthcheck(): (RoutingContext) -> Unit

defaultRole

The default role of a service.

open fun defaultRole(): TockUserRole?

detailedHealthcheck

Provide enhanced information: HTTP response has JSON body with health status of resources

open fun detailedHealthcheck(): (RoutingContext) -> Unit

endJson

fun RoutingContext.endJson(success: Boolean): Unit
fun RoutingContext.endJson(result: Any?): Unit
fun HttpServerResponse.endJson(result: Any?): Unit

executeBlocking

Execute blocking code using Vertx.executeBlocking.

fun RoutingContext.executeBlocking(handler: (RoutingContext) -> Unit): Unit

firstQueryParam

fun RoutingContext.firstQueryParam(name: String): String?

healthcheck

open fun healthcheck(): (RoutingContext) -> Unit

isAuthorized

fun RoutingContext.isAuthorized(role: TockUserRole, resultHandler: (AsyncResult<Boolean>) -> Unit): Any

jsonPost

fun <I : Any, O> jsonPost(path: String, role: TockUserRole? = defaultRole(), handler: (RoutingContext, I, Handler<O>) -> Unit): Unit

livenesscheck

Provide basic liveness information: indicates whether the verticle is running

open fun livenesscheck(): (RoutingContext) -> Unit

path

fun RoutingContext.path(name: String): String

pathId

fun <T> RoutingContext.pathId(name: String): Id<T>

pathToLocale

fun RoutingContext.pathToLocale(name: String): Locale

protectedPaths

open fun protectedPaths(): Set<String>

queryId

fun <T> RoutingContext.queryId(name: String): Id<T>?

readBytes

fun readBytes(upload: FileUpload): ByteArray

readinesscheck

Provide basic readiness information: indicates whether the container is ready to respond to requests

open fun readinesscheck(): (RoutingContext) -> Unit

readJson

fun <T : Any> RoutingContext.readJson(): T
fun <T : Any> readJson(upload: FileUpload): T

readString

fun readString(upload: FileUpload): String

register

fun register(method: HttpMethod, path: String, role: TockUserRole? = defaultRole(), basePath: String = rootPath, handler: (RoutingContext) -> Unit): Unit

start

open fun start(promise: Promise<Void>): Unit

startServer

open fun startServer(promise: Promise<Void>): Unit
open fun startServer(promise: Promise<Void>, port: Int): Unit

stop

open fun stop(stopFuture: Future<Void>?): Unit

success

fun RoutingContext.success(): Unit

verticleBooleanProperty

fun verticleBooleanProperty(propertyName: String, defaultValue: Boolean): Boolean

verticleIntProperty

fun verticleIntProperty(propertyName: String, defaultValue: Int): Int

verticleLongProperty

fun verticleLongProperty(propertyName: String, defaultValue: Long): Long

verticleProperty

fun verticleProperty(propertyName: String, defaultValue: String): String

withBodyJson

fun <I : Any, O> withBodyJson(method: HttpMethod, path: String, role: TockUserRole?, handler: (RoutingContext, I, Handler<O>) -> Unit): Unit

Companion Object Properties

defaultRequestLogger

Default request logger does nothing.

val defaultRequestLogger: RequestLogger

Companion Object Functions

badRequest

fun badRequest(message: String): Nothing

notFound

fun notFound(): Nothing

unauthorized

fun unauthorized(): Nothing