use of com.xebialabs.restito.semantics.Stub in project ddf by codice.
the class SecureStubServer method stubsToHandler.
@SuppressWarnings("squid:S2177")
private HttpHandler stubsToHandler() {
return new HttpHandler() {
@Override
public void service(Request request, Response response) throws Exception {
Call call = Call.fromRequest(request);
CallsHelper.logCall(call);
boolean processed = false;
ListIterator<Stub> iterator = stubs.listIterator(stubs.size());
while (iterator.hasPrevious()) {
Stub stub = iterator.previous();
if (!stub.isApplicable(call)) {
continue;
}
stub.apply(response);
processed = true;
break;
}
if (!processed) {
response.setStatus(HttpStatus.NOT_FOUND_404);
LOGGER.debug("Request {} hasn't been covered by any of {} stubs.", request.getRequestURI(), stubs.size());
}
calls.add(call);
}
};
}
Aggregations