Dropwizard Redirect Bundle

A simple bundle for DropWizard that allows for HTTP redirects.

License

License

Categories

Categories

DropWizard Container Microservices
GroupId

GroupId

com.nefariouszhen.dropwizard
ArtifactId

ArtifactId

dropwizard-redirect-bundle
Last Version

Last Version

0.8.0
Release Date

Release Date

Type

Type

jar
Description

Description

Dropwizard Redirect Bundle
A simple bundle for DropWizard that allows for HTTP redirects.
Source Code Management

Source Code Management

https://github.com/dropwizard-bundles/dropwizard-redirect-bundle

Download dropwizard-redirect-bundle

How to add to project

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

Dependencies

compile (2)

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

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 1.10.17

Project Modules

There are no modules declared in this project.

dropwizard-redirect-bundle

A Dropwizard bundle that makes redirection a blast.

Build Status

Getting Started

Just add this maven dependency:

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

To redirect one path to another path:

public class MyApplication extends Application<...> {
  // ...

  @Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new RedirectBundle(
      new PathRedirect("/old", "/new")
    ));
  }

  // ...
}

To redirect many paths at once:

public class MyApplication extends Application<...> {
  // ...

  @Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new RedirectBundle(
      new PathRedirect(ImmutableMap.<String, String>builder()
        .put("/old1", "/new1")
        .put("/old2", "/new2")
        .build())
    ));
  }

  // ...
}

Non-HTTPS to HTTPS Redirect

To redirect non-HTTPS traffic to the HTTPS port:

public class MyApplication extends Application<...> {
  // ...

  @Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new RedirectBundle(
      new HttpsRedirect()
    ));
  }

  // ...
}

To redirect non-HTTPS traffic to HTTPS and redirect a path to another path:

public class MyApplication extends Application<...> {
  // ...

  @Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new RedirectBundle(
      new PathRedirect("/", "docs"),
      new HttpsRedirect()
    ));
  }

  // ...
}

Regular Expression Redirect

For more advanced users, there is also a regular expression based redirector that has access to the full URI. This operates in a similar fashion to the mod-rewrite module for Apache:

public class MyApplication extends Application<...> {
  // ...

  @Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new RedirectBundle(
      new UriRedirect("(.*)/welcome.html$", "$1/index.html")
    ));
  }

  // ...
}

To redirect non-HTTPS traffic to HTTPS in Dropwizard v0.9.0, use a Regular Expression Redirect:

public class MyApplication extends Application<...> {
  // ...

  @Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new RedirectBundle(
      new UriRedirect("http://localhost:8080(.*)$", "https://localhost:8443$1")
    ));
  }

  // ...
}
com.nefariouszhen.dropwizard

Dropwizard Bundles

Reusable Dropwizard Bundles

Versions

Version
0.8.0