Search in sources :

Example 1 with RuntimeExpressionException

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

the class SqlBuilder method evaluateQuery.

protected List<?> evaluateQuery(Exchange exchange) {
    configureQuery(exchange);
    Message in = exchange.getIn();
    List<?> list = in.getBody(List.class);
    if (list == null) {
        list = Collections.singletonList(in.getBody());
    }
    try {
        return query.execute(list).getResults();
    } catch (QueryExecutionException e) {
        throw new RuntimeExpressionException(e);
    }
}
Also used : QueryExecutionException(org.josql.QueryExecutionException) Message(org.apache.camel.Message) RuntimeExpressionException(org.apache.camel.RuntimeExpressionException)

Example 2 with RuntimeExpressionException

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

the class XPathBuilder method evaluateAs.

/**
     * Evaluates the expression as the given result type
     */
protected Object evaluateAs(Exchange exchange, QName resultQName) {
    // pool a pre compiled expression from pool
    XPathExpression xpathExpression = pool.poll();
    if (xpathExpression == null) {
        LOG.trace("Creating new XPathExpression as none was available from pool");
        // no avail in pool then create one
        try {
            xpathExpression = createXPathExpression();
        } catch (XPathExpressionException e) {
            throw new InvalidXPathExpression(getText(), e);
        } catch (Exception e) {
            throw new RuntimeExpressionException("Cannot create xpath expression", e);
        }
    } else {
        LOG.trace("Acquired XPathExpression from pool");
    }
    try {
        if (logNamespaces && LOG.isInfoEnabled()) {
            logNamespaces(exchange);
        }
        return doInEvaluateAs(xpathExpression, exchange, resultQName);
    } finally {
        // release it back to the pool
        pool.add(xpathExpression);
        LOG.trace("Released XPathExpression back to pool");
    }
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) XPathExpressionException(javax.xml.xpath.XPathExpressionException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException) XPathFunctionException(javax.xml.xpath.XPathFunctionException) RuntimeExpressionException(org.apache.camel.RuntimeExpressionException) RuntimeExpressionException(org.apache.camel.RuntimeExpressionException)

Example 3 with RuntimeExpressionException

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

the class XPathBuilder method createXPathExpression.

/**
     * Creates a new xpath expression as there we no available in the pool.
     * <p/>
     * This implementation must be synchronized to ensure thread safety, as this XPathBuilder instance may not have been
     * started prior to being used.
     */
protected synchronized XPathExpression createXPathExpression() throws XPathExpressionException, XPathFactoryConfigurationException {
    // ensure we are started
    try {
        start();
    } catch (Exception e) {
        throw new RuntimeExpressionException("Error starting XPathBuilder", e);
    }
    // XPathFactory is not thread safe
    XPath xPath = getXPathFactory().newXPath();
    if (!logNamespaces && LOG.isTraceEnabled()) {
        LOG.trace("Creating new XPath expression in pool. Namespaces on XPath expression: {}", getNamespaceContext().toString());
    } else if (logNamespaces && LOG.isInfoEnabled()) {
        LOG.info("Creating new XPath expression in pool. Namespaces on XPath expression: {}", getNamespaceContext().toString());
    }
    xPath.setNamespaceContext(getNamespaceContext());
    xPath.setXPathVariableResolver(getVariableResolver());
    XPathFunctionResolver parentResolver = getFunctionResolver();
    if (parentResolver == null) {
        parentResolver = xPath.getXPathFunctionResolver();
    }
    xPath.setXPathFunctionResolver(createDefaultFunctionResolver(parentResolver));
    return xPath.compile(text);
}
Also used : XPath(javax.xml.xpath.XPath) XPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException) XPathFunctionException(javax.xml.xpath.XPathFunctionException) RuntimeExpressionException(org.apache.camel.RuntimeExpressionException) RuntimeExpressionException(org.apache.camel.RuntimeExpressionException)

Aggregations

RuntimeExpressionException (org.apache.camel.RuntimeExpressionException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 XPathFactoryConfigurationException (javax.xml.xpath.XPathFactoryConfigurationException)2 XPathFunctionException (javax.xml.xpath.XPathFunctionException)2 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)2 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathFunctionResolver (javax.xml.xpath.XPathFunctionResolver)1 Message (org.apache.camel.Message)1 QueryExecutionException (org.josql.QueryExecutionException)1