4
4
import com .fasterxml .jackson .databind .ObjectMapper ;
5
5
import com .google .common .base .Charsets ;
6
6
import com .google .common .base .Optional ;
7
- import com .google .common .base .Preconditions ;
8
7
import com .google .common .base .Strings ;
9
8
import com .yammer .dropwizard .jersey .caching .CacheControl ;
10
- import com .yammer .metrics .annotation .Timed ;
9
+ import com .yammer .metrics .annotation .ExceptionMetered ;
10
+ import com .yammer .metrics .annotation .Metered ;
11
11
import org .elasticsearch .action .index .IndexResponse ;
12
12
import org .elasticsearch .client .Client ;
13
13
import org .multibit .hd .brit .crypto .PGPUtils ;
@@ -49,7 +49,7 @@ public class PublicErrorReportingResource extends BaseResource {
49
49
private final Client elasticClient ;
50
50
51
51
/**
52
- * The maximum length of the payload (typical value is 680 bytes )
52
+ * The maximum length of the payload (typical value before encryption is 200Kb so compressed should be much smaller )
53
53
*/
54
54
private final static int MAX_PAYLOAD_LENGTH = 2_000_000 ;
55
55
@@ -91,7 +91,8 @@ public PublicErrorReportingResource(byte[] secring, char[] password, String serv
91
91
@ Path ("/public-key" )
92
92
@ Consumes ("text/plain" )
93
93
@ Produces ("text/plain" )
94
- @ Timed
94
+ @ Metered
95
+ @ ExceptionMetered
95
96
@ CacheControl (maxAge = 1 , maxAgeUnit = TimeUnit .DAYS )
96
97
public Response getPublicKey () {
97
98
return Response .ok (SERVICE_PUBLIC_KEY ).build ();
@@ -107,12 +108,17 @@ public Response getPublicKey() {
107
108
@ POST
108
109
@ Consumes ("text/plain" )
109
110
@ Produces ("application/json" )
110
- @ Timed
111
+ @ Metered
112
+ @ ExceptionMetered
111
113
@ CacheControl (noCache = true )
112
114
public Response submitEncryptedErrorReport (String payload ) {
113
115
114
- Preconditions .checkNotNull (payload , "'payload' must be present" );
115
- Preconditions .checkState (payload .length () < MAX_PAYLOAD_LENGTH , "'payload' is too long" );
116
+ if (Strings .isNullOrEmpty (payload )) {
117
+ throw new WebApplicationException (Response .Status .BAD_REQUEST );
118
+ }
119
+ if (payload .length () > MAX_PAYLOAD_LENGTH ) {
120
+ throw new WebApplicationException (Response .Status .BAD_REQUEST );
121
+ }
116
122
117
123
ErrorReportResult result = processEncryptedErrorReport (payload .getBytes (Charsets .UTF_8 ));
118
124
0 commit comments