Search in sources :

Example 1 with ErrorHttpService

use of org.apache.bookkeeper.http.service.ErrorHttpService in project bookkeeper by apache.

the class TwitterAbstractHandler method processRequest.

/**
 * Process the request using the given httpEndpointService.
 */
Future<Response> processRequest(HttpEndpointService httpEndpointService, Request request) {
    HttpServiceRequest httpServiceRequest = new HttpServiceRequest().setMethod(convertMethod(request)).setParams(convertParams(request)).setBody(request.contentString());
    HttpServiceResponse httpServiceResponse = null;
    try {
        httpServiceResponse = httpEndpointService.handle(httpServiceRequest);
    } catch (Exception e) {
        httpServiceResponse = new ErrorHttpService().handle(httpServiceRequest);
    }
    Response response = Response.apply();
    response.setContentString(httpServiceResponse.getBody());
    response.statusCode(httpServiceResponse.getStatusCode());
    return Future.value(response);
}
Also used : Response(com.twitter.finagle.http.Response) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) ErrorHttpService(org.apache.bookkeeper.http.service.ErrorHttpService) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse)

Example 2 with ErrorHttpService

use of org.apache.bookkeeper.http.service.ErrorHttpService in project bookkeeper by apache.

the class VertxAbstractHandler method processRequest.

/**
 * Process the request using the given httpEndpointService.
 */
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.getBodyAsString());
    HttpServiceResponse response = null;
    try {
        response = httpEndpointService.handle(request);
    } catch (Exception e) {
        response = new ErrorHttpService().handle(request);
    }
    httpResponse.setStatusCode(response.getStatusCode());
    httpResponse.end(response.getBody());
}
Also used : ErrorHttpService(org.apache.bookkeeper.http.service.ErrorHttpService) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpServerResponse(io.vertx.core.http.HttpServerResponse) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse)

Aggregations

ErrorHttpService (org.apache.bookkeeper.http.service.ErrorHttpService)2 HttpServiceRequest (org.apache.bookkeeper.http.service.HttpServiceRequest)2 HttpServiceResponse (org.apache.bookkeeper.http.service.HttpServiceResponse)2 Response (com.twitter.finagle.http.Response)1 HttpServerRequest (io.vertx.core.http.HttpServerRequest)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1