Search in sources :

Example 1 with FilterImpl

use of spark.FilterImpl in project spark by perwendel.

the class AfterFilters method execute.

static void execute(RouteContext context) throws Exception {
    Object content = context.body().get();
    List<RouteMatch> matchSet = context.routeMatcher().findMultiple(HttpMethod.after, context.uri(), context.acceptType());
    for (RouteMatch filterMatch : matchSet) {
        Object filterTarget = filterMatch.getTarget();
        if (filterTarget instanceof FilterImpl) {
            if (context.requestWrapper().getDelegate() == null) {
                Request request = RequestResponseFactory.create(filterMatch, context.httpRequest());
                context.requestWrapper().setDelegate(request);
            } else {
                context.requestWrapper().changeMatch(filterMatch);
            }
            context.responseWrapper().setDelegate(context.response());
            FilterImpl filter = (FilterImpl) filterTarget;
            filter.handle(context.requestWrapper(), context.responseWrapper());
            String bodyAfterFilter = context.response().body();
            if (bodyAfterFilter != null) {
                content = bodyAfterFilter;
            }
        }
    }
    context.body().set(content);
}
Also used : FilterImpl(spark.FilterImpl) Request(spark.Request) RouteMatch(spark.routematch.RouteMatch)

Example 2 with FilterImpl

use of spark.FilterImpl in project spark by perwendel.

the class BeforeFilters method execute.

static void execute(RouteContext context) throws Exception {
    Object content = context.body().get();
    List<RouteMatch> matchSet = context.routeMatcher().findMultiple(HttpMethod.before, context.uri(), context.acceptType());
    for (RouteMatch filterMatch : matchSet) {
        Object filterTarget = filterMatch.getTarget();
        if (filterTarget instanceof FilterImpl) {
            Request request = RequestResponseFactory.create(filterMatch, context.httpRequest());
            FilterImpl filter = (FilterImpl) filterTarget;
            context.requestWrapper().setDelegate(request);
            context.responseWrapper().setDelegate(context.response());
            filter.handle(context.requestWrapper(), context.responseWrapper());
            String bodyAfterFilter = context.response().body();
            if (bodyAfterFilter != null) {
                content = bodyAfterFilter;
            }
        }
    }
    context.body().set(content);
}
Also used : FilterImpl(spark.FilterImpl) Request(spark.Request) RouteMatch(spark.routematch.RouteMatch)

Example 3 with FilterImpl

use of spark.FilterImpl in project spark by perwendel.

the class AfterAfterFilters method execute.

static void execute(RouteContext context) throws Exception {
    Object content = context.body().get();
    List<RouteMatch> matchSet = context.routeMatcher().findMultiple(HttpMethod.afterafter, context.uri(), context.acceptType());
    for (RouteMatch filterMatch : matchSet) {
        Object filterTarget = filterMatch.getTarget();
        if (filterTarget instanceof FilterImpl) {
            if (context.requestWrapper().getDelegate() == null) {
                Request request = RequestResponseFactory.create(filterMatch, context.httpRequest());
                context.requestWrapper().setDelegate(request);
            } else {
                context.requestWrapper().changeMatch(filterMatch);
            }
            context.responseWrapper().setDelegate(context.response());
            FilterImpl filter = (FilterImpl) filterTarget;
            filter.handle(context.requestWrapper(), context.responseWrapper());
            String bodyAfterFilter = context.response().body();
            if (bodyAfterFilter != null) {
                content = bodyAfterFilter;
            }
        }
    }
    context.body().set(content);
}
Also used : FilterImpl(spark.FilterImpl) Request(spark.Request) RouteMatch(spark.routematch.RouteMatch)

Aggregations

FilterImpl (spark.FilterImpl)3 Request (spark.Request)3 RouteMatch (spark.routematch.RouteMatch)3