Search in sources :

Example 26 with Request

use of spark.Request in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddMissingRepotype.

public void testRepoAddMissingRepotype() {
    Request mockRequest = Mockito.mock(Request.class);
    Repo mockRepo = Mockito.mock(Repo.class);
    ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, null, null);
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = false;
    when(mockRequest.queryParams("reponame")).thenReturn("test");
    when(mockRequest.queryParams("repourl")).thenReturn("test");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("repotype is a required parameter");
    assertThat(apiResponse.isSucessful()).isFalse();
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 27 with Request

use of spark.Request in project newts by OpenNMS.

the class Web method main.

public static void main(String... args) {
    staticFileLocation("/static");
    get(new VelocityRoute("/stations") {

        @Override
        public Object handle(Request request, Response response) {
            Map<String, Object> model = Maps.newHashMap();
            model.put("stationsMap", STATION_NAMES);
            return modelAndView(model, "index.wm");
        }
    });
    get(new VelocityRoute("/summer88") {

        @Override
        public Object handle(Request arg0, Response arg1) {
            Map<String, Object> model = Maps.newHashMap();
            model.put("stationIds", STATION_IDS);
            return modelAndView(model, "summer.wm");
        }
    });
    get(new VelocityRoute("/stations/:stationName") {

        @Override
        public Object handle(Request request, Response response) {
            String stationName = request.params(":stationName");
            String id = STATION_IDS.get(stationName);
            if (id == null) {
                halt(404, "No such station");
            }
            Map<String, String> model = Maps.newHashMap();
            model.put("location", STATION_NAMES.get(stationName));
            model.put("id", id);
            model.put("start", request.queryParams("start"));
            model.put("end", request.queryParams("end"));
            model.put("resolution", request.queryParams("resolution"));
            return modelAndView(model, "station.wm");
        }
    });
}
Also used : Response(spark.Response) Request(spark.Request) VelocityRoute(spark.template.velocity.VelocityRoute) Map(java.util.Map)

Example 28 with Request

use of spark.Request 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 29 with Request

use of spark.Request 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 30 with Request

use of spark.Request 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

Request (spark.Request)57 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)34 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)32 Repo (com.searchcode.app.dao.Repo)28 ApiResponse (com.searchcode.app.dto.api.ApiResponse)27 RepoResult (com.searchcode.app.model.RepoResult)10 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)8 Response (spark.Response)8 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)7 HashSet (java.util.HashSet)6 Map (java.util.Map)5 ModelAndView (spark.ModelAndView)5 RouteMatch (spark.routematch.RouteMatch)4 ValidatorResult (com.searchcode.app.model.ValidatorResult)3 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)3 FilterImpl (spark.FilterImpl)3 HaltException (spark.HaltException)3 Values (com.searchcode.app.config.Values)2 Data (com.searchcode.app.dao.Data)2 CodeResult (com.searchcode.app.dto.CodeResult)2