Skip to content

Commit e437de4

Browse files
committed
Upgrade to Dropwizard 0.7.0
1 parent 8f18b75 commit e437de4

File tree

10 files changed

+175
-103
lines changed

10 files changed

+175
-103
lines changed

pom.xml

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,78 @@
1111
<artifactId>BitHub</artifactId>
1212
<version>0.1</version>
1313

14+
<properties>
15+
<dropwizard.version>0.7.0</dropwizard.version>
16+
</properties>
17+
1418
<dependencies>
1519
<dependency>
16-
<groupId>com.yammer.dropwizard</groupId>
20+
<groupId>io.dropwizard</groupId>
1721
<artifactId>dropwizard-core</artifactId>
18-
<version>0.6.2</version>
22+
<version>${dropwizard.version}</version>
1923
</dependency>
2024
<dependency>
21-
<groupId>com.yammer.metrics</groupId>
22-
<artifactId>metrics-graphite</artifactId>
23-
<version>2.2.0</version>
24-
</dependency>
25-
<dependency>
26-
<groupId>com.yammer.dropwizard</groupId>
25+
<groupId>io.dropwizard</groupId>
2726
<artifactId>dropwizard-auth</artifactId>
28-
<version>0.6.2</version>
27+
<version>${dropwizard.version}</version>
2928
</dependency>
3029
<dependency>
31-
<groupId>com.yammer.dropwizard</groupId>
30+
<groupId>io.dropwizard</groupId>
3231
<artifactId>dropwizard-jdbi</artifactId>
33-
<version>0.6.2</version>
32+
<version>${dropwizard.version}</version>
3433
</dependency>
3534
<dependency>
36-
<groupId>com.yammer.dropwizard</groupId>
35+
<groupId>io.dropwizard</groupId>
3736
<artifactId>dropwizard-client</artifactId>
38-
<version>0.6.2</version>
37+
<version>${dropwizard.version}</version>
3938
</dependency>
4039
<dependency>
41-
<groupId>com.yammer.dropwizard</groupId>
40+
<groupId>io.dropwizard</groupId>
4241
<artifactId>dropwizard-migrations</artifactId>
43-
<version>0.6.2</version>
42+
<version>${dropwizard.version}</version>
4443
</dependency>
4544
<dependency>
46-
<groupId>com.yammer.dropwizard</groupId>
45+
<groupId>io.dropwizard</groupId>
4746
<artifactId>dropwizard-testing</artifactId>
48-
<version>0.6.2</version>
47+
<version>${dropwizard.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.dropwizard</groupId>
51+
<artifactId>dropwizard-metrics-graphite</artifactId>
52+
<version>${dropwizard.version}</version>
4953
</dependency>
54+
<dependency>
55+
<groupId>io.dropwizard</groupId>
56+
<artifactId>dropwizard-views</artifactId>
57+
<version>${dropwizard.version}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>io.dropwizard</groupId>
61+
<artifactId>dropwizard-servlets</artifactId>
62+
<version>${dropwizard.version}</version>
63+
</dependency>
64+
5065
<dependency>
5166
<groupId>com.sun.jersey</groupId>
5267
<artifactId>jersey-json</artifactId>
53-
<version>1.17.1</version>
68+
<version>1.18.1</version>
5469
</dependency>
70+
<dependency>
71+
<groupId>com.codahale.metrics</groupId>
72+
<artifactId>metrics-graphite</artifactId>
73+
<version>3.0.2</version>
74+
</dependency>
75+
5576
<dependency>
5677
<groupId>com.sun.jersey.contribs</groupId>
5778
<artifactId>jersey-multipart</artifactId>
58-
<version>1.17.1</version>
79+
<version>1.18.1</version>
5980
</dependency>
6081
<dependency>
6182
<groupId>commons-net</groupId>
6283
<artifactId>commons-net</artifactId>
6384
<version>3.2</version>
6485
</dependency>
65-
<dependency>
66-
<groupId>com.yammer.dropwizard</groupId>
67-
<artifactId>dropwizard-views</artifactId>
68-
<version>0.6.2</version>
69-
</dependency>
7086
<dependency>
7187
<groupId>org.ocpsoft.prettytime</groupId>
7288
<artifactId>prettytime</artifactId>

src/main/java/org/whispersystems/bithub/BithubServerConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
package org.whispersystems.bithub;
1919

2020
import com.fasterxml.jackson.annotation.JsonProperty;
21-
import com.yammer.dropwizard.config.Configuration;
2221
import org.whispersystems.bithub.config.BithubConfiguration;
2322
import org.whispersystems.bithub.config.CoinbaseConfiguration;
2423
import org.whispersystems.bithub.config.GithubConfiguration;
25-
import org.whispersystems.bithub.config.WebhookConfiguration;
2624

2725
import javax.validation.Valid;
2826
import javax.validation.constraints.NotNull;
2927

28+
import io.dropwizard.Configuration;
29+
3030
public class BithubServerConfiguration extends Configuration {
3131

3232
@Valid

src/main/java/org/whispersystems/bithub/BithubService.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,36 @@
1717

1818
package org.whispersystems.bithub;
1919

20-
import com.yammer.dropwizard.Service;
21-
import com.yammer.dropwizard.auth.basic.BasicAuthProvider;
22-
import com.yammer.dropwizard.config.Bootstrap;
23-
import com.yammer.dropwizard.config.Environment;
24-
import com.yammer.dropwizard.views.ViewBundle;
20+
import org.eclipse.jetty.servlets.CrossOriginFilter;
2521
import org.whispersystems.bithub.auth.GithubWebhookAuthenticator;
2622
import org.whispersystems.bithub.client.CoinbaseClient;
2723
import org.whispersystems.bithub.client.GithubClient;
2824
import org.whispersystems.bithub.config.RepositoryConfiguration;
2925
import org.whispersystems.bithub.controllers.GithubController;
3026
import org.whispersystems.bithub.controllers.StatusController;
31-
import org.whispersystems.bithub.filters.CorsHeaderFilter;
3227
import org.whispersystems.bithub.mappers.IOExceptionMapper;
3328
import org.whispersystems.bithub.mappers.UnauthorizedHookExceptionMapper;
3429

30+
import javax.servlet.DispatcherType;
3531
import java.math.BigDecimal;
32+
import java.util.EnumSet;
3633
import java.util.List;
3734

35+
import io.dropwizard.Application;
36+
import io.dropwizard.auth.basic.BasicAuthProvider;
37+
import io.dropwizard.setup.Bootstrap;
38+
import io.dropwizard.setup.Environment;
39+
import io.dropwizard.views.ViewBundle;
40+
3841
/**
3942
* The main entry point for the service.
4043
*
4144
* @author Moxie Marlinspike
4245
*/
43-
public class BithubService extends Service<BithubServerConfiguration> {
46+
public class BithubService extends Application<BithubServerConfiguration> {
4447

4548
@Override
4649
public void initialize(Bootstrap<BithubServerConfiguration> bootstrap) {
47-
bootstrap.setName("bithub-server");
4850
bootstrap.addBundle(new ViewBundle());
4951
}
5052

@@ -61,13 +63,15 @@ public void run(BithubServerConfiguration config, Environment environment)
6163
GithubClient githubClient = new GithubClient(githubUser, githubToken);
6264
CoinbaseClient coinbaseClient = new CoinbaseClient(config.getCoinbaseConfiguration().getApiKey());
6365

64-
environment.addFilter(new CorsHeaderFilter(), "/v1/status/*");
65-
environment.addResource(new GithubController(githubRepositories, githubClient, coinbaseClient, payoutRate));
66-
environment.addResource(new StatusController(coinbaseClient, payoutRate));
67-
environment.addProvider(new IOExceptionMapper());
68-
environment.addProvider(new UnauthorizedHookExceptionMapper());
69-
environment.addProvider(new BasicAuthProvider<>(
70-
new GithubWebhookAuthenticator(githubWebhookUser, githubWebhookPwd), GithubWebhookAuthenticator.REALM));
66+
environment.servlets().addFilter("CORS", CrossOriginFilter.class)
67+
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
68+
69+
environment.jersey().register(new GithubController(githubRepositories, githubClient, coinbaseClient, payoutRate));
70+
environment.jersey().register(new StatusController(coinbaseClient, payoutRate));
71+
environment.jersey().register(new IOExceptionMapper());
72+
environment.jersey().register(new UnauthorizedHookExceptionMapper());
73+
environment.jersey().register(new BasicAuthProvider<>(new GithubWebhookAuthenticator(githubWebhookUser, githubWebhookPwd),
74+
GithubWebhookAuthenticator.REALM));
7175
}
7276

7377
public static void main(String[] args) throws Exception {

src/main/java/org/whispersystems/bithub/auth/GithubWebhookAuthenticator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.whispersystems.bithub.auth;
22

33
import com.google.common.base.Optional;
4-
import com.yammer.dropwizard.auth.Authenticator;
5-
import com.yammer.dropwizard.auth.basic.BasicCredentials;
4+
5+
import io.dropwizard.auth.Authenticator;
6+
import io.dropwizard.auth.basic.BasicCredentials;
67

78
/**
89
* Accepts only one fixed username/password combination.

src/main/java/org/whispersystems/bithub/controllers/GithubController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
package org.whispersystems.bithub.controllers;
1919

20+
import com.codahale.metrics.annotation.Timed;
2021
import com.fasterxml.jackson.databind.ObjectMapper;
21-
import com.yammer.dropwizard.auth.Auth;
22-
import com.yammer.metrics.annotation.Timed;
2322
import org.apache.commons.net.util.SubnetUtils;
2423
import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
2524
import org.slf4j.Logger;
@@ -52,6 +51,8 @@
5251
import java.util.Map;
5352
import java.util.Set;
5453

54+
import io.dropwizard.auth.Auth;
55+
5556
/**
5657
* Handles incoming API calls from GitHub. These are currently only
5758
* PushEvent webhooks.

src/main/java/org/whispersystems/bithub/controllers/StatusController.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.whispersystems.bithub.controllers;
1919

20-
import com.yammer.metrics.annotation.Timed;
20+
import com.codahale.metrics.annotation.Timed;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import org.whispersystems.bithub.client.CoinbaseClient;
@@ -87,12 +87,13 @@ public Response getCurrentCommitPrice(@QueryParam("format") @DefaultValue("png")
8787
CacheControl cacheControl = new CacheControl();
8888
cacheControl.setNoCache(true);
8989

90-
if (format.equals("json")) {
91-
return Response.ok(cachedPaymentStatus.get().getEntity(), MediaType.APPLICATION_JSON_TYPE).cacheControl(cacheControl).build();
92-
} else if (format.equals("png_small")) {
93-
return Response.ok(cachedPaymentStatus.get().getSmallBadge(), "image/png").cacheControl(cacheControl).build();
94-
} else {
95-
return Response.ok(cachedPaymentStatus.get().getBadge(), "image/png").cacheControl(cacheControl).build();
90+
switch (format) {
91+
case "json":
92+
return Response.ok(cachedPaymentStatus.get().getEntity(), MediaType.APPLICATION_JSON_TYPE).cacheControl(cacheControl).build();
93+
case "png_small":
94+
return Response.ok(cachedPaymentStatus.get().getSmallBadge(), "image/png").cacheControl(cacheControl).build();
95+
default:
96+
return Response.ok(cachedPaymentStatus.get().getBadge(), "image/png").cacheControl(cacheControl).build();
9697
}
9798
}
9899

src/main/java/org/whispersystems/bithub/views/RecentTransactionsView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.whispersystems.bithub.views;
1919

20-
import com.yammer.dropwizard.views.View;
2120
import org.slf4j.Logger;
2221
import org.slf4j.LoggerFactory;
2322
import org.whispersystems.bithub.entities.Transaction;
@@ -27,6 +26,8 @@
2726
import java.util.LinkedList;
2827
import java.util.List;
2928

29+
import io.dropwizard.views.View;
30+
3031
/**
3132
* A rendered HTML view of recent BitHub transactions.
3233
*

0 commit comments

Comments
 (0)