Search in sources :

Example 1 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class RouteInfo method of.

public static RouteInfo of(ActionContext context) {
    H.Method m = context.req().method();
    String path = context.req().url();
    RequestHandler handler = context.handler();
    if (null == handler) {
        handler = UNKNOWN_HANDLER;
    }
    return new RouteInfo(m, path, handler);
}
Also used : RequestHandler(act.handler.RequestHandler) H(org.osgl.http.H)

Example 2 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class ActionContext method applyCorsSpec.

public ActionContext applyCorsSpec() {
    RequestHandler handler = handler();
    if (null != handler) {
        CORS.Spec spec = handler.corsSpec();
        spec.applyTo(this);
    }
    applyGlobalCorsSetting();
    return this;
}
Also used : CORS(act.security.CORS) RequestHandler(act.handler.RequestHandler)

Example 3 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class ActionContext method forward.

public void forward(String url) {
    E.illegalArgumentIfNot(url.startsWith("/"), "forward URL must starts with single '/'");
    E.illegalArgumentIf(url.startsWith("//"), "forward URL must starts with single `/`");
    E.unexpectedIfNot(H.Method.GET == req().method(), "forward only support on HTTP GET request");
    uploads.clear();
    extraParams.clear();
    bodyParams = null;
    urlPath = UrlPath.of(url);
    UndertowRequest req = $.cast(req());
    state = State.CREATED;
    req.forward(url);
    final RequestHandler requestHandler = router.getInvoker(H.Method.GET, url, this);
    app().eventBus().emit(new PreHandle(this));
    requestHandler.handle(this);
}
Also used : UndertowRequest(act.xio.undertow.UndertowRequest) RequestHandler(act.handler.RequestHandler) PreHandle(act.handler.event.PreHandle)

Example 4 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class ResourceGetter method preventFolderAccess.

private boolean preventFolderAccess(URL target, String path, ActionContext context) {
    RequestHandler folderHandler = subFolderIndexHandlers.get(path);
    if (null != folderHandler) {
        folderHandler.handle(context);
        return true;
    }
    if (isFolder(target, path)) {
        String indexPath = S.pathConcat(path, SEP, "index.html");
        URL indexTarget = ResourceGetter.class.getResource(indexPath);
        if (null != indexTarget) {
            folderHandler = exists(indexTarget, indexPath) ? new FixedResourceGetter(indexPath) : AlwaysForbidden.INSTANCE;
            subFolderIndexHandlers.putIfAbsent(path, folderHandler);
            folderHandler.handle(context);
        }
        return true;
    }
    return false;
}
Also used : FastRequestHandler(act.handler.builtin.controller.FastRequestHandler) RequestHandler(act.handler.RequestHandler) URL(java.net.URL)

Example 5 with RequestHandler

use of act.handler.RequestHandler in project actframework by actframework.

the class RouteTableRouterBuilderTest method withBuiltInHandler.

@Test
public void withBuiltInHandler() {
    addRouteMap("GET /public file:/public");
    RequestHandler h = router.getInvoker(GET, "/public/file1.txt", ctx);
    yes(h instanceof FileGetter);
    eq(new File("target/test-classes/public"), ActTestBase.fieldVal(h, "base"));
}
Also used : RequestHandler(act.handler.RequestHandler) File(java.io.File) FileGetter(act.handler.builtin.FileGetter) Test(org.junit.Test)

Aggregations

RequestHandler (act.handler.RequestHandler)16 Test (org.junit.Test)7 H (org.osgl.http.H)7 FileGetter (act.handler.builtin.FileGetter)5 File (java.io.File)4 FastRequestHandler (act.handler.builtin.controller.FastRequestHandler)2 PreHandle (act.handler.event.PreHandle)2 EventBus (act.event.EventBus)1 AlwaysNotFound (act.handler.builtin.AlwaysNotFound)1 Echo (act.handler.builtin.Echo)1 ResourceGetter (act.handler.builtin.ResourceGetter)1 PostHandle (act.handler.event.PostHandle)1 Timer (act.metric.Timer)1 CORS (act.security.CORS)1 ActErrorResult (act.view.ActErrorResult)1 UndertowRequest (act.xio.undertow.UndertowRequest)1 URL (java.net.URL)1 NotAppliedException (org.osgl.exception.NotAppliedException)1 ErrorResult (org.osgl.mvc.result.ErrorResult)1 NotFound (org.osgl.mvc.result.NotFound)1