Throw an exception instead of using Optional<Resposne>
This commit is contained in:
parent
73fa3c3fe4
commit
ba5e5a780f
|
@ -202,12 +202,7 @@ public class MessageController {
|
||||||
contentLength += message.getBody().length();
|
contentLength += message.getBody().length();
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Response> maybeResponse = validateContentLength(contentLength, userAgent);
|
validateContentLength(contentLength, userAgent);
|
||||||
|
|
||||||
if (maybeResponse.isPresent()) {
|
|
||||||
return maybeResponse.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
validateEnvelopeType(message.getType(), userAgent);
|
validateEnvelopeType(message.getType(), userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,17 +773,16 @@ public class MessageController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Response> validateContentLength(final int contentLength, final String userAgent) {
|
private void validateContentLength(final int contentLength, final String userAgent) {
|
||||||
Metrics.summary(CONTENT_SIZE_DISTRIBUTION_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent)))
|
Metrics.summary(CONTENT_SIZE_DISTRIBUTION_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent)))
|
||||||
.record(contentLength);
|
.record(contentLength);
|
||||||
|
|
||||||
if (contentLength > MAX_MESSAGE_SIZE) {
|
if (contentLength > MAX_MESSAGE_SIZE) {
|
||||||
Metrics.counter(REJECT_OVERSIZE_MESSAGE_COUNTER, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent)))
|
Metrics.counter(REJECT_OVERSIZE_MESSAGE_COUNTER, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent)))
|
||||||
.increment();
|
.increment();
|
||||||
return Optional.of(Response.status(Status.REQUEST_ENTITY_TOO_LARGE).build());
|
throw new WebApplicationException(Status.REQUEST_ENTITY_TOO_LARGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateEnvelopeType(final int type, final String userAgent) {
|
private void validateEnvelopeType(final int type, final String userAgent) {
|
||||||
|
|
Loading…
Reference in New Issue