Search in sources :

Example 1 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class ServiceJet method reply404Error.

/**
 * Service Not Found ( 404 )
 *
 * @param context
 */
private void reply404Error(final RoutingContext context) {
    final HttpServerRequest request = context.request();
    final WebException exception = new _404ServiceNotFoundException(getClass(), request.uri(), request.method());
    Answer.reply(context, Envelop.failure(exception));
}
Also used : io.vertx.up.exception._404ServiceNotFoundException(io.vertx.up.exception._404ServiceNotFoundException) WebException(io.vertx.up.exception.WebException)

Example 2 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class Flower method executeRequest.

static void executeRequest(final RoutingContext context, final Map<String, List<Rule>> rulers, final Depot depot, final Object[] args, final Validator verifier) {
    // Extract major object
    final WebException error = verifyPureArguments(verifier, depot, args);
    if (null == error) {
        // Check if annotated with @Codex
        final KeyPair<Integer, Class<?>> found = Anno.findParameter(depot.getEvent().getAction(), Codex.class);
        if (null == found.getValue()) {
            context.next();
        } else {
            // @Codex validation for different types
            final Class<?> type = found.getValue();
            final Object value = args[found.getKey()];
            verifyCodex(context, rulers, depot, type, value);
        }
    } else {
        // Hibernate validate failure
        replyError(context, error, depot.getEvent());
    }
}
Also used : WebException(io.vertx.up.exception.WebException)

Example 3 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class Flower method verifyCodex.

private static void verifyCodex(final RoutingContext context, final Map<String, List<Rule>> rulers, final Depot depot, final Class<?> type, final Object value) {
    final Rigor rigor = Rigor.get(type);
    if (null == rigor) {
        LOGGER.warn(Info.RIGOR_NOT_FOUND, type);
        context.next();
    } else {
        final WebException error = rigor.verify(rulers, value);
        if (null == error) {
            // Ignore Errors
            context.next();
        } else {
            // Reply Error
            replyError(context, error, depot.getEvent());
        }
    }
}
Also used : WebException(io.vertx.up.exception.WebException) Rigor(io.vertx.up.rs.announce.Rigor)

Example 4 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class BaseRuler method failure.

protected WebException failure(final String field, final Object value, final Rule rule) {
    final String message = rule.getMessage();
    final WebException error = new _400ValidationRuleException(getClass(), field, value, message);
    error.setReadible(message);
    getLogger().info(Info.MSG_FAILURE, error.toJson());
    return error;
}
Also used : WebException(io.vertx.up.exception.WebException) io.vertx.up.exception._400ValidationRuleException(io.vertx.up.exception._400ValidationRuleException)

Example 5 with WebException

use of io.vertx.up.exception.WebException in project vertx-zero by silentbalanceyh.

the class LengthRuler method verify.

@Override
public WebException verify(final String field, final Object value, final Rule rule) {
    WebException error = null;
    // Extract length
    final JsonObject config = rule.getConfig();
    if (config.containsKey("max")) {
        final Ruler ruler = Ruler.get("maxlength");
        error = ruler.verify(field, value, rule);
    }
    if (null == error && config.containsKey("min")) {
        final Ruler ruler = Ruler.get("minlength");
        error = ruler.verify(field, value, rule);
    }
    return error;
}
Also used : WebException(io.vertx.up.exception.WebException) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

WebException (io.vertx.up.exception.WebException)17 JsonObject (io.vertx.core.json.JsonObject)2 Rule (io.vertx.up.atom.Rule)2 Envelop (io.vertx.up.atom.Envelop)1 Event (io.vertx.up.atom.agent.Event)1 io.vertx.up.exception._400ValidationException (io.vertx.up.exception._400ValidationException)1 io.vertx.up.exception._400ValidationRuleException (io.vertx.up.exception._400ValidationRuleException)1 io.vertx.up.exception._404ServiceNotFoundException (io.vertx.up.exception._404ServiceNotFoundException)1 io.vertx.up.exception._405MethodForbiddenException (io.vertx.up.exception._405MethodForbiddenException)1 io.vertx.up.exception._500EntityCastException (io.vertx.up.exception._500EntityCastException)1 io.vertx.up.exception._500InternalServerException (io.vertx.up.exception._500InternalServerException)1 Rigor (io.vertx.up.rs.announce.Rigor)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1