List of usage examples for com.google.gwt.http.client Response SC_REQUEST_ENTITY_TOO_LARGE
int SC_REQUEST_ENTITY_TOO_LARGE
To view the source code for com.google.gwt.http.client Response SC_REQUEST_ENTITY_TOO_LARGE.
Click Source Link
From source file:org.sigmah.server.servlet.FileServlet.java
License:Open Source License
/** * See {@link ServletMethod#UPLOAD_ORGANIZATION_LOGO} for JavaDoc. * //from w w w . ja v a 2 s. c om * @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); organizationDAO.persist(organization, context.getUser()); // -- // Deleting previous logo file. // -- if (StringUtils.isNotBlank(previousLogoFileName)) { fileStorageProvider.delete(previousLogoFileName); } response.getWriter().write(organization.getLogo()); }
From source file:org.sigmah.server.servlet.FileServlet.java
License:Open Source License
/** * See {@link ServletMethod#UPLOAD} for JavaDoc. * // ww w . ja v a 2s . co m * @param request * The HTTP request containing the file id parameter. * @param response * The HTTP response on which the file content is written. * @param context * The execution context. * @throws Exception * If an error occurs during process. */ protected void upload(final HttpServletRequest request, final HttpServletResponse response, final ServletExecutionContext context) throws Exception { // -- // Verify content length. // -- 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); final long size = this.processUpload(multipartRequest, response, fileName, false); final Map<String, String> properties = multipartRequest.getProperties(); conflicts.searchForFileAddConflicts(properties, context.getLanguage(), context.getUser()); // -- // Create the associated entries in File and FileVersion tables. // -- final Integer fileId = fileDAO.saveOrUpdate(properties, fileName, (int) size); final FileVersion fileVersion = fileDAO.getLastVersion(fileId); // -- // If a monitored point must be created. // -- final MonitoredPoint monitoredPoint = parseMonitoredPoint(properties); if (monitoredPoint != null) { final Integer projectId = ClientUtils.asInt(properties.get(FileUploadUtils.DOCUMENT_PROJECT)); final Project project = projectDAO.findById(projectId); monitoredPoint.setFile(fileDAO.findById(fileId)); MonitoredPointList list = project.getPointsList(); if (list == null) { list = new MonitoredPointList(); project.setPointsList(list); } if (list.getPoints() == null) { list.setPoints(new ArrayList<MonitoredPoint>()); } // Adds the point to the list. list.addMonitoredPoint(monitoredPoint); // Saves monitored point. monitoredPointDAO.persist(monitoredPoint, context.getUser()); } final MonitoredPointDTO monitoredPointDTO = mapper().map(monitoredPoint, new MonitoredPointDTO(), MonitoredPointDTO.Mode.BASE); final FileVersionDTO fileVersionDTO = mapper().map(fileVersion, new FileVersionDTO()); response.setContentType(FileType.HTML.getContentType()); response.getWriter().write(FileUploadResponse.serialize(fileVersionDTO, monitoredPointDTO)); }
From source file:org.sigmah.shared.file.DirectTransfertManager.java
License:Open Source License
@Override public void upload(final FormPanel formPanel, final ProgressListener progressListener) { final ServletUrlBuilder urlBuilder = new ServletUrlBuilder(authenticationProvider, pageManager, ServletConstants.Servlet.FILE, ServletConstants.ServletMethod.UPLOAD); formPanel.setAction(urlBuilder.toString()); formPanel.setEncoding(FormPanel.Encoding.MULTIPART); formPanel.setMethod(FormPanel.Method.POST); formPanel.addListener(Events.Submit, new Listener<FormEvent>() { @Override//from w ww . j av a 2 s. c o m public void handleEvent(FormEvent formEvent) { formPanel.removeListener(Events.Submit, this); final String result = formEvent.getResultHtml(); switch (ServletConstants.getErrorCode(result)) { case Response.SC_OK: progressListener.onLoad(result); break; case Response.SC_NO_CONTENT: progressListener.onFailure(Cause.EMPTY_FILE); break; case Response.SC_REQUEST_ENTITY_TOO_LARGE: progressListener.onFailure(Cause.FILE_TOO_LARGE); break; case Response.SC_PRECONDITION_FAILED: progressListener.onFailure(Cause.BAD_REQUEST); break; default: progressListener.onFailure(Cause.SERVER_ERROR); break; } } }); formPanel.submit(); }