@Test public void testHandleFileSubmit() { FileUploadEvent event = new FileUploadEvent(uiComponent, nativeUploadedFile); fileUploadManager.handleFileUpload(event); assertEquals("submitted?faces-redirect=true&uploadId=" + fileUploadManager.getUploadId(), fileUploadManager.handleFileSubmit()); }
public String handleFileSubmit() { String redirect = ""; if (!uploadedFiles.isEmpty()) { try { String targetDirectory = FILE_SUBMIT_PATH + uploadId; int index = 1; Iterator<UploadFile> iterator = uploadedFiles .iterator(); while (iterator.hasNext()) { UploadFile uploadedFile = (UploadFile) iterator .next(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( uploadedFile.getContents()); File targetFile = new File(targetDirectory + TEMP_EXTENSION + index + "_" + uploadedFile.getName()); FileUtils.copyInputStreamToFile( byteArrayInputStream, targetFile); LOGGER.info("submitted: {}", uploadedFile); index++; } new File(targetDirectory + TEMP_EXTENSION) .renameTo(new File(targetDirectory)); redirect = "submitted?faces-redirect=true&uploadId=" + uploadId; init(); LOGGER.info("submitted all files for uploadId: {}", uploadId); } catch (IOException ioException) { LOGGER.error("files not submitted", ioException); FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submit failed", "Unexpected error occured")); } } else { FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No submit", "No file(s) have been uploaded")); } return redirect; }
FileUploadManager implements Serializable { public String handleFileSubmit() { String redirect = ""; if (!uploadedFiles.isEmpty()) { try { String targetDirectory = FILE_SUBMIT_PATH + uploadId; int index = 1; Iterator<UploadFile> iterator = uploadedFiles .iterator(); while (iterator.hasNext()) { UploadFile uploadedFile = (UploadFile) iterator .next(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( uploadedFile.getContents()); File targetFile = new File(targetDirectory + TEMP_EXTENSION + index + "_" + uploadedFile.getName()); FileUtils.copyInputStreamToFile( byteArrayInputStream, targetFile); LOGGER.info("submitted: {}", uploadedFile); index++; } new File(targetDirectory + TEMP_EXTENSION) .renameTo(new File(targetDirectory)); redirect = "submitted?faces-redirect=true&uploadId=" + uploadId; init(); LOGGER.info("submitted all files for uploadId: {}", uploadId); } catch (IOException ioException) { LOGGER.error("files not submitted", ioException); FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submit failed", "Unexpected error occured")); } } else { FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No submit", "No file(s) have been uploaded")); } return redirect; } }
FileUploadManager implements Serializable { public String handleFileSubmit() { String redirect = ""; if (!uploadedFiles.isEmpty()) { try { String targetDirectory = FILE_SUBMIT_PATH + uploadId; int index = 1; Iterator<UploadFile> iterator = uploadedFiles .iterator(); while (iterator.hasNext()) { UploadFile uploadedFile = (UploadFile) iterator .next(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( uploadedFile.getContents()); File targetFile = new File(targetDirectory + TEMP_EXTENSION + index + "_" + uploadedFile.getName()); FileUtils.copyInputStreamToFile( byteArrayInputStream, targetFile); LOGGER.info("submitted: {}", uploadedFile); index++; } new File(targetDirectory + TEMP_EXTENSION) .renameTo(new File(targetDirectory)); redirect = "submitted?faces-redirect=true&uploadId=" + uploadId; init(); LOGGER.info("submitted all files for uploadId: {}", uploadId); } catch (IOException ioException) { LOGGER.error("files not submitted", ioException); FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submit failed", "Unexpected error occured")); } } else { FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No submit", "No file(s) have been uploaded")); } return redirect; }  }
FileUploadManager implements Serializable { public String handleFileSubmit() { String redirect = ""; if (!uploadedFiles.isEmpty()) { try { String targetDirectory = FILE_SUBMIT_PATH + uploadId; int index = 1; Iterator<UploadFile> iterator = uploadedFiles .iterator(); while (iterator.hasNext()) { UploadFile uploadedFile = (UploadFile) iterator .next(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( uploadedFile.getContents()); File targetFile = new File(targetDirectory + TEMP_EXTENSION + index + "_" + uploadedFile.getName()); FileUtils.copyInputStreamToFile( byteArrayInputStream, targetFile); LOGGER.info("submitted: {}", uploadedFile); index++; } new File(targetDirectory + TEMP_EXTENSION) .renameTo(new File(targetDirectory)); redirect = "submitted?faces-redirect=true&uploadId=" + uploadId; init(); LOGGER.info("submitted all files for uploadId: {}", uploadId); } catch (IOException ioException) { LOGGER.error("files not submitted", ioException); FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submit failed", "Unexpected error occured")); } } else { FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No submit", "No file(s) have been uploaded")); } return redirect; }  @PostConstruct void init(); List<UploadFile> getUploadedFiles(); String getUploadId(); void handleFileUpload(FileUploadEvent event); void handleFileRemoval(String id); String handleFileSubmit(); String getCurrentFileLimit(); StreamedContent getImage(); }
FileUploadManager implements Serializable { public String handleFileSubmit() { String redirect = ""; if (!uploadedFiles.isEmpty()) { try { String targetDirectory = FILE_SUBMIT_PATH + uploadId; int index = 1; Iterator<UploadFile> iterator = uploadedFiles .iterator(); while (iterator.hasNext()) { UploadFile uploadedFile = (UploadFile) iterator .next(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( uploadedFile.getContents()); File targetFile = new File(targetDirectory + TEMP_EXTENSION + index + "_" + uploadedFile.getName()); FileUtils.copyInputStreamToFile( byteArrayInputStream, targetFile); LOGGER.info("submitted: {}", uploadedFile); index++; } new File(targetDirectory + TEMP_EXTENSION) .renameTo(new File(targetDirectory)); redirect = "submitted?faces-redirect=true&uploadId=" + uploadId; init(); LOGGER.info("submitted all files for uploadId: {}", uploadId); } catch (IOException ioException) { LOGGER.error("files not submitted", ioException); FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submit failed", "Unexpected error occured")); } } else { FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No submit", "No file(s) have been uploaded")); } return redirect; }  @PostConstruct void init(); List<UploadFile> getUploadedFiles(); String getUploadId(); void handleFileUpload(FileUploadEvent event); void handleFileRemoval(String id); String handleFileSubmit(); String getCurrentFileLimit(); StreamedContent getImage(); static final int FILE_LIMIT; }