dropwizard-redirect-bundle

A simple bundle for DropWizard that allows for HTTP redirects.

License

License

Categories

Categories

DropWizard Container Microservices
GroupId

GroupId

io.dropwizard-bundles
ArtifactId

ArtifactId

dropwizard-redirect-bundle
Last Version

Last Version

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

Dependencies

compile (1)

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

test (2)

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

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")
    ));
  }

  // ...
}
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
0.9.2
0.9.1
0.9.0
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0