use of org.apache.qpid.server.filter.SelectorParsingException in project qpid-broker-j by apache.
the class ConfiguredObjectQuery method filterObjects.
private List<ConfiguredObject<?>> filterObjects(final List<ConfiguredObject<?>> objects, final String whereClause) {
List<ConfiguredObject<?>> filteredObjects = new ArrayList<>();
ConfiguredObjectFilterParser parser = new ConfiguredObjectFilterParser();
parser.setConfiguredObjectExpressionFactory(_expressionFactory);
try {
final BooleanExpression<ConfiguredObject> expression = parser.parseWhere(whereClause);
for (ConfiguredObject<?> object : objects) {
try {
if (expression.matches(object)) {
filteredObjects.add(object);
}
} catch (RuntimeException e) {
throw new EvaluationException("Error while evaluating object against where clause", e);
}
}
} catch (ParseException | TokenMgrError e) {
throw new SelectorParsingException("Unable to parse where clause", e);
}
return filteredObjects;
}
use of org.apache.qpid.server.filter.SelectorParsingException in project qpid-broker-j by apache.
the class ConfiguredObjectQuery method parseSelectClause.
private HeadersAndValueExpressions parseSelectClause(final String selectClause) {
final List<String> headers = new ArrayList<>();
final List<Expression> valueExpressions = new ArrayList<>();
if (selectClause != null) {
ConfiguredObjectFilterParser parser = new ConfiguredObjectFilterParser();
parser.setConfiguredObjectExpressionFactory(_expressionFactory);
try {
final List<Map<String, Expression>> expressions = parser.parseSelect(selectClause);
for (Map<String, Expression> expression : expressions) {
final Map.Entry<String, Expression> entry = expression.entrySet().iterator().next();
headers.add(entry.getKey());
valueExpressions.add(entry.getValue());
}
} catch (ParseException | TokenMgrError e) {
throw new SelectorParsingException("Unable to parse select clause", e);
}
} else {
for (String field : STANDARD_FIELDS) {
headers.add(field);
valueExpressions.add(_expressionFactory.createConfiguredObjectExpression(field));
}
}
return new HeadersAndValueExpressions() {
@Override
public List<String> getHeaders() {
return Collections.unmodifiableList(headers);
}
@Override
public List<Expression> getValueExpressions() {
return Collections.unmodifiableList(valueExpressions);
}
@Override
public boolean hasHeader(final String headerName) {
return headers.contains(headerName);
}
@Override
public Expression getValueExpressionForHeader(final String headerName) {
final int i = headers.indexOf(headerName);
if (i < 0) {
throw new IllegalStateException(String.format("No expression found for header '%s'", headerName));
}
return valueExpressions.get(i);
}
};
}
use of org.apache.qpid.server.filter.SelectorParsingException in project qpid-broker-j by apache.
the class QueryServlet method performQuery.
private void performQuery(final HttpServletRequest request, final HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException, ServletException {
String categoryName;
X parent = getParent(request, managedObject);
if (parent != null && ((categoryName = getRequestedCategory(request, managedObject)) != null)) {
Model model = parent.getModel();
Class<? extends ConfiguredObject> category = getSupportedCategory(categoryName, model);
if (category != null) {
List<ConfiguredObject<?>> objects = getAllObjects(parent, category, request);
try {
ConfiguredObjectQuery query = new ConfiguredObjectQuery(objects, request.getParameter("select"), request.getParameter("where"), request.getParameter("orderBy"), request.getParameter("limit"), request.getParameter("offset"));
String attachmentFilename = request.getParameter(CONTENT_DISPOSITION_ATTACHMENT_FILENAME_PARAM);
if (attachmentFilename != null) {
setContentDispositionHeaderIfNecessary(response, attachmentFilename);
}
if ("csv".equalsIgnoreCase(request.getParameter("format"))) {
sendCsvResponse(query, response);
} else {
Map<String, Object> resultsObject = new LinkedHashMap<>();
resultsObject.put("headers", query.getHeaders());
resultsObject.put("results", query.getResults());
resultsObject.put("total", query.getTotalNumberOfRows());
sendJsonResponse(resultsObject, request, response);
}
} catch (SelectorParsingException e) {
sendJsonErrorResponse(request, response, HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
} catch (EvaluationException e) {
sendJsonErrorResponse(request, response, SC_UNPROCESSABLE_ENTITY, e.getMessage());
}
} else {
sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Unknown object type " + categoryName);
}
} else {
sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Invalid path");
}
}
use of org.apache.qpid.server.filter.SelectorParsingException in project qpid-broker-j by apache.
the class SendingLinkEndpoint method prepareConsumerOptionsAndFilters.
private void prepareConsumerOptionsAndFilters(final SendingDestination destination) throws AmqpErrorException {
// TODO QPID-7952: this method might modify the source. this is not good encapsulation. furthermore if it does so then it should inform the link/linkregistry about it!
_destination = destination;
final Source source = getSource();
EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
boolean noLocal = false;
JMSSelectorFilter messageFilter = null;
if (destination instanceof ExchangeSendingDestination) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
} else if (destination instanceof StandardSendingDestination) {
MessageSource messageSource = _destination.getMessageSource();
if (messageSource instanceof Queue && ((Queue<?>) messageSource).getAvailableAttributes().contains("topic")) {
source.setDistributionMode(StdDistMode.COPY);
}
Map<Symbol, Filter> filters = source.getFilter();
Map<Symbol, Filter> actualFilters = new HashMap<>();
if (filters != null) {
for (Map.Entry<Symbol, Filter> entry : filters.entrySet()) {
if (entry.getValue() instanceof NoLocalFilter) {
actualFilters.put(entry.getKey(), entry.getValue());
noLocal = true;
} else if (messageFilter == null && entry.getValue() instanceof org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) {
org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) entry.getValue();
try {
messageFilter = new JMSSelectorFilter(selectorFilter.getValue());
actualFilters.put(entry.getKey(), entry.getValue());
} catch (ParseException | SelectorParsingException | TokenMgrError e) {
Error error = new Error();
error.setCondition(AmqpError.INVALID_FIELD);
error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
throw new AmqpErrorException(error);
}
}
}
}
source.setFilter(actualFilters.isEmpty() ? null : actualFilters);
if (source.getDistributionMode() != StdDistMode.COPY) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
}
} else {
throw new ConnectionScopedRuntimeException("Unknown destination type");
}
if (noLocal) {
options.add(ConsumerOption.NO_LOCAL);
}
FilterManager filters = null;
if (messageFilter != null) {
filters = new FilterManager();
filters.add(messageFilter.getName(), messageFilter);
}
_consumerOptions = options;
_consumerFilters = filters;
}
use of org.apache.qpid.server.filter.SelectorParsingException in project qpid-broker-j by apache.
the class ConfiguredObjectQuery method parseOrderByClause.
private List<OrderByExpression> parseOrderByClause(final String orderByClause, final HeadersAndValueExpressions headersAndValue) {
final List<OrderByExpression> orderByExpressions;
ConfiguredObjectFilterParser parser = new ConfiguredObjectFilterParser();
parser.setConfiguredObjectExpressionFactory(new ConfiguredObjectExpressionFactory() {
@Override
public ConfiguredObjectExpression createConfiguredObjectExpression(final String propertyName) {
if (headersAndValue.hasHeader(propertyName)) {
Expression expression = headersAndValue.getValueExpressionForHeader(propertyName);
return object -> expression.evaluate(object);
} else {
return super.createConfiguredObjectExpression(propertyName);
}
}
});
try {
orderByExpressions = parser.parseOrderBy(orderByClause);
} catch (ParseException | TokenMgrError e) {
throw new SelectorParsingException("Unable to parse orderBy clause", e);
}
return orderByExpressions;
}
Aggregations