Package javax.ws.rs

Examples of javax.ws.rs.WebApplicationException


            } else {
                return objectMapper.writeValueAsString(x);
            }
        } catch (JsonProcessingException e) {
            LOG.error("Error while generating JSON", e);
            throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
        }
    }
View Full Code Here


    public Response override(@PathParam("status") String status) {
        final LoadBalancerStatus lbStatus;
        try {
            lbStatus = LoadBalancerStatus.valueOf(status.toUpperCase());
        } catch(IllegalArgumentException e) {
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        switch (lbStatus) {
            case DEAD:
                serverStatus.overrideLoadBalancerDead();
View Full Code Here

        Node radio = null;
        try {
            radio = nodeService.byNodeId(radioId);
        } catch (NodeNotFoundException e) {
            LOG.error("Radio <{}> not found.", radioId);
            throw new WebApplicationException(404);
        }

        if (radio == null) {
            LOG.error("Radio <{}> not found.", radioId);
            throw new WebApplicationException(404);
        }

        return json(radioSummary(radio));
    }
View Full Code Here

        Node radio = null;
        try {
            radio = nodeService.byNodeId(radioId);
        } catch (NodeNotFoundException e) {
            LOG.error("Radio <{}> not found.", radioId);
            throw new WebApplicationException(404);
        }

        if (radio == null) {
            LOG.error("Radio <{}> not found.", radioId);
            throw new WebApplicationException(404);
        }

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

        Map<String, Object> inputData = Maps.newHashMap();
        if (rir.inputId != null)
            inputData.put("input_id", rir.inputId);
        else
            inputData.put("input_id", new ObjectId().toHexString());
        inputData.put("title", rir.title);
        inputData.put("type", rir.type);
        inputData.put("creator_user_id", rir.creatorUserId);
        inputData.put("configuration", rir.configuration);
        inputData.put("created_at", Tools.iso8601());
        inputData.put("radio_id", rir.radioId);

        Input mongoInput = new InputImpl(inputData);

        // Write to database.
        String id;
        try {
            id = inputService.save(mongoInput);
        } catch (ValidationException e) {
            LOG.error("Validation error.", e);
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

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

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

        LOG.debug("Ping from graylog2-radio node [{}].", radioId);

        Node node = null;
View Full Code Here

    public Response override(@ApiParam(name = "status") @PathParam("status") String status) {
        final LoadBalancerStatus lbStatus;
        try {
            lbStatus = LoadBalancerStatus.valueOf(status.toUpperCase());
        } catch(IllegalArgumentException e) {
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        switch (lbStatus) {
            case DEAD:
                serverStatus.overrideLoadBalancerDead();
View Full Code Here

    @Path("/types/{inputType}")
    public String info(@PathParam("inputType") String inputType) {
        final Map<String, InputDescription> availableInputs = inputRegistry.getAvailableInputs();
        if (!availableInputs.containsKey(inputType)) {
            LOG.error("Unknown input type {} requested.", inputType);
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        final InputDescription description = availableInputs.get(inputType);
        final Map<String, Object> result = Maps.newHashMap();
        result.put("type", inputType);
        result.put("name", description.getName());
View Full Code Here

  protected ObjectId loadObjectId(String id) {
    try {
      return new ObjectId(id);
    } catch (IllegalArgumentException e) {
          LOG.error("Invalid ObjectID \"" + id + "\". Returning HTTP 400.");
          throw new WebApplicationException(400);
    }
  }
View Full Code Here

    }

    protected void restrictToMaster() {
        if(!serverStatus.hasCapability(ServerStatus.Capability.MASTER)) {
            LOG.warn("Rejected request that is only allowed against master nodes. Returning HTTP 403.");
            throw new WebApplicationException(403);
        }
    }
View Full Code Here

    @GET
    @Path("/{route: .*}")
    public Response asset(@PathParam("route") String route) {
        // Directory traversal should not be possible but just to make sure..
        if (route.contains("..")) {
            throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }

        if (route.trim().equals("")) {
            route = "index.html";
        }

        byte[] read;
        try {
            read = Resources.toByteArray(classLoader.getResource("swagger/" + route));
        } catch (IOException e) {
            throw new WebApplicationException(404);
        }

        return Response.ok()
                .entity(read)
                .header("Content-Type", guessContentType(route))
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.