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

io.dropwizard-bundles
ArtifactId

ArtifactId

dropwizard-configurable-assets-bundle
Last Version

Last Version

1.3.5
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/io.dropwizard-bundles/dropwizard-configurable-assets-bundle/ -->
<dependency>
    <groupId>io.dropwizard-bundles</groupId>
    <artifactId>dropwizard-configurable-assets-bundle</artifactId>
    <version>1.3.5</version>
</dependency>
// https://jarcasting.com/artifacts/io.dropwizard-bundles/dropwizard-configurable-assets-bundle/
implementation 'io.dropwizard-bundles:dropwizard-configurable-assets-bundle:1.3.5'
// https://jarcasting.com/artifacts/io.dropwizard-bundles/dropwizard-configurable-assets-bundle/
implementation ("io.dropwizard-bundles:dropwizard-configurable-assets-bundle:1.3.5")
'io.dropwizard-bundles:dropwizard-configurable-assets-bundle:jar:1.3.5'
<dependency org="io.dropwizard-bundles" name="dropwizard-configurable-assets-bundle" rev="1.3.5">
  <artifact name="dropwizard-configurable-assets-bundle" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.dropwizard-bundles', module='dropwizard-configurable-assets-bundle', version='1.3.5')
)
libraryDependencies += "io.dropwizard-bundles" % "dropwizard-configurable-assets-bundle" % "1.3.5"
[io.dropwizard-bundles/dropwizard-configurable-assets-bundle "1.3.5"]

Dependencies

compile (2)

Group / Artifact Type Version
io.dropwizard : dropwizard-core jar
io.dropwizard : dropwizard-servlets jar

test (6)

Group / Artifact Type Version
junit : junit jar
org.assertj : assertj-core jar 1.7.1
org.eclipse.jetty : jetty-http jar
org.eclipse.jetty : jetty-servlet jar
org.eclipse.jetty : jetty-servlet jar
org.mockito : mockito-core jar

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:
    ...
io.dropwizard-bundles

Dropwizard Bundles

Reusable Dropwizard Bundles

Versions

Version
1.3.5
1.2.2
1.1.4
1.0.5
1.0.0
1.0.0-rc2
0.9.2-2
0.9.2-1
0.9.2
0.9.1
0.9.0
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1-1
0.8.1
0.8.0