Example usage for javax.servlet.http HttpServletResponse SC_NO_CONTENT

List of usage examples for javax.servlet.http HttpServletResponse SC_NO_CONTENT

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_NO_CONTENT.

Prototype

int SC_NO_CONTENT

To view the source code for javax.servlet.http HttpServletResponse SC_NO_CONTENT.

Click Source Link

Document

Status code (204) indicating that the request succeeded but that there was no new information to return.

Usage

From source file:org.gss_project.gss.server.rest.TrashHandler.java

/**
 * Empties the trash can from any currently stored resource,
 * making all trashed files and folders permanently deleted.
 *
  * @param req The HTTP request we are processing
  * @param resp The HTTP response we are processing
 * @throws IOException//from w w w .  ja v a2s. co m
  * @throws IOException if an input/output error occurs
 */
public void emptyTrash(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String path = getInnerPath(req, PATH_TRASH);
    if (path.equals(""))
        path = "/";

    if (!path.equals("/")) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    try {
        User user = getUser(req);
        final User owner = getOwner(req);
        if (!owner.equals(user))
            throw new InsufficientPermissionsException("User " + user.getUsername()
                    + " does not have permission to empty the trash can owned by " + owner.getUsername());
        if (logger.isDebugEnabled())
            logger.debug("Emptying trash for user " + owner.getUsername());
        new TransactionHelper<Void>().tryExecute(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                getService().emptyTrash(owner.getId());
                return null;
            }
        });
        resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } catch (RpcException e) {
        logger.error("", e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (ObjectNotFoundException e) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
    } catch (InsufficientPermissionsException e) {
        resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, e.getMessage());
    } catch (Exception e) {
        logger.error("", e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.eclipse.dirigible.runtime.registry.RepositoryServlet.java

@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String repositoryPath = null;
    final OutputStream out = response.getOutputStream();
    try {/*from   w w  w.j av  a 2  s  . c om*/
        repositoryPath = extractRepositoryPath(request);
        IEntity entity = getEntity(repositoryPath, request);
        if (entity != null) {
            getRepository(request).removeResource(repositoryPath);
        }
    } catch (IllegalArgumentException ex) {
        logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage(), ex);
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
    } catch (MissingResourceException ex) {
        logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage(), ex);
        response.sendError(HttpServletResponse.SC_NO_CONTENT, ex.getMessage());
    } finally {
        out.flush();
        out.close();
    }
}

From source file:org.ednovo.gooru.controllers.v2.api.CommentRestV2Controller.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_COMMENT_DELETE })
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void deleteComment(@PathVariable(value = ID) final String commentUid,
        @RequestParam(value = SOFT_DELETE, required = false, defaultValue = TRUE) final Boolean softdelete,
        final HttpServletRequest request, final HttpServletResponse response) {
    final User user = (User) request.getAttribute(Constants.USER);
    this.getCommentService().deleteComment(commentUid, user, softdelete);
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

From source file:org.wiredwidgets.cow.server.web.TasksController.java

/**
 * Mark a task as complete The choice of DELETE here is based on the fact
 * that this action causes the resource (i.e. task) to be removed from its
 * location at the specified URL. Once completed, the task will then appear
 * under the /tasks/history URI. Response: http 204 if success, 404 if the
 * task was not found (i.e. an invalid task ID or a task that was already
 * completed)//from ww  w. j ava  2s .  c om
 *
 * @param id the task ID
 * @param outcome the outgoing transition for the completed task. Required
 * if the task has more than one possible outcome.
 * @param variables variable assignments for the completed task, in
 * name:value format. More than one instance of this parameter can be
 * provided (e.g. ?variable=name1:value1&variable=name2:value2 etc)
 * @param response
 */
@RequestMapping(value = "/active/{id}", method = RequestMethod.DELETE)
@ResponseBody
public void completeTask(@PathVariable("id") String id,
        @RequestParam(value = "outcome", required = false) String outcome,
        @RequestParam(value = "var", required = false) String variables, HttpServletResponse response,
        HttpServletRequest request) {
    // verify existence

    Task task = taskService.getTask(Long.valueOf(id));

    if (task == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND); // 404
    } else {
        Map<String, Object> varMap = new HashMap<String, Object>();
        if (variables != null) {
            // Note: allowing Spring to create the array has some undesired behaviors in some cases.  For example
            // if the query string contains a comma, Spring treats it as multi-valued.
            // Since we don't want that, we instead use the underlying request object to get the array.
            String[] vars = request.getParameterValues("var");
            for (String variable : vars) {
                // variable is a string in the format name:value
                // Only split on the first ":" found; the value section may contain additional ":" tokens.
                String[] split = variable.split(":", 2);
                varMap.put(split[0], split[1]);
            }
        }
        //testHumanVars.completeTask(Long.valueOf(id), task.getAssignee(), varMap);
        log.debug("Completing task: id=" + id + " outcome=" + outcome);
        log.debug("Vars: " + varMap);

        taskService.completeTask(Long.valueOf(id), task.getAssignee(), outcome, varMap);

        response.setStatus(HttpServletResponse.SC_NO_CONTENT); // 204

        //Task t = taskService.getTask(id);
        //amqpNotifier.amqpTaskPublish(t, "process", "TaskCompleted", id);
    }
}

From source file:org.opencastproject.episode.endpoint.AbstractEpisodeServiceRestEndpoint.java

