private static ResourcesRoute getMonitorUIRoute() { return new ResourcesRoute("MonitorUIRoute", "/@/ui/monitor", MonitorRouter.class.getPackage().getName(), ImmutableMap.of("", "index.html")); } }
protected void serveCacheableResource(RestxResponse resp, URL resource, String relativePath) throws IOException { String contentType = HTTP.getContentTypeFromExtension(relativePath).or("application/octet-stream"); ImmutableMap.Builder<String, String> headers = ImmutableMap.builder(); Optional<CachedResourcePolicy> cachedResourcePolicy = cachePolicyMatching(contentType, relativePath); if(cachedResourcePolicy.isPresent()) { headers.put("Cache-Control", cachedResourcePolicy.get().getCacheValue()); } serveResource(resp, resource, contentType, headers.build()); }
public ResourcesRoute(String name, String baseRestPath, String baseResourcePath, ImmutableMap<String, String> aliases, List<CachedResourcePolicy> cachedResourcePolicies) { this.name = checkNotNull(name); this.baseRestPath = ("/" + checkNotNull(baseRestPath) + "/").replaceAll("/+", "/"); this.baseResourcePath = this.ensureBaseResourcePathValid(baseResourcePath); this.aliases = checkNotNull(aliases); this.cachedResourcePolicies = ImmutableList.copyOf(cachedResourcePolicies); }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { String relativePath = this.requestRelativePath(req); relativePath = Optional.fromNullable(aliases.get(relativePath)).or(relativePath); try { URL resource = MoreResources.getResource( baseResourcePath + relativePath, RestxContext.Modes.DEV.equals(ctx.getMode()) || RestxContext.Modes.TEST.equals(ctx.getMode()) || RestxContext.Modes.INFINIREST.equals(ctx.getMode()) ); serveCacheableResource(resp, resource, relativePath); } catch (IllegalArgumentException e) { notFound(resp, relativePath); } }
@Override public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException { String relativePath = this.requestRelativePath(req); relativePath = Optional.fromNullable(aliases.get(relativePath)).or(relativePath); try { URL resource = MoreResources.getResource( baseResourcePath + relativePath, RestxContext.Modes.DEV.equals(ctx.getMode()) || RestxContext.Modes.TEST.equals(ctx.getMode()) || RestxContext.Modes.INFINIREST.equals(ctx.getMode()) ); serveCacheableResource(resp, resource, relativePath); } catch (IllegalArgumentException e) { notFound(resp, relativePath); } }
private static ResourcesRoute getMonitorUIRoute() { return new ResourcesRoute("MonitorUIRoute", "/@/ui/monitor", MonitorRouter.class.getPackage().getName(), ImmutableMap.of("", "index.html")); } }
protected void serveCacheableResource(RestxResponse resp, URL resource, String relativePath) throws IOException { String contentType = HTTP.getContentTypeFromExtension(relativePath).or("application/octet-stream"); ImmutableMap.Builder<String, String> headers = ImmutableMap.builder(); Optional<CachedResourcePolicy> cachedResourcePolicy = cachePolicyMatching(contentType, relativePath); if(cachedResourcePolicy.isPresent()) { headers.put("Cache-Control", cachedResourcePolicy.get().getCacheValue()); } serveResource(resp, resource, contentType, headers.build()); }
public ResourcesRoute(String name, String baseRestPath, String baseResourcePath, ImmutableMap<String, String> aliases, List<CachedResourcePolicy> cachedResourcePolicies) { this.name = checkNotNull(name); this.baseRestPath = ("/" + checkNotNull(baseRestPath) + "/").replaceAll("/+", "/"); this.baseResourcePath = this.ensureBaseResourcePathValid(baseResourcePath); this.aliases = checkNotNull(aliases); this.cachedResourcePolicies = ImmutableList.copyOf(cachedResourcePolicies); }
@Provides @Named("LogUIRoute") public ResourcesRoute getLogResourcesRoute() { return new ResourcesRoute("LogUIRoute", "/@/ui/log", "restx/log", ImmutableMap.of("", "index.html")); } }
@Provides @Named("StatsUIRoute") public ResourcesRoute getStatsResourcesRoute() { return new ResourcesRoute("StatsUIRoute", "/@/ui/stats", "restx/stats/ui", ImmutableMap.of("", "index.html")); } }
@Provides public ResourcesRoute sourceUI() { return new ResourcesRoute("SourcesUIRoute", "/@/ui/sources", "restx/sources", ImmutableMap.of("", "index.html")); }
@Provides public ResourcesRoute sourceUI() { return new ResourcesRoute("SourcesUIRoute", "/@/ui/sources", "restx/sources", ImmutableMap.of("", "index.html")); }
@Provides public ResourcesRoute webjars() { return new ResourcesRoute( "WebjarsRoute", "/@/webjars", "META-INF/resources/webjars", ImmutableMap.<String, String>of(), Arrays.asList( new ResourcesRoute.CachedResourcePolicy( Predicates.<ResourcesRoute.ResourceInfo>alwaysTrue(), "max-age="+ TimeUnit.DAYS.toSeconds(100) ) ) ); } }
@Provides public ResourcesRoute webjars() { return new ResourcesRoute( "WebjarsRoute", "/@/webjars", "META-INF/resources/webjars", ImmutableMap.<String, String>of(), Arrays.asList( new ResourcesRoute.CachedResourcePolicy( Predicates.<ResourcesRoute.ResourceInfo>alwaysTrue(), "max-age="+ TimeUnit.DAYS.toSeconds(100) ) ) ); } }
final PermissionFactory permissionFactory) { super("SpecRecorderRouter", new ResourcesRoute("RecorderUIRoute", "/@/ui/recorder/", "restx.specs.recorder", ImmutableMap.of("", "index.html")), new StdRoute("RecorderRoute", new StdRestxRequestMatcher("GET", "/@/recorders")) { @Override
final PermissionFactory permissionFactory) { super("SpecRecorderRouter", new ResourcesRoute("RecorderUIRoute", "/@/ui/recorder/", "restx.specs.recorder", ImmutableMap.of("", "index.html")), new StdRoute("RecorderRoute", new StdRestxRequestMatcher("GET", "/@/recorders")) { @Override