All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.sinri.keel.web.http.prehandler.PreHandlerChain Maven / Gradle / Ivy

Go to download

A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.

The newest version!
package io.github.sinri.keel.web.http.prehandler;

import io.github.sinri.keel.web.http.ApiMeta;
import io.vertx.core.Handler;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.*;

import java.util.ArrayList;
import java.util.List;

/**
 * The class provided a basic implementation.
 * You may override it to support more requirements.
 *
 * @since 3.2.13
 */
public class PreHandlerChain {
    protected final List platformHandlers = new ArrayList<>();

    protected final List securityPolicyHandlers = new ArrayList<>();
    protected final List protocolUpgradeHandlers = new ArrayList<>();
    protected final List multiTenantHandlers = new ArrayList<>();
    /**
     * Tells who the user is
     */
    protected final List authenticationHandlers = new ArrayList<>();
    protected final List inputTrustHandlers = new ArrayList<>();
    /**
     * Tells what the user is allowed to do
     */
    protected final List authorizationHandlers = new ArrayList<>();
    protected final List> userHandlers = new ArrayList<>();

    protected String uploadDirectory = BodyHandler.DEFAULT_UPLOADS_DIRECTORY;

    protected Handler failureHandler = null;

    public final void executeHandlers(Route route, ApiMeta apiMeta) {
        // === HANDLERS WEIGHT IN ORDER ===
        // PLATFORM
        route.handler(new KeelPlatformHandler());
        if (apiMeta.timeout() > 0) {
            // PlatformHandler
            route.handler(TimeoutHandler.create(apiMeta.timeout(), apiMeta.statusCodeForTimeout()));
        }
        route.handler(ResponseTimeHandler.create());
        this.platformHandlers.forEach(route::handler);

        //    SECURITY_POLICY,
        // SecurityPolicyHandler
        // CorsHandler: Cross Origin Resource Sharing
        this.securityPolicyHandlers.forEach(route::handler);

        //    PROTOCOL_UPGRADE,
        protocolUpgradeHandlers.forEach(route::handler);
        //    BODY,
        if (apiMeta.requestBodyNeeded()) {
            route.handler(BodyHandler.create(uploadDirectory));
        }
        //    MULTI_TENANT,
        multiTenantHandlers.forEach(route::handler);
        //    AUTHENTICATION,
        authenticationHandlers.forEach(route::handler);
        //    INPUT_TRUST,
        inputTrustHandlers.forEach(route::handler);
        //    AUTHORIZATION,
        authorizationHandlers.forEach(route::handler);
        //    USER
        userHandlers.forEach(route::handler);

        // failure handler
        if (failureHandler != null) {
            route.failureHandler(failureHandler);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy