List of usage examples for org.apache.commons.fileupload FileUploadException toString
public String toString()
From source file:org.apache.ofbiz.content.data.DataResourceWorker.java
/** * Uploads image data from a form and stores it in ImageDataResource. Expects key data in a field identified by the "idField" value and the binary data * to be in a field id'd by uploadField. *///from w w w. java2 s .co m // TODO: This method is not used and should be removed. amb public static String uploadAndStoreImage(HttpServletRequest request, String idField, String uploadField) { ServletFileUpload fu = new ServletFileUpload( new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp"))); List<FileItem> lst = null; Locale locale = UtilHttp.getLocale(request); try { lst = UtilGenerics.checkList(fu.parseRequest(request)); } catch (FileUploadException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } if (lst.size() == 0) { String errMsg = UtilProperties.getMessage(DataResourceWorker.err_resource, "dataResourceWorker.no_files_uploaded", locale); request.setAttribute("_ERROR_MESSAGE_", errMsg); Debug.logWarning("[DataEvents.uploadImage] No files uploaded", module); return "error"; } // This code finds the idField and the upload FileItems FileItem fi = null; FileItem imageFi = null; String imageFileName = null; Map<String, Object> passedParams = new HashMap<String, Object>(); HttpSession session = request.getSession(); GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); passedParams.put("userLogin", userLogin); byte[] imageBytes = null; for (int i = 0; i < lst.size(); i++) { fi = lst.get(i); String fieldName = fi.getFieldName(); if (fi.isFormField()) { String fieldStr = fi.getString(); passedParams.put(fieldName, fieldStr); } else if (fieldName.startsWith("imageData")) { imageFi = fi; imageBytes = imageFi.get(); passedParams.put(fieldName, imageBytes); imageFileName = imageFi.getName(); passedParams.put("drObjectInfo", imageFileName); if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]imageData: " + imageBytes.length, module); } } if (imageBytes != null && imageBytes.length > 0) { String mimeType = getMimeTypeFromImageFileName(imageFileName); if (UtilValidate.isNotEmpty(mimeType)) { passedParams.put("drMimeTypeId", mimeType); try { String returnMsg = UploadContentAndImage.processContentUpload(passedParams, "", request); if (returnMsg.equals("error")) { return "error"; } } catch (GenericServiceException e) { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } } else { request.setAttribute("_ERROR_MESSAGE_", "mimeType is empty."); return "error"; } } return "success"; }
From source file:org.mskcc.cbio.portal.util.FileUploadRequestWrapper.java
/** Constructor. */ public FileUploadRequestWrapper(HttpServletRequest aRequest) throws IOException { super(aRequest); ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); try {// w ww .j a v a 2s. c om List<FileItem> fileItems = upload.parseRequest(aRequest); convertToMaps(fileItems); } catch (FileUploadException ex) { throw new IOException("Cannot parse underlying request: " + ex.toString()); } }
From source file:org.ofbiz.content.data.DataResourceWorker.java
/** * Uploads image data from a form and stores it in ImageDataResource. Expects key data in a field identified by the "idField" value and the binary data * to be in a field id'd by uploadField. *///from w w w . j a v a 2s.c o m // TODO: This method is not used and should be removed. amb public static String uploadAndStoreImage(HttpServletRequest request, String idField, String uploadField) { //Delegator delegator = (Delegator) request.getAttribute("delegator"); //String idFieldValue = null; ServletFileUpload fu = new ServletFileUpload( new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp"))); List<FileItem> lst = null; Locale locale = UtilHttp.getLocale(request); try { lst = UtilGenerics.checkList(fu.parseRequest(request)); } catch (FileUploadException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } if (lst.size() == 0) { String errMsg = UtilProperties.getMessage(DataResourceWorker.err_resource, "dataResourceWorker.no_files_uploaded", locale); request.setAttribute("_ERROR_MESSAGE_", errMsg); Debug.logWarning("[DataEvents.uploadImage] No files uploaded", module); return "error"; } // This code finds the idField and the upload FileItems FileItem fi = null; FileItem imageFi = null; String imageFileName = null; Map<String, Object> passedParams = FastMap.newInstance(); HttpSession session = request.getSession(); GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); passedParams.put("userLogin", userLogin); byte[] imageBytes = null; for (int i = 0; i < lst.size(); i++) { fi = lst.get(i); //String fn = fi.getName(); String fieldName = fi.getFieldName(); if (fi.isFormField()) { String fieldStr = fi.getString(); passedParams.put(fieldName, fieldStr); } else if (fieldName.startsWith("imageData")) { imageFi = fi; imageBytes = imageFi.get(); passedParams.put(fieldName, imageBytes); imageFileName = imageFi.getName(); passedParams.put("drObjectInfo", imageFileName); if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]imageData: " + imageBytes.length, module); } } if (imageBytes != null && imageBytes.length > 0) { String mimeType = getMimeTypeFromImageFileName(imageFileName); if (UtilValidate.isNotEmpty(mimeType)) { passedParams.put("drMimeTypeId", mimeType); try { String returnMsg = UploadContentAndImage.processContentUpload(passedParams, "", request); if (returnMsg.equals("error")) { return "error"; } } catch (GenericServiceException e) { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } } else { request.setAttribute("_ERROR_MESSAGE_", "mimeType is empty."); return "error"; } } return "success"; }
From source file:org.pentaho.platform.web.refactor.SolutionManagerUIComponent.java
public Document doFileUpload() { String baseUrl = PentahoSystem.getApplicationContext() .getSolutionPath(SolutionManagerUIComponent.EMPTY_STR); ISolutionRepository repository = PentahoSystem.get(ISolutionRepository.class, session); String path = this.getParameter(SolutionManagerUIComponent.PATH_STR, null); IParameterProvider request = (IParameterProvider) getParameterProviders() .get(IParameterProvider.SCOPE_REQUEST); HttpServletRequest httpRequest = ((HttpRequestParameterProvider) request).getRequest(); /* // ww w.j a v a 2 s .c o m String contentType = httpRequest.getContentType(); if ((contentType == null) || ((contentType.indexOf("multipart/form-data") < 0) && (contentType.indexOf("multipart/mixed stream") < 0))) { //$NON-NLS-1$ //$NON-NLS-2$ return doGetSolutionStructure(); } DiskFileUpload uploader = new DiskFileUpload(); */ if (!ServletFileUpload.isMultipartContent(httpRequest)) { return doGetSolutionStructure(); } ServletFileUpload uploader = new ServletFileUpload(new DiskFileItemFactory()); try { List fileList = uploader.parseRequest(httpRequest); Iterator iter = fileList.iterator(); while (iter.hasNext()) { FileItem fi = (FileItem) iter.next(); // Check if not form field so as to only handle the file inputs if (!fi.isFormField()) { File tempFileRef = new File(fi.getName()); repository.addSolutionFile(baseUrl, path, tempFileRef.getName(), fi.get(), true); SolutionManagerUIComponent.logger .info(Messages.getString("SolutionManagerUIComponent.INFO_0001_FILE_SAVED") + path + "/" //$NON-NLS-1$//$NON-NLS-2$ + tempFileRef.getName()); } } } catch (FileUploadException e) { SolutionManagerUIComponent.logger.error(e.toString()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return doGetSolutionStructure(); }
From source file:podd.resources.services.CreateObjectService.java
private void loadFormData(Representation entity) { blankNodeId = ""; parentRelationship = ""; // FIXME: Each instance of this class is used only once, why is the following required? sentOntology = null;//from w w w. ja v a 2s .c om RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory()); try { List<FileItem> list = upload.parseRepresentation(entity); for (FileItem item : list) { if (item.getFieldName().equals("id") && item.isFormField()) { blankNodeId = item.getString().trim(); } if (item.getFieldName().equals("parentRelationship") && item.isFormField()) { parentRelationship = item.getString().trim(); } if (item.getFieldName().equals("ontology") && !item.isFormField()) { sentOntology = ontologyHelper.populateOntology(item.getInputStream()); } } } catch (FileUploadException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error reading form data. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "File Intialisation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Create Object Service: " + msg, e.toString()); } catch (IOException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error reading file. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "File Initalisation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Create Object Service: " + msg, e.toString()); } catch (OWLOntologyCreationException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error creating ontology. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "Ontology Creation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Create Object Service: " + msg, e.toString()); } }
From source file:podd.resources.services.DeleteDataStreamService.java
private void loadFormData(Representation entity) { objectURI = null;// www . ja v a 2 s . c o m RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory()); try { List<FileItem> list = upload.parseRepresentation(entity); for (FileItem item : list) { if (item.getFieldName().equals("URI") && item.isFormField()) { objectURI = URI.create(item.getString().trim()); } if (item.getFieldName().equals("filename") && item.isFormField()) { filename = item.getString().trim(); } } } catch (FileUploadException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error reading form data. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "File Intialisation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Delete Datastream Service: " + msg, e.toString()); } }
From source file:podd.resources.services.DeleteObjectService.java
private void loadFormData(Representation entity) { objectURI = null;/* w w w . j a va 2 s.c o m*/ RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory()); try { List<FileItem> list = upload.parseRepresentation(entity); for (FileItem item : list) { if (item.getFieldName().equals("URI") && item.isFormField()) { objectURI = URI.create(item.getString().trim()); } } } catch (FileUploadException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error reading form data. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "File Intialisation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Delete Object Service: " + msg, e.toString()); } }
From source file:podd.resources.services.EditObjectService.java
private void loadFormData(Representation entity) { objectURI = null;//ww w. j av a 2 s . c om sentOntology = null; doMerge = false; RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory()); try { List<FileItem> list = upload.parseRepresentation(entity); for (FileItem item : list) { if (item.isFormField()) { if (item.getFieldName().equals("URI")) { objectURI = URI.create(item.getString().trim()); } else if (item.getFieldName().equals("merge")) { doMerge = item.getString().equalsIgnoreCase("true") ? true : false; } } else { if (item.getFieldName().equals("ontology")) { sentOntology = ontologyHelper.populateOntology(item.getInputStream()); } } } } catch (FileUploadException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error reading form data. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "File Intialisation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Edit Object Service: " + msg, e.toString()); } catch (IOException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error reading file. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "File Initalisation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Edit Object Service: " + msg, e.toString()); } catch (OWLOntologyCreationException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error creating ontology. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "Ontology Creation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Edit Object Service: " + msg, e.toString()); } }
From source file:podd.resources.services.LocalFileAttachmentService.java
private void loadFormData(Representation entity) { fileDescMap = new LinkedHashMap<Integer, String>(); fileMap = new LinkedHashMap<Integer, FileItem>(); RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory()); try {//from w ww . j a va 2s . com List<FileItem> list = upload.parseRepresentation(entity); for (FileItem item : list) { final String fieldName = item.getFieldName().trim(); if (item.isFormField()) { if ("URI".equals(fieldName)) { objectURI = item.getString().trim(); } else { String intString = getFirstGroupMatched(DESCRIPTION_NAME_PATTERN, fieldName); if (null != intString) { fileDescMap.put(Integer.parseInt(intString), item.getString()); } } } else { String intString = getFirstGroupMatched(FILE_NAME_PATTERN, fieldName); if (null != intString) { fileMap.put(Integer.parseInt(intString), item); } } } } catch (FileUploadException e) { final String msg = "Error loading form data. "; LOGGER.error(msg, e); errorMap.put("errorMessage", msg); auditLogHelper.auditAction(ERROR, authenticatedUser, "File Attachment Service: " + msg, e.toString()); getResponse().setStatus(CLIENT_ERROR_BAD_REQUEST); } }
From source file:podd.resources.services.PublishProjectService.java
private void loadFormData(Representation entity) { objectURI = null;/* w ww.j a va 2s . c o m*/ RestletFileUpload upload = new RestletFileUpload(new DiskFileItemFactory()); try { List<FileItem> list = upload.parseRepresentation(entity); for (FileItem item : list) { if (item.getFieldName().equals("URI") && item.isFormField()) { objectURI = URI.create(item.getString().trim()); } } } catch (FileUploadException e) { getResponse().setStatus(SERVER_ERROR_INTERNAL); final String msg = "Error reading form data. "; errorHandler.handleException(GENERAL_MESSAGE_ID, "File Intialisation Error", msg, e); auditLogHelper.auditAction(ERROR, authenticatedUser, "Publish Object Service: " + msg, e.toString()); } }