|
1 | 1 | package com.chigix.resserver.endpoint.GetBucket; |
2 | 2 |
|
3 | 3 | import com.chigix.resserver.config.ApplicationContext; |
| 4 | +import com.chigix.resserver.domain.error.InvalidArgument; |
4 | 5 | import com.chigix.resserver.domain.model.bucket.Bucket; |
5 | 6 | import com.chigix.resserver.domain.model.resource.Resource; |
6 | 7 | import com.chigix.resserver.domain.error.NoSuchBucket; |
@@ -187,16 +188,35 @@ public int read() throws IOException { |
187 | 188 | ctx.writeAndFlush(new HttpChunkedInput(new ChunkedStream(result))).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); |
188 | 189 | } |
189 | 190 |
|
190 | | - private ListResponseContext buildListResponseContext(QueryStringDecoder query, Bucket bucket) { |
| 191 | + private ListResponseContext buildListResponseContext( |
| 192 | + QueryStringDecoder query, Bucket bucket) |
| 193 | + throws InvalidArgument { |
191 | 194 | ListResponseContext resp = new ListResponseContext(bucket); |
192 | 195 | resp.delimiter = decodeQueryParamString(query, "delimiter"); |
193 | 196 | resp.startAfter = decodeQueryParamString(query, "start-after"); |
194 | 197 | resp.encodingType = decodeQueryParamString(query, "encoding-type"); |
195 | 198 | resp.prefix = decodeQueryParamString(query, "prefix"); |
196 | | - String max_keys = decodeQueryParamString(query, "max-keys"); |
| 199 | + final String max_keys = decodeQueryParamString(query, "max-keys"); |
197 | 200 | if (max_keys != null) { |
198 | | - // @TODO Check exception for invalid format of integer number. |
199 | | - int max_keys_int = Integer.valueOf(max_keys); |
| 201 | + final int max_keys_int; |
| 202 | + try { |
| 203 | + max_keys_int = Integer.valueOf(max_keys); |
| 204 | + } catch (NumberFormatException numberFormatException) { |
| 205 | + throw new InvalidMaxKeys() { |
| 206 | + @Override |
| 207 | + public String getArgumentValue() { |
| 208 | + return max_keys; |
| 209 | + } |
| 210 | + }; |
| 211 | + } |
| 212 | + if (max_keys_int < 0 || max_keys_int > 2147483647) { |
| 213 | + throw new InvalidMaxKeys() { |
| 214 | + @Override |
| 215 | + public String getArgumentValue() { |
| 216 | + return max_keys_int + ""; |
| 217 | + } |
| 218 | + }; |
| 219 | + } |
200 | 220 | resp.maxKeys = max_keys_int; |
201 | 221 | } |
202 | 222 | resp.continuationToken = decodeQueryParamString(query, "continuation-token"); |
@@ -369,4 +389,21 @@ public ListResponseContext(Bucket bucket) { |
369 | 389 |
|
370 | 390 | } |
371 | 391 |
|
| 392 | + private static abstract class InvalidMaxKeys extends InvalidArgument implements |
| 393 | + InvalidArgument.ArgumentNameInclude, |
| 394 | + InvalidArgument.ArgumentValueInclude { |
| 395 | + |
| 396 | + @Override |
| 397 | + public String getMessage() { |
| 398 | + return "Argument maxKeys must be an integer " |
| 399 | + + "between 0 and 2147483647"; |
| 400 | + } |
| 401 | + |
| 402 | + @Override |
| 403 | + public String getArgumentName() { |
| 404 | + return "maxKeys"; |
| 405 | + } |
| 406 | + |
| 407 | + } |
| 408 | + |
372 | 409 | } |
0 commit comments