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);
}
}
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");
}
}
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);
}
Aggregations