This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new f048e7a3b1 Add more detailed exceptions in VertxAbstractHandler (#4483)
f048e7a3b1 is described below
commit f048e7a3b127cfa3a7e9761d589225f078d6712c
Author: Starry <[email protected]>
AuthorDate: Sun Aug 18 21:56:40 2024 +0800
Add more detailed exceptions in VertxAbstractHandler (#4483)
---
.../bookkeeper/http/service/HttpServiceRequest.java | 5 +++++
.../bookkeeper/http/vertx/VertxAbstractHandler.java | 15 ++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git
a/bookkeeper-http/http-server/src/main/java/org/apache/bookkeeper/http/service/HttpServiceRequest.java
b/bookkeeper-http/http-server/src/main/java/org/apache/bookkeeper/http/service/HttpServiceRequest.java
index da2e248634..8d56c091d6 100644
---
a/bookkeeper-http/http-server/src/main/java/org/apache/bookkeeper/http/service/HttpServiceRequest.java
+++
b/bookkeeper-http/http-server/src/main/java/org/apache/bookkeeper/http/service/HttpServiceRequest.java
@@ -67,4 +67,9 @@ public class HttpServiceRequest {
this.params = params;
return this;
}
+
+ @Override
+ public String toString() {
+ return "HttpServiceRequest{" + "body=" + body + ", method=" + method +
", params=" + params + '}';
+ }
}
diff --git
a/bookkeeper-http/vertx-http-server/src/main/java/org/apache/bookkeeper/http/vertx/VertxAbstractHandler.java
b/bookkeeper-http/vertx-http-server/src/main/java/org/apache/bookkeeper/http/vertx/VertxAbstractHandler.java
index 9c595511f6..5dc88948cf 100644
---
a/bookkeeper-http/vertx-http-server/src/main/java/org/apache/bookkeeper/http/vertx/VertxAbstractHandler.java
+++
b/bookkeeper-http/vertx-http-server/src/main/java/org/apache/bookkeeper/http/vertx/VertxAbstractHandler.java
@@ -20,6 +20,7 @@
*/
package org.apache.bookkeeper.http.vertx;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
@@ -30,19 +31,23 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.bookkeeper.http.HttpServer;
-import org.apache.bookkeeper.http.service.ErrorHttpService;
import org.apache.bookkeeper.http.service.HttpEndpointService;
import org.apache.bookkeeper.http.service.HttpServiceRequest;
import org.apache.bookkeeper.http.service.HttpServiceResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Http Handler for Vertx based Http Server.
*/
public abstract class VertxAbstractHandler implements Handler<RoutingContext> {
+ private static final Logger LOG =
LoggerFactory.getLogger(VertxAbstractHandler.class);
+
/**
* Process the request using the given httpEndpointService.
*/
+ @SuppressFBWarnings("DCN_NULLPOINTER_EXCEPTION")
void processRequest(HttpEndpointService httpEndpointService,
RoutingContext context) {
HttpServerRequest httpRequest = context.request();
HttpServerResponse httpResponse = context.response();
@@ -50,11 +55,15 @@ public abstract class VertxAbstractHandler implements
Handler<RoutingContext> {
.setMethod(convertMethod(httpRequest))
.setParams(convertParams(httpRequest))
.setBody(context.body().asString());
- HttpServiceResponse response = null;
+ HttpServiceResponse response;
try {
response = httpEndpointService.handle(request);
+ } catch (NullPointerException | IllegalArgumentException e) {
+ LOG.error("Vertx handler failed to process request {}, cause {}",
request.toString(), e);
+ throw new RuntimeException(e);
} catch (Exception e) {
- response = new ErrorHttpService().handle(request);
+ LOG.error("Exception in vertx handler", e);
+ throw new RuntimeException(e);
}
httpResponse.setStatusCode(response.getStatusCode());
if (response.getContentType() != null) {