本文整理汇总了Java中io.vertx.ext.web.RoutingContext.fail方法的典型用法代码示例。如果您正苦于以下问题:Java RoutingContext.fail方法的具体用法?Java RoutingContext.fail怎么用?Java RoutingContext.fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.RoutingContext
的用法示例。
在下文中一共展示了RoutingContext.fail方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pageUpdateHandler
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void pageUpdateHandler(RoutingContext context) {
String title = context.request().getParam("title");
Handler<AsyncResult<Void>> handler = reply -> {
if (reply.succeeded()) {
context.response().setStatusCode(303);
context.response().putHeader("Location", "/wiki/" + title);
context.response().end();
} else {
context.fail(reply.cause());
}
};
String markdown = context.request().getParam("markdown");
if ("yes".equals(context.request().getParam("newPage"))) {
dbService.createPage(title, markdown, handler);
} else {
dbService.savePage(Integer.valueOf(context.request().getParam("id")), markdown, handler);
}
}
示例2: apiCreatePage
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void apiCreatePage(RoutingContext context) {
if (context.user().principal().getBoolean("canCreate", false)) {
JsonObject page = context.getBodyAsJson();
if (!validateJsonPageDocument(context, page, "name", "markdown")) {
return;
}
dbService.createPage(page.getString("name"), page.getString("markdown"), reply -> {
if (reply.succeeded()) {
context.response().setStatusCode(201);
context.response().putHeader("Content-Type", "application/json");
context.response().end(new JsonObject().put("success", true).encode());
} else {
context.response().setStatusCode(500);
context.response().putHeader("Content-Type", "application/json");
context.response().end(new JsonObject()
.put("success", false)
.put("error", reply.cause().getMessage()).encode());
}
});
} else {
context.fail(401);
}
}
示例3: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(final RoutingContext event) {
if (event.failed()) {
final Throwable ex = event.failure();
if (ex instanceof WebException) {
final WebException error = (WebException) ex;
Answer.reply(event, Envelop.failure(error));
} else {
// Other exception found
event.fail(ex);
}
} else {
// Success, do not throw, continue to request
event.next();
}
}
示例4: writeJsonResponse
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* Returns a handler writing the received {@link AsyncResult} to the routing context and setting the HTTP status to
* the given status.
* @param context the routing context
* @param status the status
* @return the handler
*/
private static <T> Handler<AsyncResult<T>> writeJsonResponse(RoutingContext context, int status) {
return ar -> {
if (ar.failed()) {
if (ar.cause() instanceof NoSuchElementException) {
context.response().setStatusCode(404).end(ar.cause().getMessage());
} else {
context.fail(ar.cause());
}
} else {
context.response().setStatusCode(status)
.putHeader("content-type", "application/json; charset=utf-8")
.end(Json.encodePrettily(ar.result()));
}
};
}
示例5: apiDeletePage
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void apiDeletePage(RoutingContext context) {
if (context.user().principal().getBoolean("canDelete", false)) {
int id = Integer.valueOf(context.request().getParam("id"));
dbService.deletePage(id, reply -> {
handleSimpleDbReply(context, reply);
});
} else {
context.fail(401);
}
}
示例6: shutdownHandler
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* Use to terminate the application using a HTTP Post
* It requires an AdminKey header to work
*/
private void shutdownHandler(final RoutingContext ctx) {
// check for AdminKey header
String adminKey = this.config().getString("AdminKey");
if (adminKey == null || adminKey.equals(ctx.request().getHeader("AdminKey"))) {
// TODO: check the body for the right credentials
this.shutdownExecution(ctx.response());
} else {
ctx.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 401, "Sucker nice try!"));
}
}
示例7: jsonResponseHandler
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
protected <T> Handler<AsyncResult<T>> jsonResponseHandler(final RoutingContext routingContext,
final int statusCode,
final Function<T, String> viewCreationFunction) {
return result -> {
if (result.succeeded()) {
routingContext.response()
.setStatusCode(statusCode)
.putHeader(HttpHeaders.CONTENT_TYPE, JsonMedia.CONTENT_TYPE_UTF_8)
.end(viewCreationFunction.apply(result.result()));
} else {
routingContext.fail(new VerticleException(result.cause()));
}
};
}
示例8: processException
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void processException(final RoutingContext ctx, final Throwable exception) {
if (null != exception) {
if (exception instanceof WebException) {
final WebException error = (WebException) exception;
final HttpStatusCode statusCode = error.getStatus();
final String payload = error.getMessage();
final HttpServerResponse response = ctx.response();
switch (statusCode) {
case MOVE_TEMPORARILY: {
response.putHeader(HttpHeaders.LOCATION, payload)
.setStatusCode(statusCode.code())
.end("Redirecting to " + payload + ".");
}
return;
case UNAUTHORIZED: {
final String header = this.authenticateHeader(ctx);
if (null != header) {
response.putHeader("WWW-Authenticate", header);
}
ctx.fail(this.UNAUTHORIZED);
}
return;
default:
ctx.fail(error);
return;
}
}
}
// Fallback 500
ctx.fail(new _500InternalServerException(this.getClass(),
null == exception ? null : exception.getMessage()));
}
示例9: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext routingContext) {
try {
R requestBody = fetchBody(routingContext, routingContext.request().method());
RequestContext<R> requestContext = DefaultRequestContext.forRequest(requestBody)
.requestPath(routingContext.request().path())
.headers(getHeaders(routingContext))
.parameters(getParameters(routingContext)).build();
ResponseContext<S> responseContext = new VertxResponseContext<>(routingContext);
executeRequest(routingContext, ServerApp.make(), new DefaultExecutionContext<>(requestContext, responseContext));
} catch (Exception e) {
routingContext.fail(e);
}
}
示例10: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void handle(RoutingContext rc) {
@Nullable JsonObject json = rc.getBodyAsJson();
if (json == null || json.getDouble("amount") == null) {
System.out.println("No content or no amount");
rc.fail(400);
return;
}
double amount = json.getDouble("amount");
String target = json.getString("currency");
if (target == null) {
target = "EUR";
}
double rate = getRate(target);
if (rate == -1) {
System.out.println("Unknown currency: " + target);
rc.fail(400);
}
int i = random.nextInt(10);
if (i < 5) {
rc.response().end(new JsonObject()
.put("amount", convert(amount, rate))
.put("currency", target).encode()
);
} else if (i < 8) {
// Failure
rc.fail(500);
}
// Timeout, we don't write the response.
}
示例11: apiUpdatePage
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void apiUpdatePage(RoutingContext context) {
if (context.user().principal().getBoolean("canUpdate", false)) {
int id = Integer.valueOf(context.request().getParam("id"));
JsonObject page = context.getBodyAsJson();
if (!validateJsonPageDocument(context, page, "markdown")) {
return;
}
dbService.savePage(id, page.getString("markdown"), reply -> {
handleSimpleDbReply(context, reply);
});
} else {
context.fail(401);
}
}
示例12: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext context) {
context.fail(valueOf(NOT_FOUND));
}
示例13: unexpectedFailure
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
protected void unexpectedFailure(RoutingContext context, Throwable failure) {
context.fail(this.toTechnicalException(failure));
}