Search in sources :

Example 1 with EvaluationException

use of org.apache.qpid.server.management.plugin.servlet.query.EvaluationException 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");
    }
}
Also used : SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ConfiguredObjectQuery(org.apache.qpid.server.management.plugin.servlet.query.ConfiguredObjectQuery) Model(org.apache.qpid.server.model.Model) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) EvaluationException(org.apache.qpid.server.management.plugin.servlet.query.EvaluationException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 SelectorParsingException (org.apache.qpid.server.filter.SelectorParsingException)1 ConfiguredObjectQuery (org.apache.qpid.server.management.plugin.servlet.query.ConfiguredObjectQuery)1 EvaluationException (org.apache.qpid.server.management.plugin.servlet.query.EvaluationException)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 Model (org.apache.qpid.server.model.Model)1