当前位置: 首页>>代码示例>>Java>>正文


Java RoutingContext.fail方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:21,代码来源:HttpServerVerticle.java

示例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);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:24,代码来源:HttpServerVerticle.java

示例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();
    }
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:AuthenticateEndurer.java

示例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()));
        }
    };
}
 
开发者ID:cescoffier,项目名称:introduction-to-vert.x,代码行数:23,代码来源:ActionHelper.java

示例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);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:11,代码来源:HttpServerVerticle.java

示例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!"));
	}
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:15,代码来源:ApplicationStarter.java

示例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()));
        }
    };
}
 
开发者ID:yyunikov,项目名称:vertx-gradle-starter,代码行数:15,代码来源:Endpoint.java

示例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()));
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:35,代码来源:AuthPhylum.java

示例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);
    }
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:15,代码来源:AbstractEndpoint.java

示例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.
}
 
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:33,代码来源:CurrencyService.java

示例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);
  }
}
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:15,代码来源:HttpServerVerticle.java

示例12: handle

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext context) {
    context.fail(valueOf(NOT_FOUND));
}
 
开发者ID:valuelogic,项目名称:vertx-web-problem,代码行数:5,代码来源:NotFoundHandlerImpl.java

示例13: unexpectedFailure

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
protected void unexpectedFailure(RoutingContext context, Throwable failure) {
    context.fail(this.toTechnicalException(failure));
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:4,代码来源:VertxAsyncSecurityHandler.java


注:本文中的io.vertx.ext.web.RoutingContext.fail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。