public StaticResourcesHandler(Customization customization) { super(new RouteOptions()); this.customization = customization; }
public OnRoute cacheCapacity(int cacheCapacity) { options.cacheCapacity(cacheCapacity); return this; }
public OnRoute cacheTTL(long cacheTTL) { options.cacheTTL(cacheTTL); return this; }
private RouteOptions opts(MediaType contentType) { // don't change if already customized if (options.contentType() == null || !options.contentTypeCustomized()) { options.contentType(contentType); } return options; }
@Override public boolean isAPI() { if (options.mvc()) return false; return options.contentType() != MediaType.HTML_UTF_8; }
public AbstractDecoratingHttpHandler(FastHttp http, RouteOptions options) { super(options); U.notNull(http, "http"); this.decorator = options.managed() ? new HttpManagedHandlerDecorator(this, http, options) : new HttpUnmanagedHandlerDecorator(this, http, options.contentType()); }
RouteOptions opts = handler.options(); TransactionMode txm = opts.transaction(); String tx = txm != TransactionMode.NONE ? AnsiColor.bold(txm.name()) : txm.name(); "!roles", opts.roles(), "transaction", tx, "mvc", opts.mvc(), "cacheTTL", opts.cacheTTL());
private void execHandlerJob(final Channel channel, final boolean isKeepAlive, final MediaType contentType, final Req req) { With.tag(CTX_TAG_HANDLER).exchange(req).run(() -> { try { req.response() .view(options.view()) .contentType(options.contentType()) .mvc(options.mvc()); handleWithWrappers(channel, isKeepAlive, contentType, req, wrappers.get()); } catch (Throwable e) { handleError(req, e); } }); }
@Override public void reload() { reloaded = true; bootstrappedBeans.reset(); ioCContext.reset(); http().resetConfig(); defaults = new RouteOptions(); defaults.zone(zone); attributes().clear(); ViewResolver viewResolver = custom().viewResolver(); if (viewResolver instanceof AbstractViewResolver) { ((AbstractViewResolver) viewResolver).reset(); } }
static HttpWrapper[] assembleWrappers(FastHttp http, RouteOptions options) { List<HttpWrapper> wrappers = U.list(); wrappers.add(new HttpAuthWrapper(options.roles())); TransactionMode txMode = U.or(options.transaction(), TransactionMode.NONE); if (txMode != TransactionMode.NONE) { wrappers.add(new HttpTxWrapper(txMode)); } Collections.addAll(wrappers, getConfiguredWrappers(http, options)); return U.arrayOf(HttpWrapper.class, wrappers); }
@SuppressWarnings("unchecked") protected Cache<HTTPCacheKey, CachedResp> createCache() { if (options == null || options.cacheTTL() <= 0) return null; return Caching.of(HTTPCacheKey.class, CachedResp.class) .name(verb + " " + path) .ttl(options.cacheTTL()) .capacity(options.cacheCapacity()) .manageable(true) .statistics(true) .build(); }
public OnRoute managed(boolean managed) { options.managed(managed); return this; }
public OnRoute contentType(MediaType contentType) { options.contentType(contentType); return this; }
public OnRoute transaction(TransactionMode txMode) { options.transaction(txMode); return this; }
public OnRoute wrappers(HttpWrapper... wrappers) { options.wrappers(wrappers); return this; }
private RouteOptions mvcOpts() { return opts(MediaType.HTML_UTF_8).mvc(true); }
public OnRoute roles(String... roles) { options.roles(roles); return this; }
public OnRoute view(String viewName) { options.view(viewName); return this; }
RouteOptions opts = handler.options(); TransactionMode txm = opts.transaction(); String tx = txm != TransactionMode.NONE ? AnsiColor.bold(txm.name()) : txm.name(); "!roles", opts.roles(), "transaction", tx, "mvc", opts.mvc(), "cacheTTL", opts.cacheTTL());
@Override public void run() { try { req.response() .view(options.view()) .contentType(options.contentType()) .mvc(options.mvc()); handleWithWrappers(channel, isKeepAlive, contentType, req, wrappers.get()); } catch (Throwable e) { handleError(req, e); } }