本文整理匯總了Java中io.vertx.core.http.HttpClientRequest.exceptionHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientRequest.exceptionHandler方法的具體用法?Java HttpClientRequest.exceptionHandler怎麽用?Java HttpClientRequest.exceptionHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.http.HttpClientRequest
的用法示例。
在下文中一共展示了HttpClientRequest.exceptionHandler方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getList
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void getList(String urlBase,
Handler<ExtendedAsyncResult<ModuleDescriptor[]>> fut) {
String url = urlBase;
if (!url.endsWith("/")) {
url += "/";
}
url += "_/proxy/modules";
final Buffer body = Buffer.buffer();
HttpClientRequest req = httpClient.getAbs(url, res -> {
res.handler(body::appendBuffer);
res.endHandler(x -> {
if (res.statusCode() != 200) {
fut.handle(new Failure<>(ErrorType.USER, body.toString()));
} else {
ModuleDescriptor[] ml = Json.decodeValue(body.toString(),
ModuleDescriptor[].class);
fut.handle(new Success<>(ml));
}
});
res.exceptionHandler(x
-> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
});
req.exceptionHandler(x
-> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
req.end();
}
示例2: addFull
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void addFull(String urlBase, ModuleDescriptor ml,
Handler<ExtendedAsyncResult<ModuleDescriptor>> fut) {
String url = urlBase;
if (!url.endsWith("/")) {
url += "/";
}
url += "_/proxy/modules";
Buffer body = Buffer.buffer();
HttpClientRequest req = httpClient.postAbs(url, res -> {
res.handler(body::appendBuffer);
res.endHandler(x -> {
if (res.statusCode() != 201) {
fut.handle(new Failure<>(ErrorType.USER, body.toString()));
} else {
ModuleDescriptor md = Json.decodeValue(body.toString(),
ModuleDescriptor.class);
fut.handle(new Success<>(md));
}
});
res.exceptionHandler(x
-> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
});
req.exceptionHandler(x
-> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
req.end(Json.encodePrettily(ml));
}
示例3: postUrlBody
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void postUrlBody(String url, String doc,
Handler<AsyncResult<Void>> future) {
HttpClientRequest req = client.postAbs(url, res -> {
Buffer body = Buffer.buffer();
res.exceptionHandler(d -> future.handle(Future.failedFuture(d.getCause())));
res.handler(body::appendBuffer);
res.endHandler(d -> {
if (res.statusCode() == 201) {
containerId = body.toJsonObject().getString("Id");
future.handle(Future.succeededFuture());
} else {
String m = "createContainer HTTP error "
+ Integer.toString(res.statusCode()) + "\n"
+ body.toString();
logger.error(m);
future.handle(Future.failedFuture(m));
}
});
});
req.exceptionHandler(d -> future.handle(Future.failedFuture(d.getCause())));
req.putHeader("Content-Type", "application/json");
req.end(doc);
}
示例4: delete
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
/**
* <p>Delete chunks or layers from the GeoRocket data store.</p>
* <p>Either <code>query</code> or <code>layer</code> must be given to
* protect against requests that accidentally delete the whole data store.
* If you want to do so, provide an empty <code>query</code> and the root
* layer <code>/</code>.</p>
* @param query a search query specifying the chunks to delete (or
* <code>null</code> if all chunks and all sub-layers from the given
* <code>layer</code> should be deleted)
* @param layer the absolute path to the layer from which to delete (or
* <code>null</code> if the whole store should be searched for chunks
* to delete)
* @param handler a handler that will be called when the operation has
* finished
*/
public void delete(String query, String layer, Handler<AsyncResult<Void>> handler) {
if ((query == null || query.isEmpty()) && (layer == null || layer.isEmpty())) {
handler.handle(Future.failedFuture("No search query and no layer given. "
+ "Do you really wish to delete the whole data store? If so, "
+ "set the layer to '/'."));
return;
}
String queryPath = prepareQuery(query, layer);
HttpClientRequest request = client.delete(getEndpoint() + queryPath);
request.exceptionHandler(t -> {
handler.handle(Future.failedFuture(t));
});
request.handler(response -> {
if (response.statusCode() != 204) {
fail(response, handler);
} else {
response.endHandler(v -> {
handler.handle(Future.succeededFuture());
});
}
});
configureRequest(request).end();
}
示例5: search
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
/**
* <p>Search the GeoRocket data store and return a {@link ReadStream} of
* merged chunks matching the given criteria.</p>
* <p>If <code>query</code> is <code>null</code> or empty all chunks from
* the given <code>layer</code> (and all sub-layers) will be returned. If
* <code>layer</code> is also <code>null</code> or empty the contents of the
* whole data store will be returned.</p>
* <p>The caller is responsible for handling exceptions through
* {@link ReadStream#exceptionHandler(Handler)}.</p>
* @param query a search query specifying which chunks to return (may be
* <code>null</code>)
* @param layer the name of the layer where to search for chunks recursively
* (may be <code>null</code>)
* @param handler a handler that will receive the {@link ReadStream} from
* which the merged chunks matching the given criteria can be read
*/
public void search(String query, String layer,
Handler<AsyncResult<ReadStream<Buffer>>> handler) {
if ((query == null || query.isEmpty()) && (layer == null || layer.isEmpty())) {
handler.handle(Future.failedFuture("No search query and no layer given. "
+ "Do you really wish to export/query the whole data store? If so, "
+ "set the layer to '/'."));
return;
}
String queryPath = prepareQuery(query, layer);
HttpClientRequest request = client.get(getEndpoint() + queryPath);
request.exceptionHandler(t -> handler.handle(Future.failedFuture(t)));
request.handler(response -> {
if (response.statusCode() == 404) {
fail(response, handler, message -> new NoSuchElementException(ClientAPIException.parse(message).getMessage()));
} else if (response.statusCode() != 200) {
fail(response, handler);
} else {
handler.handle(Future.succeededFuture(response));
}
});
configureRequest(request).end();
}
示例6: health
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void health(DeploymentDescriptor md,
Handler<ExtendedAsyncResult<HealthDescriptor>> fut) {
HealthDescriptor hd = new HealthDescriptor();
String url = md.getUrl();
hd.setInstId(md.getInstId());
hd.setSrvcId(md.getSrvcId());
if (url == null || url.length() == 0) {
hd.setHealthMessage("Unknown");
hd.setHealthStatus(false);
fut.handle(new Success<>(hd));
} else {
HttpClientRequest req = httpClient.getAbs(url, res -> {
res.endHandler(res1 -> {
hd.setHealthMessage("OK");
hd.setHealthStatus(true);
fut.handle(new Success<>(hd));
});
res.exceptionHandler(res1 -> {
hd.setHealthMessage("Fail: " + res1.getMessage());
hd.setHealthStatus(false);
fut.handle(new Success<>(hd));
});
});
req.exceptionHandler(res -> {
hd.setHealthMessage("Fail: " + res.getMessage());
hd.setHealthStatus(false);
fut.handle(new Success<>(hd));
});
req.end();
}
}
示例7: getRemoteUrl
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void getRemoteUrl(Iterator<String> it,
Handler<ExtendedAsyncResult<String>> fut) {
if (!it.hasNext()) {
fut.handle(new Failure<>(ErrorType.NOT_FOUND, "pull: none of remote URLs work"));
} else {
final String baseUrl = it.next();
String url = baseUrl;
if (!url.endsWith("/")) {
url += "/";
}
url += "_/version";
final Buffer body = Buffer.buffer();
HttpClientRequest req = httpClient.getAbs(url, res -> {
res.handler(body::appendBuffer);
res.endHandler(x -> {
if (res.statusCode() != 200) {
logger.info("pull for " + baseUrl + " failed with status "
+ res.statusCode());
fut.handle(new Failure<>(ErrorType.USER,
"pull for " + baseUrl + " returned status " + res.statusCode() + "\n" + body.toString()));
} else {
fut.handle(new Success<>(baseUrl));
}
});
res.exceptionHandler(x
-> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage()))
);
});
req.exceptionHandler(res -> {
logger.info("pull for " + baseUrl + " failed with status "
+ res.getMessage());
getRemoteUrl(it, fut);
});
req.end();
}
}
示例8: postUrl
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void postUrl(String url, String msg,
Handler<AsyncResult<Void>> future) {
HttpClientRequest req = client.postAbs(url, res -> handle204(res, msg, future));
req.exceptionHandler(d -> future.handle(Future.failedFuture(d.getCause())));
req.end();
}
示例9: deleteUrl
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void deleteUrl(String url,
Handler<AsyncResult<Void>> future) {
HttpClientRequest req = client.deleteAbs(url, res -> handle204(res, "deleteContainer", future));
req.exceptionHandler(d -> future.handle(Future.failedFuture(d.getCause())));
req.end();
}
示例10: checkURLs
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void checkURLs(TestContext context, String url, int codeExpected, String accept) {
try {
Async async = context.async();
HttpMethod method = HttpMethod.GET;
HttpClient client = vertx.createHttpClient();
HttpClientRequest request = client.requestAbs(method,
url, new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse httpClientResponse) {
log.info(httpClientResponse.statusCode() + ", " + codeExpected + " status expected: " + url);
context.assertEquals(codeExpected, httpClientResponse.statusCode(), url);
httpClientResponse.bodyHandler( body -> {
log.info(body.toString());
});
async.complete();
}
});
request.exceptionHandler(error -> {
context.fail(url + " - " + error.getMessage());
async.complete();
});
request.headers().add("x-okapi-tenant", "abcdefg");
request.headers().add("Accept", accept);
request.setChunked(true);
request.end();
} catch (Throwable e) {
log.error(e.getMessage(), e);
} finally {
}
}
示例11: getUrl
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void getUrl(String url, Handler<AsyncResult<JsonObject>> future) {
HttpClientRequest req = client.getAbs(url, res -> {
Buffer body = Buffer.buffer();
res.exceptionHandler(d -> {
logger.warn(url + ": " + d.getMessage());
future.handle(Future.failedFuture(url + ": " + d.getMessage()));
});
res.handler(body::appendBuffer);
res.endHandler(d -> {
if (res.statusCode() == 200) {
JsonObject b = body.toJsonObject();
logger.info(b.encodePrettily());
future.handle(Future.succeededFuture(b));
} else {
String m = url + " HTTP error "
+ Integer.toString(res.statusCode()) + "\n"
+ body.toString();
logger.error(m);
future.handle(Future.failedFuture(m));
}
});
});
req.exceptionHandler(d -> {
logger.warn(url + ": " + d.getMessage());
future.handle(Future.failedFuture(url + ": " + d.getMessage()));
});
req.end();
}
示例12: doScrolledStorepointRequest
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
/**
* Performs request against the server and checks for the scroll headers.
* Fails when the headers are not present or an error occured during the request.
*
* @param context Test context
* @param url url
* @param checkHeaders should the test check the headers
* @param checkScrollIdHeaderPresent should the test check the scroll id
* @param handler response handler
*/
private void doScrolledStorepointRequest(TestContext context, String url, Boolean checkHeaders,
Boolean checkScrollIdHeaderPresent, Handler<HttpClientResponse> handler) {
HttpClient client = createHttpClient();
HttpClientRequest request = client.get(url, response -> {
if (checkHeaders) {
checkScrollingResponsePresent(response, context, checkScrollIdHeaderPresent);
}
handler.handle(response);
});
request.exceptionHandler(x -> {
context.fail("Exception during query.");
});
request.end();
}
示例13: proxy
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的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;
}
示例14: request
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
/**
* Make a request to Okapi.
*
* @param method GET or POST or such
* @param path like "/foomodule/something"
* @param data for the request. Most likely a JSON string.
* @param fut callback when done. Most likely a JSON string if all went well,
* or a plain text string in case of errors.
*/
public void request(HttpMethod method, String path, String data,
Handler<ExtendedAsyncResult<String>> fut) {
if (this.okapiUrl == null) {
fut.handle(new Failure<>(INTERNAL, "OkapiClient: No OkapiUrl specified"));
return;
}
String url = this.okapiUrl + path;
String tenant = "-";
if (headers.containsKey(XOkapiHeaders.TENANT)) {
tenant = headers.get(XOkapiHeaders.TENANT);
}
respHeaders = null;
String logReqMsg = reqId + " REQ " + "okapiClient " + tenant + " "
+ method.toString() + " " + url;
if (logInfo) {
logger.info(logReqMsg);
} else {
logger.debug(logReqMsg);
}
HttpClientRequest req = httpClient.requestAbs(method, url, reqres -> {
String logResMsg = reqId
+ " RES " + reqres.statusCode() + " 0us " // TODO - get timing
+ "okapiClient " + url;
if (logInfo) {
logger.info(logResMsg);
} else {
logger.debug(logResMsg);
}
final Buffer buf = Buffer.buffer();
respHeaders = reqres.headers();
reqres.handler(b -> {
logger.debug(reqId + " OkapiClient Buffering response " + b.toString());
buf.appendBuffer(b);
});
reqres.endHandler(e -> {
responsebody = buf.toString();
if (reqres.statusCode() >= 200 && reqres.statusCode() <= 299) {
fut.handle(new Success<>(responsebody));
} else {
if (reqres.statusCode() == 404) {
fut.handle(new Failure<>(NOT_FOUND, "404 " + responsebody + ": " + url));
} else if (reqres.statusCode() == 403) {
fut.handle(new Failure<>(FORBIDDEN, "403 " + responsebody + ": " + url));
} else if (reqres.statusCode() == 400) {
fut.handle(new Failure<>(USER, responsebody));
} else {
fut.handle(new Failure<>(INTERNAL, responsebody));
}
}
});
reqres.exceptionHandler(e -> fut.handle(new Failure<>(INTERNAL, e)));
});
req.exceptionHandler(x -> {
String msg = x.getMessage();
logger.warn(reqId + " OkapiClient exception: " + msg);
fut.handle(new Failure<>(INTERNAL, msg));
});
for (Map.Entry<String, String> entry : headers.entrySet()) {
logger.debug(reqId + " OkapiClient: adding header " + entry.getKey() + ": " + entry.getValue());
}
req.headers().addAll(headers);
req.end(data);
}
示例15: proxyRequestHttpClient
import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
private void proxyRequestHttpClient(Iterator<ModuleInstance> it,
ProxyContext pc, Buffer bcontent, ModuleInstance mi) {
RoutingContext ctx = pc.getCtx();
String url = makeUrl(mi, ctx);
HttpMethod meth = ctx.request().method();
HttpClientRequest cReq = httpClient.requestAbs(meth, url, res -> {
if (res.statusCode() < 200 || res.statusCode() >= 300) {
relayToResponse(ctx.response(), res);
makeTraceHeader(mi, res.statusCode(), pc);
res.handler(data -> {
ctx.response().write(data);
pc.trace("ProxyRequestHttpClient response chunk '"
+ data.toString() + "'");
});
res.endHandler(x -> {
pc.closeTimer();
ctx.response().end();
pc.trace("ProxyRequestHttpClient response end");
});
res.exceptionHandler(e
-> pc.warn("proxyRequestHttpClient: res exception (a)", e));
} else if (it.hasNext()) {
makeTraceHeader(mi, res.statusCode(), pc);
pc.closeTimer();
relayToRequest(res, pc);
proxyR(it, pc, null, bcontent);
} else {
relayToResponse(ctx.response(), res);
makeTraceHeader(mi, res.statusCode(), pc);
res.endHandler(x -> {
pc.closeTimer();
pc.trace("ProxyRequestHttpClient final response buf '"
+ bcontent + "'");
ctx.response().end(bcontent);
});
res.exceptionHandler(e
-> pc.warn("proxyRequestHttpClient: res exception (b)", e));
}
});
cReq.exceptionHandler(e -> {
pc.warn("proxyRequestHttpClient failure: " + url, e);
pc.responseText(500, "proxyRequestHttpClient failure: "
+ mi.getModuleDescriptor().getId() + " " + mi.getUrl() + ": "
+ e + " " + e.getMessage());
});
cReq.headers().setAll(ctx.request().headers());
cReq.headers().remove("Content-Length");
pc.trace("ProxyRequestHttpClient request buf '"
+ bcontent + "'");
cReq.end(bcontent);
log(pc, cReq);
}