use of javax.el.ValueExpression in project jersey by jersey.
the class ELLinkBuilder method getParameterValues.
private static Map<String, Object> getParameterValues(List<String> parameterNames, InjectLinkDescriptor linkField, LinkELContext context, UriInfo uriInfo) {
Map<String, Object> values = new HashMap<>();
for (String name : parameterNames) {
String elExpression = linkField.getBinding(name);
if (elExpression == null) {
String value = uriInfo.getPathParameters().getFirst(name);
if (value == null) {
value = uriInfo.getQueryParameters().getFirst(name);
}
if (value != null) {
values.put(name, value);
continue;
}
elExpression = "${" + ResponseContextResolver.INSTANCE_OBJECT + "." + name + "}";
}
ValueExpression expr = expressionFactory.createValueExpression(context, elExpression, String.class);
Object value = expr.getValue(context);
values.put(name, value != null ? value.toString() : null);
}
return values;
}
use of javax.el.ValueExpression in project jersey by jersey.
the class LinkELContextTest method testEmbeddedExpression.
@Test
public void testEmbeddedExpression() {
System.out.println("Embedded expression");
ExpressionFactory factory = ExpressionFactory.newInstance();
LinkELContext context = new LinkELContext(new EntityBean(), null);
ValueExpression expr = factory.createValueExpression(context, "foo/${entity.id}/bar", String.class);
Object value = expr.getValue(context);
assertEquals("foo/" + ID + "/bar", value);
}
use of javax.el.ValueExpression in project jersey by jersey.
the class LinkELContextTest method testMultipleExpressions.
@Test
public void testMultipleExpressions() {
System.out.println("Multiple expressions");
ExpressionFactory factory = ExpressionFactory.newInstance();
LinkELContext context = new LinkELContext(new EntityBean(), null);
ValueExpression expr = factory.createValueExpression(context, "foo/${entity.id}/bar/${entity.name}", String.class);
Object value = expr.getValue(context);
assertEquals("foo/" + ID + "/bar/" + NAME, value);
}
use of javax.el.ValueExpression in project camel by apache.
the class JuelExpression method evaluate.
public <T> T evaluate(Exchange exchange, Class<T> tClass) {
// Create (if needed) the ExpressionFactory first from the CamelContext using FactoryFinder
ExpressionFactory factory = getExpressionFactory(exchange.getContext());
ELContext context = populateContext(createContext(), exchange);
ValueExpression valueExpression = factory.createValueExpression(context, expression, type);
Object value = valueExpression.getValue(context);
LOG.trace("Value returned {}", value);
return exchange.getContext().getTypeConverter().convertTo(tClass, value);
}
Aggregations