diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.java index af7db1e5..6e0ab500 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.java @@ -36,6 +36,14 @@ public interface GateleenExceptionFactory { public Exception newException(String msg, Throwable cause); + /** Convenience overload for {@link #newIllegalStateException(String, Throwable)}. */ + public default IllegalStateException newIllegalStateException(String msg) { return newIllegalStateException(msg, null); } + + /** Convenience overload for {@link #newIllegalStateException(String, Throwable)}. */ + public default IllegalStateException newIllegalStateException(Throwable cause) { return newIllegalStateException(null, cause); } + + public IllegalStateException newIllegalStateException(String msg, Throwable cause); + public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.java index 1a26ae48..1ce9631a 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.java @@ -16,6 +16,12 @@ public Exception newException(String message, Throwable cause) { return new GateleenNoStacktraceException(message, cause); } + @Override + public IllegalStateException newIllegalStateException(String msg, Throwable cause) { + if (cause instanceof IllegalStateException) return (IllegalStateException) cause; + return new NoStackIllegalStateException(msg); + } + @Override public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message) { return new GateleenNoStackReplyException(failureType, failureCode, message); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.java index 1fc0889c..b15e3719 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.java @@ -15,6 +15,11 @@ public Exception newException(String message, Throwable cause) { return new Exception(message, cause); } + @Override + public IllegalStateException newIllegalStateException(String msg, Throwable cause) { + return new IllegalStateException(msg, cause); + } + @Override public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message) { return new ReplyException(failureType, failureCode, message); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/NoStackIllegalStateException.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/NoStackIllegalStateException.java new file mode 100644 index 00000000..e773a9c0 --- /dev/null +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/NoStackIllegalStateException.java @@ -0,0 +1,26 @@ +package org.swisspush.gateleen.core.exception; + +public class NoStackIllegalStateException extends IllegalStateException { + + public NoStackIllegalStateException() { + super(); + } + + public NoStackIllegalStateException(String s) { + super(s); + } + + public NoStackIllegalStateException(String message, Throwable cause) { + super(message, cause); + } + + public NoStackIllegalStateException(Throwable cause) { + super(cause); + } + + @Override + public Throwable fillInStackTrace() { + return this; + } + +} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java index 2d02b7ef..823a4c65 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java @@ -28,6 +28,6 @@ public void setRoutingContexttHandler(Handler wrappedRoutingCont @Override protected HttpClientRequest doRequest(HttpMethod method, String uri) { - return new LocalHttpClientRequest(method, uri, vertx, wrappedRoutingContexttHandler, exceptionFactory, new LocalHttpServerResponse(vertx)); + return new LocalHttpClientRequest(method, uri, vertx, wrappedRoutingContexttHandler, exceptionFactory, new LocalHttpServerResponse(vertx, exceptionFactory)); } } diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpServerResponse.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpServerResponse.java index d6ad0845..0f1cd1ca 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpServerResponse.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpServerResponse.java @@ -6,6 +6,7 @@ import io.vertx.core.http.impl.headers.HeadersMultiMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.util.StatusCode; /** @@ -16,6 +17,7 @@ public class LocalHttpServerResponse extends BufferBridge implements FastFailHttpServerResponse { private static final Logger logger = LoggerFactory.getLogger(LocalHttpServerResponse.class); + private final GateleenExceptionFactory exceptionFactory; private int statusCode; private String statusMessage; private static final String EMPTY = ""; @@ -118,8 +120,9 @@ public HttpClientResponse exceptionHandler(Handler handler) { }; - public LocalHttpServerResponse(Vertx vertx) { + public LocalHttpServerResponse(Vertx vertx, GateleenExceptionFactory exceptionFactory) { super(vertx); + this.exceptionFactory = exceptionFactory; // Attach most simple possible exception handler to base. setExceptionHandler(thr -> logger.error("Processing of response failed.", thr)); } @@ -214,9 +217,10 @@ public Future write(String chunk, String enc) { public Future write(Buffer data) { // emulate Vertx's HttpServerResponseImpl if (!chunked && !headers.contains(HttpHeaders.CONTENT_LENGTH)) { - IllegalStateException ex = new IllegalStateException("You must set the Content-Length header to be the total size of the message " + IllegalStateException ex = exceptionFactory.newIllegalStateException("" + + "You must set the Content-Length header to be the total size of the message " + "body BEFORE sending any data if you are not using HTTP chunked encoding."); - logger.error("non-proper HttpServerResponse occured", ex); + logger.debug("non-proper HttpServerResponse occurred", ex); throw ex; } ensureBound(); diff --git a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java index c05d9d3e..b9c0c0c1 100644 --- a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java +++ b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java @@ -217,7 +217,7 @@ private void setHttpClientRespondStatusCode(StatusCode statusCode) { String url = (String) invocation.getArguments()[1]; LocalHttpClientRequest request = new LocalHttpClientRequest(httpMethod, url, vertx, event -> { - }, exceptionFactory, new LocalHttpServerResponse(vertx)) { + }, exceptionFactory, new LocalHttpServerResponse(vertx, exceptionFactory)) { @Override public HttpClientRequest response(Handler> handler) { FastFaiHttpClientResponse response = new FastFaiHttpClientResponse() {