当前位置: 首页>>代码示例>>Java>>正文


Java Response.SC_NO_CONTENT属性代码示例

本文整理汇总了Java中com.google.gwt.http.client.Response.SC_NO_CONTENT属性的典型用法代码示例。如果您正苦于以下问题:Java Response.SC_NO_CONTENT属性的具体用法?Java Response.SC_NO_CONTENT怎么用?Java Response.SC_NO_CONTENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.gwt.http.client.Response的用法示例。


在下文中一共展示了Response.SC_NO_CONTENT属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadAvatar

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);
}
 
开发者ID:sigmah-dev,项目名称:sigmah,代码行数:26,代码来源:FileServlet.java

示例2: handleSuccess

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);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:AsyncRequestCallback.java

示例3: uploadOrganizationLogo

/**
 * 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());
}
 
开发者ID:sigmah-dev,项目名称:sigmah,代码行数:74,代码来源:FileServlet.java


注:本文中的com.google.gwt.http.client.Response.SC_NO_CONTENT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。