Java 类io.dropwizard.servlets.assets.AssetServlet 实例源码

项目:zucchini-ui    文件:ZucchiniUIApplication.java   
@Override
public void run(final ZucchiniUIConfiguration configuration, final Environment environment) throws Exception {
    // Register the servlet that generates the UI Javascript config file
    final ServletHolder uiConfigServletHolder = new ServletHolder(new UIConfigServlet(configuration.getFrontend(), environment.getObjectMapper(), BASE_PATH));
    environment.getApplicationContext().addServlet(uiConfigServletHolder, BASE_PATH + "/assets/config.js");

    // Redirect to UI
    final ServletHolder redirectServletHolder = new ServletHolder(new RedirectServlet(BASE_PATH + "/"));
    environment.getApplicationContext().addServlet(redirectServletHolder, "");
    environment.getApplicationContext().addServlet(redirectServletHolder, BASE_PATH);

    // Forward 404 pages to index (used for browser history)
    final FilterHolder forwardFilterHolder = new FilterHolder(new ForwardToIndexFilter(BASE_PATH));
    environment.getApplicationContext().addFilter(forwardFilterHolder, BASE_PATH + "/*", EnumSet.allOf(DispatcherType.class));

    // Default servlet
    final ServletHolder defaultServletHolder = new ServletHolder(new AssetServlet("/favicons/", "/", null, StandardCharsets.UTF_8));
    environment.getApplicationContext().addServlet(defaultServletHolder, "/");
}
项目:dropwizard-markdown-assets-bundle    文件:MarkdownAssetsServlet.java   
/**
 * Construct a {@link MarkdownAssetsServlet} configured with provided parameters, having a wrapped default
 * {@link AssetServlet} for fulfilling non-markdown asset requests.
 * <p>
 * {@code MarkdownAssetsServlet} and {@link AssetServlet} serve static assets loaded from {@code resourceURL}
 * (typically a file: or jar: URL). The assets are served at URIs rooted at {@code uriPath}. For
 * example, given a {@code resourceURL} of {@code "file:/data/assets"} and a {@code uriPath} of
 * {@code "/js"}, an {@code AssetServlet} would serve the contents of {@code
 * /data/assets/example.js} in response to a request for {@code /js/example.js}. If a directory
 * is requested and {@code indexFile} is defined, then {@code AssetServlet} will attempt to
 * serve a file with that name in that directory.
 *  @param resourcePath      the base URL from which assets are loaded
 * @param uriPath            the URI path fragment in which all requests are rooted
 * @param indexFile          the filename to use when directories are requested
 * @param defaultCharset     the default character set
 * @param configuration      environment-specific configuration properties
 * @param extensions         Flexmark-Java markdown rendering extensions to use
 * @param options            Flexmark-Java markdown rendering options
 * @param cacheBuilderSpec   {@link CacheBuilderSpec} for rendered pages
 */
public MarkdownAssetsServlet(@NotNull String resourcePath,
                             @NotNull String uriPath,
                             @NotNull String indexFile,
                             @NotNull Charset defaultCharset,
                             @NotNull MarkdownAssetsConfiguration configuration,
                             @NotNull List<Extension> extensions,
                             @NotNull DataHolder options,
                             @NotNull CacheBuilderSpec cacheBuilderSpec) {

    this.resourcePath = resourcePath;
    this.uriPath = uriPath;
    this.indexFile = indexFile;
    this.defaultCharset = defaultCharset;
    this.configuration = configuration;

    parser = Parser.builder(options).extensions(extensions).build();
    renderer = HtmlRenderer.builder(options).extensions(extensions).build();

    assetServlet = new AssetServlet(resourcePath, uriPath, indexFile, defaultCharset);
    pageCache = CacheBuilder.from(cacheBuilderSpec)
            .build(new CacheLoader<URL, CachedPage>() {
                @Override
                public CachedPage load(@NotNull URL key) throws Exception {
                    return renderPage(key);
                }
            });
    try {
        URL resource = this.getClass().getResource(resourcePath);
        Preconditions.checkNotNull(resource, "Resource root URL (" + resourcePath + ") was not found");

        resourceRootURL = resource.toURI();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Resource root URL (" + resourcePath + ") was ind", e);
    }
}
项目:soabase    文件:AdminConsoleApp.java   
@Override
public final void run(T configuration, Environment environment) throws Exception
{
    environment.jersey().register(DiscoveryResource.class);
    environment.jersey().register(AttributesResource.class);
    environment.jersey().register(PreferencesResource.class);

    environment.jersey().register(AuthResource.class);
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            AuthSpecHolder holder = new AuthSpecHolder(builder.getAuthSpec());
            bind(holder).to(AuthSpecHolder.class);
        }
    };
    environment.jersey().register(binder);
    if ( builder.getAuthSpec() != null )
    {
        environment.servlets().setSessionHandler(new SessionHandler());
    }

    ComponentManager componentManager = SoaBundle.getFeatures(environment).getNamed(ComponentManager.class, SoaFeatures.DEFAULT_NAME);
    for ( TabComponent component : componentManager.getTabs() )
    {
        int index = 0;
        for ( AssetsPath assetsPath : component.getAssetsPaths() )
        {
            AssetServlet servlet = new AssetServlet(assetsPath.getResourcePath(), assetsPath.getUriPath(), null, Charsets.UTF_8);
            environment.servlets().addServlet(component.getName() + index++, servlet).addMapping(assetsPath.getUriPath() + '*');
        }
    }

}
项目:metadict    文件:SinglePageAppAssetsBundle.java   
@Override
protected AssetServlet createServlet() {
    return new SinglePageAppAssetServlet(this.getResourcePath(), this.getUriPath(), this.getIndexFile(), StandardCharsets.UTF_8);
}
项目:robe    文件:AdvancedAssetBundle.java   
private HttpServlet getClasspathAssetServlet(AssetConfiguration assetConf, String resourcePath, String uriPath) {
    return new AssetServlet(resourcePath,uriPath,assetConf.getIndexFile(), Charsets.UTF_8);
}