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();
}
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");
}
});
}
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);
}
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);
}
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);
}
Aggregations