Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bazaarvoice/dropwizard-redirect-bundle
A simple bundle for DropWizard that allows for HTTP redirects
https://github.com/bazaarvoice/dropwizard-redirect-bundle
Last synced: about 2 months ago
JSON representation
A simple bundle for DropWizard that allows for HTTP redirects
- Host: GitHub
- URL: https://github.com/bazaarvoice/dropwizard-redirect-bundle
- Owner: bazaarvoice
- License: other
- Archived: true
- Created: 2012-11-30T20:21:45.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2022-03-09T15:21:49.000Z (almost 3 years ago)
- Last Synced: 2024-08-04T01:05:21.370Z (5 months ago)
- Language: Java
- Size: 25.4 KB
- Stars: 13
- Watchers: 23
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-dropwizard - dropwizard-redirect-bundle - allows for HTTP redirects. (Open Source / Eclipse)
README
**NOTE: THIS PROJECT IS DEPRECATED.** This projects is no longer maintained. It is deprecated for
[dropwizard-bundles maintained fork](https://github.com/dropwizard-bundles/dropwizard-redirect-bundle).
Users of this project should update their project dependencies appropriately.Getting Started
===============Just add this maven dependency:
```xmlcom.bazaarvoice.dropwizard
dropwizard-redirect-bundle
0.4.0```
- For Dropwizard 0.6.2: use version < 0.3.0
- For Dropwizard 0.7.0: use version >= 0.3.0To redirect one path to another path:
```java
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:
```java
public class MyApplication extends Application<...> {
// ...@Override
public void initialize(Bootstrap> bootstrap) {
bootstrap.addBundle(new RedirectBundle(
new PathRedirect(ImmutableMap.builder()
.put("/old1", "/new1")
.put("/old2", "/new2")
.build())
));
}// ...
}
```To redirect non-HTTPS traffic to the HTTPS port:
```java
public class MyApplication extends Application<...> {
// ...@Override
public void initialize(Bootstrap> bootstrap) {
bootstrap.addBundle(new RedirectBundle(
new HttpsRedirect()
));
}// ...
}
```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:
```java
public class MyApplication extends Application<...> {
// ...@Override
public void initialize(Bootstrap> bootstrap) {
bootstrap.addBundle(new RedirectBundle(
new UriRedirect("(.*)/welcome.html$", "$1/index.html")
));
}// ...
}
```If you have to combine http to https redirect and path redirect at the same time, then you want to do the following:
```java
public class MyApplication extends Application<...> {
// ...@Override
public void initialize(Bootstrap> bootstrap) {
bootstrap.addBundle(new RedirectBundle(
bootstrap.addBundle(new RedirectBundle(new PathRedirect("/", "docs"), new HttpsRedirect()));
));
}// ...
}
```