當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServerRequest.exceptionHandler方法代碼示例

本文整理匯總了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;
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:48,代碼來源:ProxyServiceImpl.java


注:本文中的io.vertx.core.http.HttpServerRequest.exceptionHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。