Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
700 additions
and
2 deletions.
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,3 +1,6 @@ | ||
target | ||
.idea | ||
*.iml | ||
*.class | ||
|
||
# Package Files # | ||
|
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,2 +1,144 @@ | ||
wiztowar | ||
======== | ||
WizToWar - Have your cake and eat it too | ||
======================================== | ||
|
||
WizToWar is a simple library that enables a Dropwizard service to also be deployable in a WAR container such as Tomcat. | ||
|
||
By following the steps in the usage section below you will be able to create both a Dropwizard jar and a WAR of the same | ||
service. | ||
|
||
|
||
Caveat emptor: | ||
-------------- | ||
|
||
* Only tested on Tomcat 7 | ||
* No support for bundles | ||
* Many features untested | ||
* Goes against the whole philosophy of Dropwizard... | ||
|
||
Usage | ||
------ | ||
|
||
Include the wiztowar jar as a dependency: | ||
|
||
<dependency> | ||
<groupId>com.twilio</groupId> | ||
<artifactId>wiztowar</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
|
||
Create a new class for your application like this: | ||
|
||
package com.twilio.mixerstate; | ||
|
||
import com.google.common.io.Resources; | ||
import com.twilio.wiztowar.DWAdapter; | ||
import com.yammer.dropwizard.Service; | ||
|
||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
|
||
public class MixerStateDWApplication extends DWAdapter<MixerStateServiceConfiguration> { | ||
final static MixerStateService service = new MixerStateService(); | ||
/** | ||
* Return the Dropwizard service you want to run. | ||
*/ | ||
public Service getSingletonService(){ | ||
return service; | ||
} | ||
/** | ||
* Return the File where the configuration lives. | ||
*/ | ||
@Override | ||
public File getConfigurationFile() { | ||
|
||
URL url = Resources.getResource("mixer-state-server.yml"); | ||
try { | ||
return new File(url.toURI()); | ||
} catch (URISyntaxException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} | ||
|
||
|
||
Create a main/webapp/WEB-INF/web.xml file: | ||
------------------------------------------ | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app> | ||
|
||
<listener> | ||
<listener-class>com.twilio.wiztowar.ServletContextCallback</listener-class> | ||
</listener> | ||
<servlet> | ||
<servlet-name>Jersey REST Service</servlet-name> | ||
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> | ||
<!--- Replace this with your DWAdapter derived application --> | ||
<init-param> | ||
<param-name>javax.ws.rs.Application</param-name> | ||
<param-value>com.twilio.mixerstate.MixerStateDWApplication</param-value> | ||
</init-param> | ||
<!--- Replace this with your DWAdapter derived application --> | ||
<init-param> | ||
<param-name>com.sun.jersey.config.property.packages</param-name> | ||
<param-value>com.twilio.mixerstate.resources</param-value> | ||
</init-param> | ||
<init-param> | ||
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> | ||
<param-value>true</param-value> | ||
</init-param> | ||
<!-- Only required for logging requests | ||
<init-param> | ||
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> | ||
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value> | ||
</init-param> | ||
<init-param> | ||
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name> | ||
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value> | ||
</init-param> | ||
--> | ||
<load-on-startup>1</load-on-startup> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>Jersey REST Service</servlet-name> | ||
<url-pattern>/*</url-pattern> | ||
</servlet-mapping> | ||
</web-app> | ||
|
||
Make sure you also build a WAR artifact | ||
--------------------------------------------- | ||
|
||
There are two alternatives to building a war: | ||
|
||
### Add instructions to also build a WAR | ||
|
||
This goes in `<build><plugins>` section: | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.4</version> | ||
<executions> | ||
<execution> | ||
<id>default-war</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>war</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<webappDirectory>target/webapp</webappDirectory> | ||
</configuration> | ||
</plugin> | ||
|
||
### Change packaging of your Dropwizard service | ||
|
||
If you do not intend to run the Dropwizard service standalone, you can simply change the "packaging" element in pom.xml to be "war" instead of "jar". | ||
|
||
|
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,91 @@ | ||
<?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.twilio</groupId> | ||
<artifactId>wiztowar</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<dropwizard.version>0.6.2</dropwizard.version> | ||
<metrics.version>2.2.0</metrics.version> | ||
</properties> | ||
|
||
<scm> | ||
<connection>scm:git:git://github.com/twilio/wiztowar.git</connection> | ||
<developerConnection>scm:git:git@github.com:twilio/wiztowar.git</developerConnection> | ||
<url>http://github.com/twilio/wiztowar</url> | ||
</scm> | ||
<distributionManagement> | ||
|
||
<snapshotRepository> | ||
<id>sonatype-nexus-snapshots</id> | ||
<name>Sonatype Nexus snapshot repository</name> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</snapshotRepository> | ||
<repository> | ||
<id>sonatype-nexus-staging</id> | ||
<name>Sonatype Nexus release repository</name> | ||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.yammer.dropwizard</groupId> | ||
<artifactId>dropwizard-core</artifactId> | ||
<version>${dropwizard.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.yammer.metrics</groupId> | ||
<artifactId>metrics-annotation</artifactId> | ||
<version>${metrics.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-release-plugin</artifactId> | ||
<version>2.2.2</version> | ||
<configuration> | ||
<arguments>-Dgpg.passphrase=${gpg.passphrase}</arguments> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>release-sign-artifacts</id> | ||
<activation> | ||
<property> | ||
<name>performRelease</name> | ||
<value>true</value> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>1.4</version> | ||
<configuration> | ||
<passphrase>${gpg.passphrase}</passphrase> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
Oops, something went wrong.