Ejemplo n.º 1
0
 @Override
 public void handle(RestxRouteMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx)
     throws IOException {
   String relativePath = req.getRestxPath().substring(baseRestPath.length());
   relativePath = Optional.fromNullable(aliases.get(relativePath)).or(relativePath);
   try {
     URL resource =
         MoreResources.getResource(
             baseResourcePath + relativePath, RestxContext.Modes.DEV.equals(ctx.getMode()));
     resp.setStatus(HttpStatus.OK.getCode());
     resp.setContentType(
         HTTP.getContentTypeFromExtension(relativePath).or("application/octet-stream"));
     ByteStreams.copy(Resources.newInputStreamSupplier(resource), resp.getOutputStream());
   } catch (IllegalArgumentException e) {
     notFound(resp, relativePath);
   }
 }
Ejemplo n.º 2
0
 protected Map<String, RestxSpec> buildSpecsMap(boolean searchInSources) {
   Map<String, RestxSpec> specsMap = Maps.newLinkedHashMap();
   Map<String, URL> specs =
       MoreResources.findResources("", Pattern.compile(".*\\.spec\\.yaml"), searchInSources);
   for (final Map.Entry<String, URL> spec : specs.entrySet()) {
     try {
       specsMap.put(
           spec.getKey(),
           specLoader.load(
               spec.getKey(),
               new CharSource() {
                 @Override
                 public Reader openStream() throws IOException {
                   return new InputStreamReader(spec.getValue().openStream(), Charsets.UTF_8);
                 }
               }));
     } catch (Exception e) {
       logger.warn("exception while loading restx spec " + spec + ": " + e, e);
     }
   }
   return specsMap;
 }