Search in sources :

Example 1 with ExpressionIllegalSyntaxException

use of org.apache.camel.ExpressionIllegalSyntaxException in project camel by apache.

the class BeanLanguageInvalidOGNLTest method testBeanLanguageInvalidOGNL.

public void testBeanLanguageInvalidOGNL() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").transform().method(MyReallyCoolBean.class, "getOther[xx");
        }
    });
    try {
        context.start();
        fail("Should have thrown exception");
    } catch (FailedToCreateRouteException e) {
        RuntimeCamelException rce = assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
        MethodNotFoundException mnfe = assertIsInstanceOf(MethodNotFoundException.class, rce.getCause());
        assertEquals("getOther[xx", mnfe.getMethodName());
        ExpressionIllegalSyntaxException cause = assertIsInstanceOf(ExpressionIllegalSyntaxException.class, mnfe.getCause());
        assertEquals("Illegal syntax: getOther[xx", cause.getMessage());
        assertEquals("getOther[xx", cause.getExpression());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) ExpressionIllegalSyntaxException(org.apache.camel.ExpressionIllegalSyntaxException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MethodNotFoundException(org.apache.camel.component.bean.MethodNotFoundException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ExpressionIllegalSyntaxException(org.apache.camel.ExpressionIllegalSyntaxException) MethodNotFoundException(org.apache.camel.component.bean.MethodNotFoundException)

Example 2 with ExpressionIllegalSyntaxException

use of org.apache.camel.ExpressionIllegalSyntaxException in project camel by apache.

the class JsonPathExpression method init.

public void init() {
    String exp = expression;
    if (predicate && isAllowEasyPredicate()) {
        EasyPredicateParser parser = new EasyPredicateParser();
        exp = parser.parse(expression);
        if (!exp.equals(expression)) {
            LOG.debug("EasyPredicateParser parsed {} -> {}", expression, exp);
        }
    }
    LOG.debug("Initializing {} using: {}", predicate ? "predicate" : "expression", exp);
    try {
        engine = new JsonPathEngine(exp, suppressExceptions, allowSimple, options);
    } catch (Exception e) {
        throw new ExpressionIllegalSyntaxException(exp, e);
    }
}
Also used : ExpressionIllegalSyntaxException(org.apache.camel.ExpressionIllegalSyntaxException) EasyPredicateParser(org.apache.camel.jsonpath.easypredicate.EasyPredicateParser) ExpressionEvaluationException(org.apache.camel.ExpressionEvaluationException) ExpressionIllegalSyntaxException(org.apache.camel.ExpressionIllegalSyntaxException)

Example 3 with ExpressionIllegalSyntaxException

use of org.apache.camel.ExpressionIllegalSyntaxException in project camel by apache.

the class LanguageSupport method loadResource.

/**
     * Loads the resource if the given expression is referring to an external resource by using
     * the syntax <tt>resource:scheme:uri<tt>.
     * If the expression is not referring to a resource, then its returned as is.
     * <p/>
     * For example <tt>resource:classpath:mygroovy.groovy</tt> to refer to a groovy script on the classpath.
     *
     * @param expression the expression
     * @return the expression
     * @throws ExpressionIllegalSyntaxException is thrown if error loading the resource
     */
protected String loadResource(String expression) throws ExpressionIllegalSyntaxException {
    if (camelContext != null && expression.startsWith(RESOURCE)) {
        String uri = expression.substring(RESOURCE.length());
        InputStream is = null;
        try {
            is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, uri);
            expression = camelContext.getTypeConverter().mandatoryConvertTo(String.class, is);
        } catch (Exception e) {
            throw new ExpressionIllegalSyntaxException(expression, e);
        } finally {
            IOHelper.close(is);
        }
    }
    return expression;
}
Also used : InputStream(java.io.InputStream) ExpressionIllegalSyntaxException(org.apache.camel.ExpressionIllegalSyntaxException) ExpressionIllegalSyntaxException(org.apache.camel.ExpressionIllegalSyntaxException)

Aggregations

ExpressionIllegalSyntaxException (org.apache.camel.ExpressionIllegalSyntaxException)3 InputStream (java.io.InputStream)1 ExpressionEvaluationException (org.apache.camel.ExpressionEvaluationException)1 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 MethodNotFoundException (org.apache.camel.component.bean.MethodNotFoundException)1 EasyPredicateParser (org.apache.camel.jsonpath.easypredicate.EasyPredicateParser)1