Skip to content

Commit

Permalink
Added a Bundle that automatically registers the servlet.
Browse files Browse the repository at this point in the history
  • Loading branch information
marmelo committed Oct 15, 2018
1 parent fc0c270 commit 255b057
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -2,5 +2,4 @@
/src/main/webapp/dist
/src/main/webapp/node_modules
/src/main/webapp/package-lock.json
/src/main/resources/org/marmelo/dropwizard/metrics/bundle.js
/src/main/resources/org/marmelo/dropwizard/metrics/index.html
/src/main/resources/org/marmelo/dropwizard/metrics/*
17 changes: 14 additions & 3 deletions pom.xml
Expand Up @@ -17,11 +17,22 @@
<dropwizard.version>1.3.6</dropwizard.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
@@ -0,0 +1,72 @@
/*
* MIT License (MIT)
*
* Copyright (c) 2018 Rafael Marmelo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.marmelo.dropwizard.metrics.bundles;

import io.dropwizard.Bundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.marmelo.dropwizard.metrics.servlets.MetricsUIServlet;

/**
* Dropwizard Metrics UI Bundle.
*
* @author Rafael Marmelo
* @since 1.0
*/
public class MetricsUIBundle implements Bundle {

/**
* The servlet mapping.
*/
private final String mapping;

/**
* Creates a new Metrics UI Bundle.
*
* The UI will be deployed by default at "/admin" path.
*/
public MetricsUIBundle() {
this("/admin/*");
}
/**
* Creates a new Metrics UI Bundle.
*
* @param mapping the path where to deploy the UI ("/admin/*" by default).
*/
public MetricsUIBundle(final String mapping) {
this.mapping = mapping;
}

@Override
public void initialize(final Bootstrap<?> bootstrap) {
// empty
}

@Override
public void run(final Environment environment) {
environment.admin()
.addServlet("Dropwizard Metrics UI", new MetricsUIServlet())
.addMapping(this.mapping);
}
}
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.marmelo.dropwizard.metrics;
package org.marmelo.dropwizard.metrics.servlets;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Empty file.

0 comments on commit 255b057

Please sign in to comment.