Java Code Examples for com.google.gwt.http.client.Response.SC_NO_CONTENT

The following are Jave code examples for showing how to use SC_NO_CONTENT of the com.google.gwt.http.client.Response class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sigmah   File: FileServlet.java   View Source Code Vote up 6 votes
protected void uploadAvatar(final HttpServletRequest request, final HttpServletResponse response, final ServletExecutionContext context) throws Exception {
	final int contentLength = request.getContentLength();

	if (contentLength == 0) {
		LOG.error("Empty file.");
		throw new StatusServletException(Response.SC_NO_CONTENT);
	}

	if (contentLength > FileUploadUtils.MAX_UPLOAD_FILE_SIZE) {
		LOG.error("File's size is too big to be uploaded (size: {}, maximum : {}).", contentLength, FileUploadUtils.MAX_UPLOAD_FILE_SIZE);
		throw new StatusServletException(Response.SC_REQUEST_ENTITY_TOO_LARGE);
	}

	final String fileName = generateUniqueName();

	// --
	// Writing the file.
	// --

	final MultipartRequest multipartRequest = new MultipartRequest(request);
	processUpload(multipartRequest, response, fileName, false, FileUploadUtils.MAX_AVATAR_SIZE);

	response.setStatus(Response.SC_OK);
	response.setContentType(FileType.TXT.getContentType());
	response.getWriter().write(fileName);
}
 
Example 2
Project: che   File: AsyncRequestCallback.java   View Source Code Vote up 5 votes
private void handleSuccess(Response response) {
  try {
    if (unmarshaller != null) {
      // It's needed for handling a situation when response DTO object is NULL
      if (response.getStatusCode() != Response.SC_NO_CONTENT) {
        unmarshaller.unmarshal(response);
      }
      payload = unmarshaller.getPayload();
    }

    onSuccess(payload);
  } catch (Exception e) {
    onFailure(e);
  }
}
 
Example 3
Project: sigmah   File: FileServlet.java   View Source Code Vote up 4 votes
/**
 * See {@link ServletMethod#UPLOAD_ORGANIZATION_LOGO} for JavaDoc.
 * 
 * @param request
 *          The HTTP request containing the Organization id parameter.
 * @param response
 *          The HTTP response on which the file content is written.
 * @param context
 *          The execution context.
 * @throws java.io.IOException
 *           If an error occured while reading or writing to the socket or if an error occured while storing the
 *           uploaded file.
 * @throws org.sigmah.server.servlet.base.StatusServletException
 *           If the id parameter was not found or not parseable or if the request type is not MULTIPART or if the file
 *           exceeded the maximum allowed size.
 * @throws org.apache.commons.fileupload.FileUploadException
 *           If an error occured while reading the uploaded file.
 * @throws javax.servlet.ServletException
 *           If the given organization could not be found.
 */
protected void uploadOrganizationLogo(final HttpServletRequest request, final HttpServletResponse response, final ServletExecutionContext context)
		throws IOException, StatusServletException, ServletException, FileUploadException {

	// --
	// Retrieving parameters from request.
	// --

	final Integer organizationId = getIntegerParameter(request, RequestParameter.ID, false);

	// --
	// Retrieving Organization entity.
	// --

	final Organization organization = organizationDAO.findById(organizationId);
	if (organization == null) {
		throw new ServletException("Cannot find Organization with id '" + organizationId + "'.");
	}

	final String previousLogoFileName = organization.getLogo();

	// --
	// Verifying content length.
	// --

	final int contentLength = request.getContentLength();

	if (contentLength == 0) {
		LOG.error("Empty logo file.");
		throw new StatusServletException(Response.SC_NO_CONTENT);
	}

	if (contentLength > FileUploadUtils.MAX_UPLOAD_IMAGE_SIZE) {
		LOG.error("Logo file's size is too big to be uploaded (size: {}, maximum : {}).", contentLength, FileUploadUtils.MAX_UPLOAD_IMAGE_SIZE);
		throw new StatusServletException(Response.SC_REQUEST_ENTITY_TOO_LARGE);
	}

	// --
	// Saving new logo.
	// --

	organization.setLogo(organization.getId() + "_" + new Date().getTime());
	processUpload(new MultipartRequest(request), response, organization.getLogo(), true, null);
	organizationDAO.persist(organization, context.getUser());

	// --
	// Deleting previous logo file.
	// --

	if (StringUtils.isNotBlank(previousLogoFileName)) {
		fileStorageProvider.delete(previousLogoFileName);
	}

	response.getWriter().write(organization.getLogo());
}