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.ednovo.gooru.controllers.v1.api.SubdomainRestController.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_SUBDOMAIN_DELETE })
@RequestMapping(value = RequestMappingUri.ID, method = RequestMethod.DELETE)
public void deleteSubdomain(HttpServletResponse response, HttpServletRequest request,
        @PathVariable(ID) Integer subDomaintId) {
    this.getSubdomainService().deleteSubdomain(subDomaintId);
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

From source file:com.google.api.server.spi.response.ServletResponseResultWriterTest.java

@Test
public void testWriteNull() throws Exception {
    MockHttpServletResponse response = new MockHttpServletResponse();
    ServletResponseResultWriter writer = new ServletResponseResultWriter(response, null);
    writer.write(null);/*from  w  w w . jav a 2  s . c  o  m*/
    assertEquals("", response.getContentAsString());
    assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
}

From source file:se.tillvaxtverket.ttsigvalws.ttwebservice.TTSigValServlet.java

/**
 * Processes requests for both HTTP//from  w  w  w  . j av a  2 s.co m
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    String action = request.getParameter("action");
    Locale respLocale = Locale.getDefault();
    baseModel.refreshTrustStore();
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (isMultipart) {
        processFileUpload(request, response);
        return;
    }

    if (action == null) {
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        response.getWriter().write("");
        return;
    }

    if (action.equals("logout")) {
        response.setContentType("text/html;charset=UTF-8");
        String authType = (request.getAuthType() == null) ? "" : request.getAuthType();
        response.getWriter().write("<logout>" + authType.toLowerCase() + "</logout>");
    }

    if (action.equals("authdata")) {
        response.setContentType("text/xml;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        StringBuilder b = new StringBuilder();
        String authType = request.getAuthType();
        String remoteUser = utf8(request.getRemoteUser());
        if (authType != null && remoteUser != null) {
            b.append("<remoteUser type=\"").append(authType).append("\">");
            b.append(remoteUser).append("</remoteUser>");
            b.append("<authContext>");
            b.append(getAuthContext(request));
            b.append("</authContext>");
            b.append("<userAttributes>");
            b.append(getAuthAttributes(request));
            b.append("</userAttributes>");
        }
        String authResponse = "<authData>" + b.toString() + "</authData>";
        response.getWriter().write(authResponse);
    }

    if (action.equals("policylist")) {
        boolean contentAdded = true;
        if (contentAdded) {
            response.setContentType("text/xml;charset=UTF-8");
            response.setHeader("Cache-Control", "no-cache");
            response.getWriter().write("<policies>" + getPolicyData() + "</policies>");
        } else {
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        }
        return;
    }

    if (action.equals("serverdoclist")) {
        boolean contentAdded = true;
        if (contentAdded) {
            response.setContentType("text/xml;charset=UTF-8");
            response.setHeader("Cache-Control", "no-cache");
            response.getWriter().write("<sigFiles>" + getServerdocs() + "</sigFiles>");
        } else {
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        }
        return;
    }

    if (action.equals("verify")) {
        String verifyResult = verifyServerDocSignature(request);
        if (verifyResult != null) {
            response.setContentType("text/xml;charset=UTF-8");
            response.setHeader("Cache-Control", "no-cache");
            response.getWriter().write(verifyResult);
        } else {
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        }
        return;
    }
    if (action.equals("postverify")) {
        processValidationPost(request, response);
        return;
    }
}

From source file:org.mule.transport.servlet.AbstractReceiverServlet.java

protected void writeEmptyResponse(HttpServletResponse servletResponse) throws IOException {
    servletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
    if (feedback) {
        servletResponse.setStatus(HttpServletResponse.SC_OK);
        servletResponse.getWriter().write("Action was processed successfully. There was no result");
    }/*from  www .  ja  v  a2s  .  co  m*/
}

From source file:org.opencastproject.fileupload.rest.FileUploadRestService.java

