Skip to content

Commit

Permalink
Add more detailed exceptions in VertxAbstractHandler (#4483)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodePrometheus authored Aug 18, 2024
1 parent a569a49 commit f048e7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public HttpServiceRequest setParams(Map<String, String> params) {
this.params = params;
return this;
}

@Override
public String toString() {
return "HttpServiceRequest{" + "body=" + body + ", method=" + method + ", params=" + params + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,31 +31,39 @@
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();
HttpServiceRequest request = new HttpServiceRequest()
.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) {
Expand Down

0 comments on commit f048e7a

Please sign in to comment.