Iterator<WhenHttpRequest> iterator = spec.iterator();
if (!iterator.hasNext()) {
return Optional.absent();
}
final WhenHttpRequest whenHttpRequest = iterator.next();
return Optional.of(new RestxHandlerMatch(
new StdRestxRequestMatch(req.getRestxPath()),
new RestxHandler() {
@Override
public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp,
RestxContext ctx) throws IOException {
resp.setStatus(HttpStatus.havingCode(whenHttpRequest.getThen().getExpectedCode()));
if (whenHttpRequest.getThen().getExpectedCode() == HttpStatus.OK.getCode()) {
resp.setContentType("application/json");
}
resp.getWriter().print(whenHttpRequest.getThen().getExpected());
}
}
));
}