@POST
@Produces(MediaType.TEXT_PLAIN)/*from   www.  j  a va2 s .c  o  m*/
@Path("newjob")
@RestQuery(name = "newjob", description = "Creates a new upload job and returns the jobs ID.", restParameters = {
        @RestParameter(description = "The name of the file that will be uploaded", isRequired = false, name = REQUESTFIELD_FILENAME, type = RestParameter.Type.STRING),
        @RestParameter(description = "The size of the file that will be uploaded", isRequired = false, name = REQUESTFIELD_FILESIZE, type = RestParameter.Type.STRING),
        @RestParameter(description = "The size of the chunks that will be uploaded", isRequired = false, name = REQUESTFIELD_CHUNKSIZE, type = RestParameter.Type.STRING),
        @RestParameter(description = "The flavor of this track", isRequired = false, name = REQUESTFIELD_FLAVOR, type = RestParameter.Type.STRING),
        @RestParameter(description = "The mediapackage the file should belong to", isRequired = false, name = REQUESTFIELD_MEDIAPACKAGE, type = RestParameter.Type.TEXT) }, reponses = {
                @RestResponse(description = "job was successfully created", responseCode = HttpServletResponse.SC_OK),
                @RestResponse(description = "upload service gave an error", responseCode = HttpServletResponse.SC_NO_CONTENT) }, returnDescription = "The ID of the newly created upload job")
public Response getNewJob(@FormParam(REQUESTFIELD_FILENAME) String filename,
        @FormParam(REQUESTFIELD_FILESIZE) long filesize, @FormParam(REQUESTFIELD_CHUNKSIZE) int chunksize,
        @FormParam(REQUESTFIELD_MEDIAPACKAGE) String mediapackage,
        @FormParam(REQUESTFIELD_FLAVOR) String flav) {
    try {
        if (filename == null || filename.trim().length() == 0) {
            filename = "john.doe";
        }
        if (filesize < 1) {
            filesize = -1;
        }
        if (chunksize < 1) {
            chunksize = -1;
        }
        MediaPackage mp = null;
        if (mediapackage != null && !mediapackage.equals("")) {
            mp = factory.newMediaPackageBuilder().loadFromXml(mediapackage);
        }

        MediaPackageElementFlavor flavor = null;
        if (flav != null && !flav.equals("")) {
            flavor = new MediaPackageElementFlavor(flav.split("/")[0], flav.split("/")[1]);
        }

        FileUploadJob job = uploadService.createJob(filename, filesize, chunksize, mp, flavor);
        return Response.ok(job.getId()).build();
    } catch (FileUploadException e) {
        log.error(e.getMessage(), e);
        return Response.status(Response.Status.NO_CONTENT).entity(e.getMessage()).build();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return Response.serverError().entity(buildUnexpectedErrorMessage(e)).build();
    }
}

From source file:org.alfresco.web.app.servlet.DownloadRawContentServlet.java

/**
 * Processes the request using the current context i.e. no
 * authentication checks are made, it is presumed they have already
 * been done.//w  ww .j a va 2s.  c om
 * 
 * @param req The HTTP request
 * @param res The HTTP response
 */
