List of usage examples for org.springframework.web.multipart MultipartHttpServletRequest getFileMap
Map<String, MultipartFile> getFileMap();
From source file:com.glaf.mail.web.springmvc.MailTaskController.java
@RequestMapping("/uploadMails") public ModelAndView uploadMails(HttpServletRequest request, ModelMap modelMap) { MultipartHttpServletRequest req = (MultipartHttpServletRequest) request; Map<String, Object> params = RequestUtils.getParameterMap(req); logger.debug(params);/*from w w w . ja v a 2 s . c o m*/ // System.out.println(params); String taskId = req.getParameter("taskId"); if (StringUtils.isEmpty(taskId)) { taskId = req.getParameter("id"); } MailTask mailTask = null; if (StringUtils.isNotEmpty(taskId)) { mailTask = mailTaskService.getMailTask(taskId); } if (mailTask != null && StringUtils.equals(RequestUtils.getActorId(request), mailTask.getCreateBy())) { try { Map<String, MultipartFile> fileMap = req.getFileMap(); Set<Entry<String, MultipartFile>> entrySet = fileMap.entrySet(); for (Entry<String, MultipartFile> entry : entrySet) { MultipartFile mFile = entry.getValue(); if (mFile.getOriginalFilename() != null && mFile.getSize() > 0) { logger.debug(mFile.getName()); if (mFile.getOriginalFilename().endsWith(".txt")) { byte[] bytes = mFile.getBytes(); String rowIds = new String(bytes); List<String> addresses = StringTools.split(rowIds); if (addresses.size() <= 100000) { mailDataFacede.saveMails(taskId, addresses); } else { throw new RuntimeException("mail addresses too many"); } break; } } } } catch (Exception ex) {// ? ex.printStackTrace(); throw new RuntimeException(ex.getMessage()); } } return this.mailList(request, modelMap); }
From source file:egovframework.oe1.cms.srm.web.EgovOe1OperImprovReqController.java
/** * ?? ?./*from w w w . ja v a 2 s . c o m*/ * * @param EgovOe1OperImprovReqVO * @param model * @return "forward:/cms/srm/gnrl/selectOperImprovReqList.do" * @exception Exception */ @RequestMapping(value = "/cms/srm/gnrl/insertOperImprovReq.do") public String insertOperImprovReq(final MultipartHttpServletRequest multiRequest, @ModelAttribute("vo") EgovOe1OperImprovReqVO vo, SessionStatus status) throws Exception { //? Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "forward:/cms/com/EgovOe1LoginUsr.do"; //? ?? } /** ? */ List<EgovOe1FileVO> _result = null; String _atchFileId = ""; final Map<String, MultipartFile> files = multiRequest.getFileMap(); if (!files.isEmpty()) { _result = fileUtil.parseFileInf(files, "", 0, "", ""); _atchFileId = fileMngService.insertFileInfs(_result); //?? ?? ?? ? ID . } vo.setRequstAtchFileId(_atchFileId); operImprovReqService.insertOperImprovReq(vo); status.setComplete(); return "forward:/cms/srm/gnrl/selectOperImprovReqList.do"; }
From source file:org.dataone.proto.trove.mn.rest.v1.ObjectController.java
/** * */// www .j a v a2 s.co m @RequestMapping(value = "/v1/object/{pid}", method = RequestMethod.POST) public ModelAndView create(MultipartHttpServletRequest fileRequest, HttpServletResponse response) throws InvalidSystemMetadata, InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, InsufficientResources, NotImplemented, InvalidRequest { Session session = new Session(); Identifier identifier = new Identifier(); MultipartFile sytemMetaDataMultipart = null; MultipartFile objectMultipart = null; SystemMetadata systemMetadata = null; Set<String> keys = fileRequest.getFileMap().keySet(); for (String key : keys) { if (key.equalsIgnoreCase("sysmeta")) { sytemMetaDataMultipart = fileRequest.getFileMap().get(key); } else { objectMultipart = fileRequest.getFileMap().get(key); } } if (sytemMetaDataMultipart != null) { try { systemMetadata = (SystemMetadata) TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sytemMetaDataMultipart.getInputStream()); } catch (IOException ex) { throw new InvalidSystemMetadata("15001", ex.getMessage()); } catch (JiBXException ex) { throw new InvalidSystemMetadata("15002", ex.getMessage()); } catch (InstantiationException ex) { throw new InvalidSystemMetadata("15003", ex.getMessage()); } catch (IllegalAccessException ex) { throw new InvalidSystemMetadata("15004", ex.getMessage()); } } else { throw new InvalidSystemMetadata("15005", "System Metadata was not found as Part of Multipart Mime message"); } identifier.setValue(systemMetadata.getIdentifier().getValue()); InputStream objectInputStream = null; if (objectMultipart != null && !(objectMultipart.isEmpty())) { try { objectInputStream = objectMultipart.getInputStream(); } catch (IOException ex) { throw new InvalidRequest("15006", ex.getMessage()); } } else { throw new InvalidRequest("15007", "Object to be created is not attached"); } DateTime dt = new DateTime(); systemMetadata.setDateUploaded(dt.toDate()); systemMetadata.setDateSysMetadataModified(dt.toDate()); if (!this.logRequest(fileRequest, Event.CREATE, identifier)) { throw new ServiceFailure("20001", "unable to log request"); } identifier = mnStorage.create(session, identifier, objectInputStream, systemMetadata); return new ModelAndView("xmlIdentifierViewResolver", "org.dataone.service.types.v1.Identifier", identifier); }
From source file:egovframework.oe1.cms.srm.web.EgovOe1OperImprovReqController.java
/** * ?? ./* w ww . jav a 2s.c o m*/ * * @param EgovOe1OperImprovReqVO * @param model * @return "forward:/cms/srm/gnrl/selectOperImprovReqList.do" * @exception Exception */ @RequestMapping(value = "/cms/srm/gnrl/updateOperImprovReq.do") public String updateOperImprovReq(final MultipartHttpServletRequest multiRequest, @ModelAttribute("vo") EgovOe1OperImprovReqVO vo, SessionStatus status) throws Exception { //? Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "forward:/cms/com/EgovOe1LoginUsr.do"; //? ?? } String _atchFileId = vo.getRequstAtchFileId();// ? ? ? ? ? ID . final Map<String, MultipartFile> files = multiRequest.getFileMap(); if (!files.isEmpty()) { if ("".equals(_atchFileId) || _atchFileId == null) { List<EgovOe1FileVO> _result = fileUtil.parseFileInf(files, "", 0, _atchFileId, ""); _atchFileId = fileMngService.insertFileInfs(_result); // ? ? ID . vo.setRequstAtchFileId(_atchFileId); // ? ? ?? ? ID . } else { EgovOe1FileVO fvo = new EgovOe1FileVO(); fvo.setAtchFileId(_atchFileId); // ? ? ?? VO? ? ID . int _cnt = fileMngService.getMaxFileSN(fvo); // ? ID? ? ? ? ??. List<EgovOe1FileVO> _result = fileUtil.parseFileInf(files, "", _cnt, _atchFileId, ""); fileMngService.updateFileInfs(_result); } } operImprovReqService.updateOperImprovReq(vo); return "forward:/cms/srm/gnrl/selectOperImprovReqList.do"; }
From source file:egovframework.oe1.cms.sim.web.EgovOe1ChangeRequestManageController.java
/** * ?? ?//from w w w .j a v a 2s .c o m * @param EgovOe1ChangeRequestVO * @return "/cms/sim/EgovChangeRequestRegistPopup" * @exception Exception */ @RequestMapping("/cms/sim/gnrl/addChangeRequest.do") public String insertChangeRequest(final MultipartHttpServletRequest multiRequest, @ModelAttribute("changeRequestvo") EgovOe1ChangeRequestVO changeRequestVo, HttpSession session, ModelMap model) throws Exception { //Spring Security Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } // attached file upload. List<EgovOe1FileVO> _result = null; String _atchFileId = ""; final Map<String, MultipartFile> files = multiRequest.getFileMap(); if (!files.isEmpty()) { _result = fileUtil.parseFileInf(files, "", 0, "", ""); _atchFileId = fileMngService.insertFileInfs(_result); //?? ?? ?? ? ID . } changeRequestVo.setAtchFileId(_atchFileId); // set Login User Id to change Operator Id. changeRequestVo.setChangeRqesterId((String) session.getAttribute("s_mberId")); // insert Change Request Info. changeRequestManageService.insertChangeRequest(changeRequestVo); //? ? , ?? UPDATE EgovOe1OperImprovReqVO operImprovReqVO = new EgovOe1OperImprovReqVO(); operImprovReqVO.setOperImprvmRequstId(changeRequestVo.getRequstSysBasisId()); /*?ID */ operImprovReqVO.setRequstSttusCode("03");/* ?? : (03) */ // set Login User Id to change Operator Id. EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser(); operImprovReqVO.setLastUpdusrId(user.getMberId()); /* ?ID */ operImprovReqService.updateOperImprovReqTransChange(operImprovReqVO); model.addAttribute("successFlag", "Y"); // return return "/cms/sim/EgovChangeRequestRegistPopup"; }
From source file:egovframework.oe1.cms.arc.web.EgovOe1ScrinController.java
/** * ?./*w w w. j a v a 2 s. c o m*/ * @param ? scrinVO , multiRequest * @return "forward:/cms/arc/selectScrin.do"; * @exception Exception */ @RequestMapping(value = "/cms/arc/addScrin.do") public String insertScrin(final MultipartHttpServletRequest multiRequest, @ModelAttribute("scrinVO") EgovOe1ScrinVO scrinVO, ModelMap model, SessionStatus status) throws Exception { // Spring Security Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; // ? ?? } // EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser(); scrinVO.setFrstRegisterId(user.getMberId()); /** ? */ List<EgovOe1FileVO> _result = null; String _atchFileId = ""; final Map<String, MultipartFile> files = multiRequest.getFileMap(); if (!files.isEmpty()) { _result = fileUtil.parseFileInf(files, "", 0, "", ""); _atchFileId = fileMngService.insertFileInfs(_result); // ?? ?? // ?? ? // ID . } scrinVO.setAtchFileId(_atchFileId); // IDd scrinVO.setScrinId(idGnrService.getNextStringId()); // ? egovOe1ScrinService.insertScrin(scrinVO); return "forward:/cms/arc/selectScrin.do"; }
From source file:com.glaf.core.web.springmvc.FileUploadController.java
@ResponseBody @RequestMapping("/upload") public void upload(HttpServletRequest request, HttpServletResponse response) { response.setContentType("text/plain;charset=UTF-8"); LoginContext loginContext = RequestUtils.getLoginContext(request); String serviceKey = request.getParameter("serviceKey"); String responseType = request.getParameter("responseType"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap:" + paramMap); MultipartHttpServletRequest req = (MultipartHttpServletRequest) request; String type = req.getParameter("type"); if (StringUtils.isEmpty(type)) { type = "0"; }//from w ww. ja va2 s.c om int maxUploadSize = conf.getInt(serviceKey + ".maxUploadSize", 0); if (maxUploadSize == 0) { maxUploadSize = conf.getInt("upload.maxUploadSize", 50);// 50MB } maxUploadSize = maxUploadSize * FileUtils.MB_SIZE; /** * ?maxDiskSize,5MB */ int maxDiskSize = conf.getInt(serviceKey + ".maxDiskSize", 0); if (maxDiskSize == 0) { maxDiskSize = conf.getInt("upload.maxDiskSize", 1024 * 1024 * 2);// 2MB } logger.debug("maxUploadSize:" + maxUploadSize); String uploadDir = Constants.UPLOAD_PATH; InputStream inputStream = null; try { PrintWriter out = response.getWriter(); Map<String, MultipartFile> fileMap = req.getFileMap(); Set<Entry<String, MultipartFile>> entrySet = fileMap.entrySet(); for (Entry<String, MultipartFile> entry : entrySet) { MultipartFile mFile = entry.getValue(); logger.debug("fize size:" + mFile.getSize()); if (mFile.getOriginalFilename() != null && mFile.getSize() > 0 && mFile.getSize() < maxUploadSize) { String filename = mFile.getOriginalFilename(); logger.debug("upload file:" + filename); logger.debug("fize size:" + mFile.getSize()); String fileId = UUID32.getUUID(); // ???? String autoCreatedDateDirByParttern = "yyyy/MM/dd"; String autoCreatedDateDir = DateFormatUtils.format(new java.util.Date(), autoCreatedDateDirByParttern); String rootDir = SystemProperties.getConfigRootPath(); if (!rootDir.endsWith(String.valueOf(File.separatorChar))) { rootDir = rootDir + File.separatorChar; } File savePath = new File(rootDir + uploadDir + autoCreatedDateDir); if (!savePath.exists()) { savePath.mkdirs(); } String fileName = savePath + "/" + fileId; BlobItem dataFile = new BlobItemEntity(); dataFile.setLastModified(System.currentTimeMillis()); dataFile.setCreateBy(loginContext.getActorId()); dataFile.setFileId(fileId); dataFile.setPath(uploadDir + autoCreatedDateDir + "/" + fileId); dataFile.setFilename(mFile.getOriginalFilename()); dataFile.setName(mFile.getOriginalFilename()); dataFile.setContentType(mFile.getContentType()); dataFile.setType(type); dataFile.setStatus(0); dataFile.setServiceKey(serviceKey); if (mFile.getSize() <= maxDiskSize) { dataFile.setData(mFile.getBytes()); } blobService.insertBlob(dataFile); dataFile.setData(null); if (mFile.getSize() > maxDiskSize) { FileUtils.save(fileName, inputStream); logger.debug(fileName + " save ok."); } if (StringUtils.equalsIgnoreCase(responseType, "json")) { StringBuilder json = new StringBuilder(); json.append("{"); json.append("'"); json.append("fileId"); json.append("':'"); json.append(fileId); json.append("'"); Enumeration<String> pNames = request.getParameterNames(); String pName; while (pNames.hasMoreElements()) { json.append(","); pName = (String) pNames.nextElement(); json.append("'"); json.append(pName); json.append("':'"); json.append(request.getParameter(pName)); json.append("'"); } json.append("}"); logger.debug(json.toString()); response.getWriter().write(json.toString()); } else { out.print(fileId); } } } } catch (Exception ex) { ex.printStackTrace(); } finally { IOUtils.close(inputStream); } }
From source file:org.dataone.proto.trove.mn.rest.v1.ObjectController.java
/** * update the object requested/* ww w .j a v a2 s. com*/ * * @param request * @param response * @param pid * @throws InvalidToken * @throws ServiceFailure * @throws IOException * @throws NotAuthorized * @throws NotFound * @throws NotImplemented */ @RequestMapping(value = "/v1/object/{pid}", method = RequestMethod.PUT) public void update(MultipartHttpServletRequest fileRequest, HttpServletResponse response, @PathVariable String pid) throws InvalidToken, ServiceFailure, IOException, NotAuthorized, NotFound, NotImplemented, InvalidRequest, InsufficientResources, InvalidSystemMetadata, IdentifierNotUnique, UnsupportedType { debugRequest(fileRequest); Identifier id = new Identifier(); try { id.setValue(urlCodec.decode(pid, "UTF-8")); } catch (DecoderException ex) { throw new ServiceFailure("20000", ex.getMessage()); } catch (UnsupportedEncodingException ex) { throw new ServiceFailure("20001", ex.getMessage()); } if (!this.logRequest(fileRequest, Event.UPDATE, id)) { throw new ServiceFailure("20001", "unable to log request"); } Session session = new Session(); InputStream objectInputStream = null; MultipartFile sytemMetaDataMultipart = null; MultipartFile objectMultipart = null; SystemMetadata systemMetadata = null; Set<String> keys = fileRequest.getFileMap().keySet(); for (String key : keys) { if (key.equalsIgnoreCase("sysmeta")) { sytemMetaDataMultipart = fileRequest.getFileMap().get(key); } else { objectMultipart = fileRequest.getFileMap().get(key); } } if (sytemMetaDataMultipart != null) { try { systemMetadata = (SystemMetadata) TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sytemMetaDataMultipart.getInputStream()); } catch (IOException ex) { throw new InvalidSystemMetadata("15001", ex.getMessage()); } catch (JiBXException ex) { throw new InvalidSystemMetadata("15002", ex.getMessage()); } catch (InstantiationException ex) { throw new InvalidSystemMetadata("15003", ex.getMessage()); } catch (IllegalAccessException ex) { throw new InvalidSystemMetadata("15004", ex.getMessage()); } } else { throw new InvalidSystemMetadata("15005", "System Metadata was not found as Part of Multipart Mime message"); } if (objectMultipart != null && !(objectMultipart.isEmpty())) { try { objectInputStream = objectMultipart.getInputStream(); } catch (IOException ex) { throw new InvalidRequest("15006", ex.getMessage()); } } else { throw new InvalidRequest("15007", "Object to be created is not attached"); } id.setValue(systemMetadata.getIdentifier().getValue()); DateTime dt = new DateTime(); systemMetadata.setDateSysMetadataModified(dt.toDate()); mnStorage.update(id, null, id, null); InputStream in = mnRead.get(id); OutputStream out = response.getOutputStream(); try { byte[] buffer = null; int filesize = in.available(); if (filesize < 250000) { buffer = new byte[SMALL_BUFF_SIZE]; } else if (filesize >= 250000 && filesize <= 500000) { buffer = new byte[MED_BUFF_SIZE]; } else { buffer = new byte[LARGE_BUFF_SIZE]; } while (true) { int amountRead = in.read(buffer); if (amountRead == -1) { break; } out.write(buffer, 0, amountRead); out.flush(); } } finally { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } }
From source file:egovframework.oe1.cms.sys.web.EgovOe1ConsentManageController.java
/** * ? ? ./* w ww . j a v a 2s.c om*/ * @param submitVO * ?? * @param bindingResult * @param model * @param status * @return ?? * @throws Exception */ @RequestMapping("/cms/cmm/modifySanctionDraftingWriting.do") public String modifySanctionDraftingWriting(final MultipartHttpServletRequest multiRequest, @ModelAttribute EgovOe1SanctionSubmitVO submitVO, BindingResult bindingResult, Model model, SessionStatus status) throws Exception { // Spring Security Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; // ? // ?? } // Server-Side Validation beanValidator.validate(submitVO, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute("sanctionSubmitVO", submitVO); return "/cms/sys/EgovSanctnDrftUpdt"; } // ?? String _atchFileId = submitVO.getAtchFileId(); final Map<String, MultipartFile> files = multiRequest.getFileMap(); if (!files.isEmpty()) { if ("".equals(_atchFileId) || _atchFileId == null) { List<EgovOe1FileVO> _result = fileUtil.parseFileInf(files, "", 0, _atchFileId, ""); _atchFileId = fileMngService.insertFileInfs(_result); submitVO.setAtchFileId(_atchFileId); } else { EgovOe1FileVO fvo = new EgovOe1FileVO(); fvo.setAtchFileId(_atchFileId); int _cnt = fileMngService.getMaxFileSN(fvo); List<EgovOe1FileVO> _result = fileUtil.parseFileInf(files, "", _cnt, _atchFileId, ""); fileMngService.updateFileInfs(_result); } } submitVO.setAtchFileId(_atchFileId); submitVO.setDrftSttusCode("1"); // 1 : submitVO.setDeleteYn("N"); // N : (? ??) log.debug(this.getClass() + " modifySanctionDraftingWriting() submitVO : " + submitVO); consentService.actionSanctionDraftingUpdt(submitVO); status.setComplete(); return "forward:/cms/cmm/inquirySubmitList.do"; }
From source file:egovframework.oe1.cms.sys.web.EgovOe1ConsentManageController.java
/** * ? ? ?? .//from www. java 2s. co m * @param submitVO * ?? * @param bindingResult * @param model * @param status * @return ?? * @throws Exception */ @RequestMapping("/cms/cmm/addSanctionDraftingWriting.do") public String addSanctionDraftingWriting(final MultipartHttpServletRequest multiRequest, @ModelAttribute EgovOe1SanctionSubmitVO submitVO, BindingResult bindingResult, Model model, SessionStatus status) throws Exception { // Spring Security Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; // ? // ?? } // Server-Side Validation beanValidator.validate(submitVO, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute("sanctionSubmitVO", submitVO); return "/cms/sys/egovSanctnDrftWritng"; } // ? ?ID ? List<EgovOe1FileVO> _result = null; String _atchFileId = ""; final Map<String, MultipartFile> files = multiRequest.getFileMap(); if (!files.isEmpty()) { _result = fileUtil.parseFileInf(files, "DSCH_", 0, "", ""); _atchFileId = fileMngService.insertFileInfs(_result); // ?? // ?? // ?? // ? // ID // . } // ? ?ID .. submitVO.setAtchFileId(_atchFileId); // ? ID log.debug(this.getClass() + " addSanctionDraftingWriting() submitVO : " + submitVO.toString()); String drftSn = consentService.actionSanctionDrafting(submitVO); log.debug(this.getClass() + " addSanctionDraftingWriting drftSn : " + drftSn); status.setComplete(); return "forward:/cms/cmm/inquirySubmitList.do"; }