Search in sources :

Example 1 with PredicateValidatorDefinition

use of org.apache.camel.model.validator.PredicateValidatorDefinition in project camel by apache.

the class ValidatorListCommandTest method doTest.

private String doTest(boolean verbose) throws Exception {
    CamelContext context = new DefaultCamelContext();
    EndpointValidatorDefinition evd = new EndpointValidatorDefinition();
    evd.setType("xml:foo");
    evd.setUri("direct:validator");
    context.getValidators().add(evd);
    PredicateValidatorDefinition pvd = new PredicateValidatorDefinition();
    pvd.setType(this.getClass());
    pvd.setExpression(new ExpressionDefinition(ExpressionBuilder.bodyExpression()));
    context.getValidators().add(pvd);
    CustomValidatorDefinition cvd = new CustomValidatorDefinition();
    cvd.setType("custom");
    cvd.setClassName(MyValidator.class.getName());
    context.getValidators().add(cvd);
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();
    CamelController controller = new DummyCamelController(context);
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    ValidatorListCommand command = new ValidatorListCommand(null, false, verbose, false);
    command.execute(controller, ps, null);
    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);
    context.stop();
    return out;
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PrintStream(java.io.PrintStream) ExplicitCamelContextNameStrategy(org.apache.camel.impl.ExplicitCamelContextNameStrategy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) PredicateValidatorDefinition(org.apache.camel.model.validator.PredicateValidatorDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) EndpointValidatorDefinition(org.apache.camel.model.validator.EndpointValidatorDefinition) CustomValidatorDefinition(org.apache.camel.model.validator.CustomValidatorDefinition) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 2 with PredicateValidatorDefinition

use of org.apache.camel.model.validator.PredicateValidatorDefinition in project camel by apache.

the class ValidatorBuilder method configure.

/**
     * Configure a Validator according to the configurations built on this builder
     * and register it into given {@code CamelContext}.
     * 
     * @param camelContext {@code CamelContext}
     */
public void configure(CamelContext camelContext) {
    ValidatorDefinition validator;
    if (uri != null) {
        EndpointValidatorDefinition etd = new EndpointValidatorDefinition();
        etd.setUri(uri);
        validator = etd;
    } else if (expression != null) {
        PredicateValidatorDefinition dtd = new PredicateValidatorDefinition();
        dtd.setExpression(expression);
        validator = dtd;
    } else if (clazz != null) {
        CustomValidatorDefinition ctd = new CustomValidatorDefinition();
        ctd.setClassName(clazz.getName());
        validator = ctd;
    } else if (beanRef != null) {
        CustomValidatorDefinition ctd = new CustomValidatorDefinition();
        ctd.setRef(beanRef);
        validator = ctd;
    } else {
        throw new IllegalArgumentException("No Validator type was specified");
    }
    validator.setType(type);
    camelContext.getValidators().add(validator);
}
Also used : PredicateValidatorDefinition(org.apache.camel.model.validator.PredicateValidatorDefinition) EndpointValidatorDefinition(org.apache.camel.model.validator.EndpointValidatorDefinition) CustomValidatorDefinition(org.apache.camel.model.validator.CustomValidatorDefinition) EndpointValidatorDefinition(org.apache.camel.model.validator.EndpointValidatorDefinition) PredicateValidatorDefinition(org.apache.camel.model.validator.PredicateValidatorDefinition) CustomValidatorDefinition(org.apache.camel.model.validator.CustomValidatorDefinition) ValidatorDefinition(org.apache.camel.model.validator.ValidatorDefinition)

Aggregations

CustomValidatorDefinition (org.apache.camel.model.validator.CustomValidatorDefinition)2 EndpointValidatorDefinition (org.apache.camel.model.validator.EndpointValidatorDefinition)2 PredicateValidatorDefinition (org.apache.camel.model.validator.PredicateValidatorDefinition)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 CamelContext (org.apache.camel.CamelContext)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ExplicitCamelContextNameStrategy (org.apache.camel.impl.ExplicitCamelContextNameStrategy)1 ExpressionDefinition (org.apache.camel.model.language.ExpressionDefinition)1 ValidatorDefinition (org.apache.camel.model.validator.ValidatorDefinition)1