Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial checking of just dropwizard project; it is NOT an archetype y…
…et; to be converted though :-)
- Loading branch information
Alexey Prohorenko
committed
May 3, 2012
1 parent
2fbb103
commit cf25881
Showing
8 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
dropwizard-archetype | ||
==================== | ||
|
||
Maven2 Archetype for Coda Hale's Dropwizard | ||
Maven2 Archetype for Coda Hale's Dropwizard | ||
|
||
$ mvn package | ||
|
||
$ java -jar target/dropwizard-example-0.0.1-SNAPSHOT.jar server configs/hello-world.yml | ||
|
||
$ open http://localhost:8080/hello-world http://localhost:8080/hello-world?name=Successful+Dropwizard+User | ||
|
||
$ open http://localhost:8081/ http://localhost:8081/metrics http://localhost:8081/threads http://localhost:8081/healthcheck | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
template: Hello, %s! | ||
defaultName: Stranger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.alexeypro.samples</groupId> | ||
<artifactId>dropwizard-example</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.yammer.dropwizard</groupId> | ||
<artifactId>dropwizard-core</artifactId> | ||
<version>0.4.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<properties> | ||
<!-- use UTF-8 for everything --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<!-- compile for Java 1.6 --> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>1.6</version> | ||
<configuration> | ||
<createDependencyReducedPom>true</createDependencyReducedPom> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>com.alexeypro.samples.services.HelloWorldService</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/alexeypro/samples/HelloWorldConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.alexeypro.samples; | ||
|
||
import com.yammer.dropwizard.config.Configuration; | ||
import org.codehaus.jackson.annotate.JsonProperty; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
|
||
public class HelloWorldConfiguration extends Configuration { | ||
@NotEmpty | ||
@JsonProperty | ||
private String template; | ||
|
||
@NotEmpty | ||
@JsonProperty | ||
private String defaultName = "Stranger"; | ||
|
||
public String getTemplate() { | ||
return template; | ||
} | ||
|
||
public String getDefaultName() { | ||
return defaultName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.alexeypro.samples; | ||
|
||
public class Saying { | ||
private final long id; | ||
private final String content; | ||
|
||
public Saying(long id, String content) { | ||
this.id = id; | ||
this.content = content; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/alexeypro/samples/health/TemplateHealthCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.alexeypro.samples.health; | ||
|
||
import com.yammer.metrics.core.HealthCheck; | ||
|
||
public class TemplateHealthCheck extends HealthCheck { | ||
private final String template; | ||
|
||
public TemplateHealthCheck(String template) { | ||
super("template"); | ||
this.template = template; | ||
} | ||
|
||
@Override | ||
protected Result check() throws Exception { | ||
final String saying = String.format(template, "TEST"); | ||
if (!saying.contains("TEST")) { | ||
return Result.unhealthy("template doesn't include a name"); | ||
} | ||
return Result.healthy(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/alexeypro/samples/resources/HelloWorldResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.alexeypro.samples.resources; | ||
|
||
import com.alexeypro.samples.Saying; | ||
import com.google.common.base.Optional; | ||
import com.yammer.metrics.annotation.Timed; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
@Path("/hello-world") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class HelloWorldResource { | ||
private final String template; | ||
private final String defaultName; | ||
private final AtomicLong counter; | ||
|
||
public HelloWorldResource(String template, String defaultName) { | ||
this.template = template; | ||
this.defaultName = defaultName; | ||
this.counter = new AtomicLong(); | ||
} | ||
|
||
@GET | ||
@Timed | ||
public Saying sayHello(@QueryParam("name") Optional<String> name) { | ||
return new Saying(counter.incrementAndGet(), | ||
String.format(template, name.or(defaultName))); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/alexeypro/samples/services/HelloWorldService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.alexeypro.samples.services; | ||
|
||
import com.alexeypro.samples.HelloWorldConfiguration; | ||
import com.alexeypro.samples.resources.HelloWorldResource; | ||
import com.alexeypro.samples.health.TemplateHealthCheck; | ||
import com.yammer.dropwizard.Service; | ||
import com.yammer.dropwizard.config.Environment; | ||
|
||
public class HelloWorldService extends Service<HelloWorldConfiguration> { | ||
public static void main(String[] args) throws Exception { | ||
new HelloWorldService().run(args); | ||
} | ||
|
||
private HelloWorldService() { | ||
super("hello-world"); | ||
} | ||
|
||
@Override | ||
protected void initialize(HelloWorldConfiguration configuration, | ||
Environment environment) { | ||
final String template = configuration.getTemplate(); | ||
final String defaultName = configuration.getDefaultName(); | ||
environment.addResource(new HelloWorldResource(template, defaultName)); | ||
environment.addHealthCheck(new TemplateHealthCheck(template)); | ||
} | ||
|
||
} |