Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more detailed exceptions in VertxAbstractHandler #4483

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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