Dropwizard Configurable Asset Bundle

An implementation of an AssetBundle for use in Dropwizard that allows user configuration.

License

License

Categories

Categories

DropWizard Container Microservices config Application Layer Libs Configuration
GroupId

GroupId

com.nefariouszhen.dropwizard
ArtifactId

ArtifactId

dropwizard-configurable-assets-bundle
Last Version

Last Version

0.8.0
Release Date

Release Date

Type

Type

jar
Description

Description

Dropwizard Configurable Asset Bundle
An implementation of an AssetBundle for use in Dropwizard that allows user configuration.
Source Code Management

Source Code Management

https://github.com/dropwizard-bundles/dropwizard-configurable-assets-bundle

Download dropwizard-configurable-assets-bundle

How to add to project

<!-- https://jarcasting.com/artifacts/com.nefariouszhen.dropwizard/dropwizard-configurable-assets-bundle/ -->
<dependency>
    <groupId>com.nefariouszhen.dropwizard</groupId>
    <artifactId>dropwizard-configurable-assets-bundle</artifactId>
    <version>0.8.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.nefariouszhen.dropwizard/dropwizard-configurable-assets-bundle/
implementation 'com.nefariouszhen.dropwizard:dropwizard-configurable-assets-bundle:0.8.0'
// https://jarcasting.com/artifacts/com.nefariouszhen.dropwizard/dropwizard-configurable-assets-bundle/
implementation ("com.nefariouszhen.dropwizard:dropwizard-configurable-assets-bundle:0.8.0")
'com.nefariouszhen.dropwizard:dropwizard-configurable-assets-bundle:jar:0.8.0'
<dependency org="com.nefariouszhen.dropwizard" name="dropwizard-configurable-assets-bundle" rev="0.8.0">
  <artifact name="dropwizard-configurable-assets-bundle" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.nefariouszhen.dropwizard', module='dropwizard-configurable-assets-bundle', version='0.8.0')
)
libraryDependencies += "com.nefariouszhen.dropwizard" % "dropwizard-configurable-assets-bundle" % "0.8.0"
[com.nefariouszhen.dropwizard/dropwizard-configurable-assets-bundle "0.8.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.google.guava : guava jar 18.0
io.dropwizard : dropwizard-core jar 0.8.0
io.dropwizard : dropwizard-servlets jar 0.8.0

test (4)

Group / Artifact Type Version
org.eclipse.jetty : jetty-servlet jar 9.2.9.v20150224
org.mockito : mockito-core jar 1.10.17
junit : junit jar 4.12
org.assertj : assertj-core jar 1.7.1

Project Modules

There are no modules declared in this project.

Configurable Assets Bundle for Dropwizard

This GitHub repository contains a drop-in replacement for Yammer's AssetsBundle class that allows for a better developer experience. Developers can use the ConfiguredAssetsBundle class anywhere they would use a AssetsBundle in their Dropwizard applications and take advantage of the ability to specify redirects for URIs to that loads them from disk instead of the classpath. This allows developers to edit browser-interpreted files and reload them without needing to recompile source.

Build Status

Maven Setup

<dependency>
  <groupId>io.dropwizard-bundles</groupId>
  <artifactId>dropwizard-configurable-assets-bundle</artifactId>
  <version>1.0.5</version>
</dependency>

Getting Started

Implement the AssetsBundleConfiguration:

public class SampleConfiguration extends Configuration implements AssetsBundleConfiguration {
  @Valid
  @NotNull
  @JsonProperty
  private final AssetsConfiguration assets = AssetsConfiguration.builder().build();

  @Override
  public AssetsConfiguration getAssetsConfiguration() {
    return assets;
  }
}

Add the assets bundle:

public class SampleService extends Application<SampleConfiguration> {
    public static void main(String[] args) throws Exception {
        new SampleService().run(args);
    }

    @Override
    public void initialize(Bootstrap<SampleConfiguration> bootstrap) {
        // Map requests to /dashboard/${1} to be found in the class path at /assets/${1}.
        bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/dashboard/"));
    }

    @Override
    public void run(SampleConfiguration configuration, Environment environment) {
        ...
    }
}

A sample local development config:

assets:
  overrides:
    # Override requests to /dashboard/${1} to instead look in 
    # ${working directory}/src/main/resources/assets/${1}
    /dashboard: src/main/resources/assets/

You can override multiple external folders with a single configuration in a following way:

assets:
  overrides:
    /dashboard/assets: /some/absolute/path/with/assets/
    /dashboard/images: /some/different/absolute/path/with/images

Instead of defining the resource path to uri path mappings in java code, they also can be specified in the configuration file.

public class SampleService extends Application<SampleConfiguration> {
    ...

    @Override
    public void initialize(Bootstrap<SampleConfiguration> bootstrap) {
        bootstrap.addBundle(new ConfiguredAssetsBundle());
    }

    @Override
    public void run(SampleConfiguration configuration, Environment environment) {
        ...
    }
}
assets:
  mappings:
    /assets: /dashboard
  overrides:
    /dashboard/assets: /some/absolute/path/with/assets/
    /dashboard/images: /some/different/absolute/path/with/images

Add Mime Types

Since 0.8, Dropwizard allows you to add new mimetypes directly to the application context.

public class SampleService extends Application<SampleConfiguration> {
   ...

   @Override
   public void run(SampleConfiguration configuration, Environment environment) {
       environment
           .getApplicationContext()
           .getMimeTypes()
           .addMimeMapping("mp4", "video/mp4");
   }
}

However if you want to override a pre-existing mime type, or add them dynamically, you can do so with your assets configuration.

assets:
  mimeTypes:
    woff: application/font-woff

Multiple URI Mappings

You can map different folders to multiple top-level directories if you wish.

Either in java code

public class SampleService extends Application<SampleConfiguration> {
    ...

    @Override
    public void initialize(Bootstrap<SampleConfiguration> bootstrap) {
        bootstrap.addBundle(new ConfiguredAssetsBundle(
            ImmutableMap.<String, String>builder()
                .put("/assets/", "/dashboard/")
                .put("/data/", "/static-data/")
                .build()
        ));
    }
}

or either in the configuration file

assets:
  mappings:
    /assets: /dashboard
    /data: /static-data
  overrides:
    ...
com.nefariouszhen.dropwizard

Dropwizard Bundles

Reusable Dropwizard Bundles

Versions

Version
0.8.0