Package javax.ws.rs

Examples of javax.ws.rs.WebApplicationException


        CreateRequest cr;
        try {
            cr = objectMapper.readValue(body, CreateRequest.class);
        } catch(IOException e) {
            LOG.error("Error while parsing JSON", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        // Create dashboard.
        Map<String, Object> dashboardData = Maps.newHashMap();
        dashboardData.put("title", cr.title);
        dashboardData.put("description", cr.description);
        dashboardData.put("creator_user_id", getCurrentUser().getName());
        dashboardData.put("created_at", Tools.iso8601());

        Dashboard dashboard = new DashboardImpl(dashboardData);
        String id;
        try {
            id = dashboardService.save(dashboard);
        } catch (ValidationException e) {
            LOG.error("Validation error.", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        dashboardRegistry.add(dashboard);

        Map<String, Object> result = Maps.newHashMap();
View Full Code Here


        try {
            Dashboard dashboard = dashboardService.load(dashboardId);
            return json(dashboard.asMap());
        } catch (org.graylog2.database.NotFoundException e) {
            throw new WebApplicationException(404);
        }
    }
View Full Code Here

            String msg = "Deleted dashboard <" + dashboard.getId() + ">. Reason: REST request.";
            LOG.info(msg);
            activityWriter.write(new Activity(msg, DashboardsResource.class));
        } catch (org.graylog2.database.NotFoundException e) {
            throw new WebApplicationException(404);
        }

        return Response.status(Response.Status.fromStatusCode(204)).build();
    }
View Full Code Here

            UpdateRequest cr;
            try {
                cr = objectMapper.readValue(body, UpdateRequest.class);
            } catch(IOException e) {
                LOG.error("Error while parsing JSON", e);
                throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
            }

            Dashboard dashboard = dashboardService.load(dashboardId);

            if(cr.title != null) {
                dashboard.setTitle(cr.title);
            }

            if (cr.description != null) {
                dashboard.setDescription(cr.description);
            }

            // Validations are happening here.
            dashboardService.save(dashboard);
        } catch (org.graylog2.database.NotFoundException e) {
            throw new WebApplicationException(404);
        } catch (ValidationException e) {
            LOG.error("Validation error.", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        return Response.status(Response.Status.OK).build();
    }
View Full Code Here

            UpdateWidgetPositionsRequest uwpr;
            try {
                uwpr = objectMapper.readValue(body, UpdateWidgetPositionsRequest.class);
            } catch(IOException e) {
                LOG.error("Error while parsing JSON", e);
                throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
            }

            Dashboard dashboard = dashboardService.load(dashboardId);
            dashboardService.updateWidgetPositions(dashboard, uwpr.positions);
        } catch (org.graylog2.database.NotFoundException e) {
            throw new WebApplicationException(404);
        } catch (ValidationException e) {
            LOG.error("Validation error.", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        return Response.status(Response.Status.OK).build();
    }
View Full Code Here

        AddWidgetRequest awr;
        try {
            awr = objectMapper.readValue(body, AddWidgetRequest.class);
        } catch(IOException e) {
            LOG.error("Error while parsing JSON", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        // Bind to streams for reader users and check stream permission.
        if (awr.config.containsKey("stream_id")) {
            checkPermission(RestPermissions.STREAMS_READ, (String) awr.config.get("stream_id"));
        } else {
            checkPermission(RestPermissions.SEARCHES_ABSOLUTE);
            checkPermission(RestPermissions.SEARCHES_RELATIVE);
            checkPermission(RestPermissions.SEARCHES_KEYWORD);
        }

        DashboardWidget widget;
        try {
            widget = DashboardWidget.fromRequest(metricRegistry, searches, awr, getCurrentUser().getName());

            Dashboard dashboard = dashboardRegistry.get(dashboardId);

            if (dashboard == null) {
                LOG.error("Dashboard [{}] not found.", dashboardId);
                throw new WebApplicationException(404);
            }

            dashboardService.addWidget(dashboard, widget);
        } catch (ValidationException e1) {
            LOG.error("Validation error.", e1);
            throw new WebApplicationException(e1, Response.Status.BAD_REQUEST);
        } catch (DashboardWidget.NoSuchWidgetTypeException e2) {
            LOG.error("No such widget type.", e2);
            throw new WebApplicationException(e2, Response.Status.BAD_REQUEST);
        } catch (InvalidRangeParametersException e3) {
            LOG.error("Invalid timerange parameters provided.", e3);
            throw new WebApplicationException(e3, Response.Status.BAD_REQUEST);
        } catch (InvalidWidgetConfigurationException e4) {
            LOG.error("Invalid widget configuration.", e4);
            throw new WebApplicationException(e4, Response.Status.BAD_REQUEST);
        }

        Map<String, Object> result = Maps.newHashMap();
        result.put("widget_id", widget.getId());
View Full Code Here

        restrictToMaster();
        checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);

        if (dashboardId == null || dashboardId.isEmpty()) {
            LOG.error("Missing dashboard ID. Returning HTTP 400.");
            throw new WebApplicationException(400);
        }

        if (widgetId == null || widgetId.isEmpty()) {
            LOG.error("Missing widget ID. Returning HTTP 400.");
            throw new WebApplicationException(400);
        }

        final Dashboard dashboard = dashboardRegistry.get(dashboardId);

        if (dashboard == null) {
            LOG.error("Dashboard not found.");
            throw new WebApplicationException(404);
        }

        final DashboardWidget widget = dashboard.getWidget(widgetId);

        dashboardService.removeWidget(dashboard, widget);
View Full Code Here

        Dashboard dashboard = dashboardRegistry.get(dashboardId);

        if (dashboard == null) {
            LOG.error("Dashboard not found.");
            throw new WebApplicationException(404);
        }

        DashboardWidget widget = dashboard.getWidget(widgetId);

        if (widget == null) {
            LOG.error("Widget not found.");
            throw new WebApplicationException(404);
        }

        try {
            return Response.status(Response.Status.OK).entity(json(widget.getComputationResult().asMap())).build();
        } catch (ExecutionException e) {
View Full Code Here

        UpdateWidgetRequest uwr;
        try {
            uwr = objectMapper.readValue(body, UpdateWidgetRequest.class);
        } catch(IOException e) {
            LOG.error("Error while parsing JSON", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        if (dashboardId == null || dashboardId.isEmpty()) {
            LOG.error("Missing dashboard ID. Returning HTTP 400.");
            throw new WebApplicationException(400);
        }

        if (widgetId == null || widgetId.isEmpty()) {
            LOG.error("Missing widget ID. Returning HTTP 400.");
            throw new WebApplicationException(400);
        }

        try {
            Dashboard dashboard = dashboardRegistry.get(dashboardId);

            if (dashboard == null) {
                LOG.error("Dashboard not found.");
                throw new WebApplicationException(404);
            }

            DashboardWidget widget = dashboard.getWidget(widgetId);

            if (widget == null) {
                LOG.error("Widget not found.");
                throw new WebApplicationException(404);
            }

            dashboardService.updateWidgetDescription(dashboard, widget, uwr.description);
        } catch (ValidationException e) {
            LOG.error("Validation error.", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        LOG.info("Updated description of widget <" + widgetId + "> on dashboard <" + dashboardId + ">. Reason: REST request.");
        return Response.status(Response.Status.OK).build();
    }
View Full Code Here

        UpdateWidgetRequest uwr;
        try {
            uwr = objectMapper.readValue(body, UpdateWidgetRequest.class);
        } catch(IOException e) {
            LOG.error("Error while parsing JSON", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        if (dashboardId == null || dashboardId.isEmpty()) {
            LOG.error("Missing dashboard ID. Returning HTTP 400.");
            throw new WebApplicationException(400);
        }

        if (widgetId == null || widgetId.isEmpty()) {
            LOG.error("Missing widget ID. Returning HTTP 400.");
            throw new WebApplicationException(400);
        }

        try {
            Dashboard dashboard = dashboardRegistry.get(dashboardId);

            if (dashboard == null) {
                LOG.error("Dashboard not found.");
                throw new WebApplicationException(404);
            }

            DashboardWidget widget = dashboard.getWidget(widgetId);

            if (widget == null) {
                LOG.error("Widget not found.");
                throw new WebApplicationException(404);
            }

            dashboardService.updateWidgetCacheTime(dashboard, widget, uwr.cacheTime);
        } catch (ValidationException e) {
            LOG.error("Validation error.", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        LOG.info("Updated cache time of widget <" + widgetId + "> on dashboard <" + dashboardId + "> to " +
                "[" + uwr.cacheTime + "]. Reason: REST request.");
        return Response.status(Response.Status.OK).build();
View Full Code Here

TOP

Related Classes of javax.ws.rs.WebApplicationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.