本文整理匯總了Java中io.vertx.core.http.HttpServerRequest.exceptionHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServerRequest.exceptionHandler方法的具體用法?Java HttpServerRequest.exceptionHandler怎麽用?Java HttpServerRequest.exceptionHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.http.HttpServerRequest
的用法示例。
在下文中一共展示了HttpServerRequest.exceptionHandler方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: proxy
import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
@Override
public Future<Buffer> proxy(RoutingContext ctx, Record record, Buffer processedBuffer) {
// Create Proxy Future
Future<Buffer> future = Future.future();
final Buffer futureBuffer = Buffer.buffer();
// Get current request
HttpServerRequest httpSrvReq = ctx.request();
HttpServerResponse httpSrvRes = ctx.response();
String uri = extractRequestUri(httpSrvReq, record);
// TODO get with configurations from config()
HttpClient httpClient = discovery.getReference(record).get();
// Init HttpClient request
HttpClientRequest httpClientReq = httpClient.request(httpSrvReq.method(), uri, httpClientRes -> {
httpSrvRes.setChunked(true);
httpSrvRes.setStatusCode(httpClientRes.statusCode());
httpSrvRes.headers().setAll(httpClientRes.headers());
httpClientRes.handler(buffer -> {
futureBuffer.appendBuffer(buffer.copy());
httpSrvRes.write(buffer);
});
httpClientRes.exceptionHandler(future::fail);
httpClientRes.endHandler((v) -> {
httpSrvRes.end();
future.complete(futureBuffer);
});
});
// Handle and proxy the request
httpClientReq.headers().setAll(httpSrvReq.headers());
// Handle request exceptions
httpSrvReq.exceptionHandler(future::fail);
// Set Request chunked
httpClientReq.setChunked(true);
// Handle client excpetions
httpClientReq.exceptionHandler(future::fail);
// Call microservice
httpClientReq.write(processedBuffer).end();
return future;
}