@POST
@Path("add")
@RestQuery(name = "add", description = "Adds a mediapackage to the episode service.", restParameters = {
        @RestParameter(name = "mediapackage", isRequired = true, type = RestParameter.Type.TEXT, defaultValue = "${this.sampleMediaPackage}", description = "The media package to add to the search index.") }, reponses = {
                @RestResponse(description = "The mediapackage was added, no content to return.", responseCode = HttpServletResponse.SC_NO_CONTENT),
                @RestResponse(description = "There has been an internal error and the mediapackage could not be added", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "No content is returned.")
public Response add(@FormParam("mediapackage") final MediaPackageImpl mediaPackage) {
    return handleException(new Function0<Response>() {
        @Override/*from ww  w  .j  a v a  2s  .c o m*/
        public Response apply() {
            getEpisodeService().add(mediaPackage);
            return noContent();
        }
    });
}

From source file:de.thm.arsnova.controller.SessionController.java

/**
 * Returns a list of my own sessions with only the necessary information like name, keyword, or counters.
 * @param statusOnly The flag that has to be set in order to get this shortened list.
 * @param response/*from   w  ww. jav  a2 s .  co  m*/
 * @return
 */
@RequestMapping(value = "/", method = RequestMethod.GET, params = "statusonly=true")
public List<SessionInfo> getMySessions(
        @RequestParam(value = "visitedonly", defaultValue = "false") final boolean visitedOnly,
        @RequestParam(value = "sortby", defaultValue = "name") final String sortby,
        final HttpServletResponse response) {
    List<SessionInfo> sessions;
    if (!visitedOnly) {
        sessions = sessionService.getMySessionsInfo();
    } else {
        sessions = sessionService.getMyVisitedSessionsInfo();
    }

    if (sessions == null || sessions.isEmpty()) {
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        return null;
    }

    if (sortby != null && sortby.equals("shortname")) {
        Collections.sort(sessions, new SessionInfoShortNameComparator());
    } else {
        Collections.sort(sessions, new SessionInfoNameComparator());
    }
    return sessions;
}

From source file:org.apache.ranger.tagsync.sink.tagadmin.TagAdminRESTSink.java

private ServiceTags uploadServiceTags(ServiceTags serviceTags) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> doUpload()");
    }/*  ww  w  .  ja va2  s  .  c  o  m*/
    WebResource webResource = createWebResource(REST_URL_IMPORT_SERVICETAGS_RESOURCE);

    ClientResponse response = webResource.accept(REST_MIME_TYPE_JSON).type(REST_MIME_TYPE_JSON)
            .put(ClientResponse.class, tagRESTClient.toJson(serviceTags));

    if (response == null || response.getStatus() != HttpServletResponse.SC_NO_CONTENT) {

        RESTResponse resp = RESTResponse.fromClientResponse(response);

        LOG.error("Upload of service-tags failed with message " + resp.getMessage());

        if (response == null || resp.getHttpStatusCode() != HttpServletResponse.SC_BAD_REQUEST) {
            // NOT an application error
            throw new Exception("Upload of service-tags failed with response: " + response);
        }

    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== doUpload()");
    }

    return serviceTags;
}

From source file:org.n52.ses.common.environment.SESMiniServlet.java

private void handleSoapRequest(HttpServletRequest request, HttpServletResponse response, Document soapRequest)
        throws IOException {
    Document soapResponse;//  ww  w.j  a  v  a2  s  .c om
    try {
        soapResponse = this.sesIsolationLayer.handleRequest(soapRequest);
    } catch (RuntimeException e) {
        throw new IOException(e);
    }

    /*
     * is null? return a http response code.
     * change made by Matthes Rieke <m.rieke@uni-muenster.de>
     */
    if (soapResponse == null) {
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } else {
        //TODO check support of ' ; charset=utf-8'
        response.setContentType("application/soap+xml; charset=utf-8");
        printResponse(request, response, XmlUtils.toString(soapResponse));
    }
}

From source file:com.sap.dirigible.runtime.registry.RepositoryServlet.java

@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String repositoryPath = null;
    final OutputStream out = response.getOutputStream();
    try {/*from www. j  a va  2s  .  c o  m*/
        repositoryPath = extractRepositoryPath(request);
        IEntity entity = getEntity(repositoryPath, request);
        if (entity != null) {
            getRepository(request).removeResource(repositoryPath);
        }
    } catch (IllegalArgumentException ex) {
        logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage());
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
    } catch (MissingResourceException ex) {
        logger.error(String.format(REQUEST_PROCESSING_FAILED_S, repositoryPath) + ex.getMessage());
        response.sendError(HttpServletResponse.SC_NO_CONTENT, ex.getMessage());
    } finally {
        out.flush();
        out.close();
    }
}

From source file:org.opencastproject.archive.base.endpoint.ArchiveRestEndpointBase.java

@DELETE
@Path("delete/{id}")
@RestQuery(name = "remove", description = "Remove an episode from the archive.", pathParameters = {
        @RestParameter(name = "id", isRequired = true, type = RestParameter.Type.STRING, description = "The media package ID to remove from the archive.") }, reponses = {
                @RestResponse(description = "The mediapackage was removed, no content to return.", responseCode = HttpServletResponse.SC_NO_CONTENT),
                @RestResponse(description = "There has been an internal error and the mediapackage could not be deleted", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "No content is returned.")
public Response delete(@PathParam("id") final String mediaPackageId) {
    return handleException(new Function0.X<Response>() {
        @Override/*  w w  w. ja va  2  s  .  c  om*/
        public Response xapply() throws NotFoundException {
            if (mediaPackageId != null && getArchive().delete(mediaPackageId))
                return noContent();
            else
                return notFound();
        }
    });
}