private void processRequest(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    String uri = req.getRequestURI();

    String contentUrl = req.getParameter(ARG_CONTENT_URL);
    if (contentUrl == null || contentUrl.length() == 0) {
        throw new IllegalArgumentException(
                "Download URL did not contain parameter '" + ARG_CONTENT_URL + "':" + uri);
    }
    String infoOnlyStr = req.getParameter(ARG_INFO_ONLY);
    boolean infoOnly = (infoOnlyStr == null) ? false : Boolean.parseBoolean(infoOnlyStr);

    ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
    ContentService contentService = serviceRegistry.getContentService();

    // Attempt to get the reader
    ContentReader reader = null;
    try {
        reader = contentService.getRawReader(contentUrl);
        // If the content doesn't exist, generate an error
        if (!reader.exists()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Returning 204 Not Found error...");
            }
            res.sendError(HttpServletResponse.SC_NO_CONTENT);
            return;
        }
    } catch (AccessDeniedException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Returning 403 Forbidden error after exception: ", e);
        }
        res.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    long readerSize = reader.getSize();
    Date readerLastModified = new Date(reader.getLastModified());
    String readerMimetype = reader.getMimetype();
    String readerEncoding = reader.getEncoding();
    Locale readerLocale = reader.getLocale();
    // Set the content info
    res.setHeader("alfresco.dr.size", DefaultTypeConverter.INSTANCE.convert(String.class, readerSize));
    res.setHeader("alfresco.dr.lastModified",
            DefaultTypeConverter.INSTANCE.convert(String.class, readerLastModified));
    res.setHeader("alfresco.dr.mimetype", readerMimetype);
    res.setHeader("alfresco.dr.encoding", readerEncoding);
    res.setHeader("alfresco.dr.locale", DefaultTypeConverter.INSTANCE.convert(String.class, readerLocale));

    // Pass the stream to the response, unless only the content info was requested
    if (infoOnly) {
        // Fill response details
        res.setContentType(DEFAULT_MIMETYPE);
        res.setCharacterEncoding(DEFAULT_ENCODING);
    } else {
        // Fill response details
        res.setContentType(readerMimetype);
        res.setCharacterEncoding(readerEncoding);

        try {
            OutputStream clientOs = res.getOutputStream();
            reader.getContent(clientOs); // Streams closed for us
        } catch (SocketException e1) {
            // Not a problem
            if (logger.isDebugEnabled()) {
                logger.debug("Client aborted stream read:\n" + "   Content URL: " + contentUrl);
            }
        } catch (ContentIOException e2) {
            // Not a problem
            if (logger.isDebugEnabled()) {
                logger.debug("Client aborted stream read:\n" + "   Content URL: " + contentUrl);
            }
        }
    }
}

From source file:org.ednovo.gooru.controllers.v1.api.DomainRestController.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_DOMAIN_DELETE })
@RequestMapping(value = RequestMappingUri.ID, method = RequestMethod.DELETE)
public void deleteDomain(@PathVariable(value = ID) Integer domainId, HttpServletRequest request,
        HttpServletResponse response) {/*from   www  . ja va2s  .  com*/
    getDomainService().deleteDomain(domainId);
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

From source file:com.homesnap.webserver.GroupRestAPITest.java

@Test
public void test9DeleteGroupList() {
    // Test impossible to create grouplist
    JSONObject jo = deleteRequestJSONObject(urn_groups, HttpServletResponse.SC_NO_CONTENT);
    Assert.assertNull(jo);/*from   w ww  .ja v a2s.c  o m*/

    // Test there is no more controllers
    JSONArray controllers = getRequestJSONArray(urn_groups);
    Assert.assertEquals(0, controllers.length());
}

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

@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String repositoryPath = null;
    final OutputStream out = response.getOutputStream();
    try {/*from   ww w.  ja  v a2  s .  co  m*/
        repositoryPath = extractRepositoryPath(request);
        IEntity entity = getEntity(repositoryPath, request);
        if (entity == null) {
            doPost(request, response);
        } else {
            if (entity instanceof IResource) {
                ByteArrayOutputStream buff = new ByteArrayOutputStream();
                IOUtils.copy(request.getInputStream(), buff);
                byte[] data = buff.toByteArray();
                IResource resource = (IResource) entity;
                resource.setContent(data);
            } else {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                        THERE_IS_AN_EXISTING_COLLECTION_AT_THE_SAME_LOCATION);
            }
        }
    } 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.v1.api.SubjectRestController.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_SUBJECT_DELETE })
@RequestMapping(value = RequestMappingUri.ID, method = RequestMethod.DELETE)
public void deleteSubject(HttpServletResponse response, HttpServletRequest request,
        @PathVariable(ID) Integer subjectId) {
    this.getSubjectService().deleteSubject(subjectId);
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}