List<RouteMatch> matchSet = routeMatcher.findTargetsForRequestedRoute(HttpMethod.before, uri, acceptType);
for (RouteMatch filterMatch : matchSet) {
Object filterTarget = filterMatch.getTarget();
if (filterTarget instanceof FilterImpl) {
Request request = RequestResponseFactory.create(filterMatch, httpRequest);
Response response = RequestResponseFactory.create(httpResponse);
FilterImpl filter = (FilterImpl) filterTarget;
req.setDelegate(request);
res.setDelegate(response);
filter.handle(req, res);
String bodyAfterFilter = Access.getBody(response);
if (bodyAfterFilter != null) {
bodyContent = bodyAfterFilter;
}
}
}
// BEFORE filters, END
HttpMethod httpMethod = HttpMethod.valueOf(httpMethodStr);
RouteMatch match = null;
match = routeMatcher.findTargetForRequestedRoute(httpMethod, uri, acceptType);
Object target = null;
if (match != null) {
target = match.getTarget();
} else if (httpMethod == HttpMethod.head && bodyContent == null) {
// See if get is mapped to provide default head mapping
bodyContent =
routeMatcher.findTargetForRequestedRoute(HttpMethod.get, uri, acceptType) != null ? "" : null;
}
if (target != null) {
try {
String result = null;
if (target instanceof RouteImpl) {
RouteImpl route = ((RouteImpl) target);
Request request = RequestResponseFactory.create(match, httpRequest);
Response response = RequestResponseFactory.create(httpResponse);
req.setDelegate(request);
res.setDelegate(response);
Object element = route.handle(req, res);
result = route.render(element);
// result = element.toString(); // TODO: Remove later when render fixed
}
if (result != null) {
bodyContent = result;
}
} catch (HaltException hEx) { // NOSONAR
throw hEx; // NOSONAR
}
}
// AFTER filters
matchSet = routeMatcher.findTargetsForRequestedRoute(HttpMethod.after, uri, acceptType);
for (RouteMatch filterMatch : matchSet) {
Object filterTarget = filterMatch.getTarget();
if (filterTarget instanceof FilterImpl) {
Request request = RequestResponseFactory.create(filterMatch, httpRequest);
Response response = RequestResponseFactory.create(httpResponse);
req.setDelegate(request);
res.setDelegate(response);