Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package restx.specs.server;
 
 import restx.*;
User: xavierhanin Date: 4/10/13 Time: 12:04 PM
@Component(priority = 1000)
public class SpecsServerRoute implements RestxRoute {
    private final RestxSpecRepository specRepository;
    public SpecsServerRoute(RestxSpecRepository specRepository) {
        this. = specRepository;
    }
    @Override
    public Optional<RestxHandlerMatchmatch(RestxRequest req) {
        Iterator<WhenHttpRequestiterator = 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 matchRestxRequest reqRestxResponse resp,
                                       RestxContext ctxthrows IOException {
                        resp.setStatus(HttpStatus.havingCode(whenHttpRequest.getThen().getExpectedCode()));
                        if (whenHttpRequest.getThen().getExpectedCode() == ..getCode()) {
                            resp.setContentType("application/json");
                        }
                        resp.getWriter().print(whenHttpRequest.getThen().getExpected());
                    }
                }
        ));
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("-- routes defined by specs:\n");
        for (String spec : .findAll()){
            Optional<RestxSpecs = .findSpecById(spec);
            for (When when : s.get().getWhens()) {
                if (when instanceof WhenHttpRequest) {
                    WhenHttpRequest httpRequest = (WhenHttpRequestwhen;
                    sb.append(httpRequest.getMethod()).append(" ").append(httpRequest.getPath())
                            .append(" (").append(spec).append(")\n");
                }
            }
        }
        sb.append("--");
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X