Example usage for org.springframework.web.multipart MultipartHttpServletRequest getParameter

List of usage examples for org.springframework.web.multipart MultipartHttpServletRequest getParameter

Introduction

In this page you can find the example usage for org.springframework.web.multipart MultipartHttpServletRequest getParameter.

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:com.photon.phresco.service.rest.api.ComponentService.java

/**
 * Updates the list of technologies/*from   w w w  . j  a  v a 2s. c  o  m*/
 * @param technologies
 * @return
  * @throws PhrescoException 
 * @throws IOException 
 */
@ApiOperation(value = " Updates technology ")
@ApiErrors(value = { @ApiError(code = 500, reason = "Unable to update technology") })
@RequestMapping(value = REST_API_TECHNOLOGIES, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        "multipart/mixed" }, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT)
public void updateTechnologies(MultipartHttpServletRequest request, HttpServletResponse response,
        @RequestParam("technology") byte[] techJson) throws PhrescoException, IOException {
    if (isDebugEnabled) {
        LOGGER.debug("ComponentService.updateTechnologies : Entry");
        LOGGER.debug("ComponentService.createTechnologies", "remoteAddress=" + request.getRemoteAddr(),
                "endpoint=" + request.getRequestURI(), "user=" + request.getParameter("userId"));
    }
    createOrUpdateTechnology(request, techJson);
}

From source file:com.photon.phresco.service.rest.api.ComponentService.java

/**
  * Creates the list of pilots/*from   w w w .  j  a  v a 2 s .  com*/
  * @param projectInfos
  * @return 
  * @throws PhrescoException 
  */
@ApiOperation(value = " Creates new pilots ")
@ApiErrors(value = { @ApiError(code = 500, reason = "Pilot creation failed") })
@RequestMapping(value = REST_API_PILOTS, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        "multipart/mixed" }, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
public @ResponseBody void createPilots(HttpServletResponse response, MultipartHttpServletRequest request,
        @RequestPart(value = "pilot", required = false) ByteArrayResource pilotFile,
        @RequestParam("pilotInfo") byte[] pilotData) throws PhrescoException {
    if (isDebugEnabled) {
        LOGGER.debug("ComponentService.createPilots : Entry");
        LOGGER.debug("ComponentService.findPilots", "remoteAddress=" + request.getRemoteAddr(),
                "endpoint=" + request.getRequestURI(), "user=" + request.getParameter("userId"));
    }
    saveOrUpdatePilot(pilotFile, pilotData);
}

From source file:com.photon.phresco.service.rest.api.ComponentService.java

/**
 * Updates the list of pilots//from www  .j av a2  s  . c o m
 * @param projectInfos
 * @return
 * @throws PhrescoException 
 */
@ApiOperation(value = " Update pilots ")
@ApiErrors(value = { @ApiError(code = 500, reason = "Pilot update failed") })
@RequestMapping(value = REST_API_PILOTS, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        "multipart/mixed" }, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT)
public @ResponseBody void updatePilots(HttpServletResponse response, MultipartHttpServletRequest request,
        @RequestPart(value = "pilot", required = false) ByteArrayResource pilotFile,
        @RequestParam("pilotInfo") byte[] pilotData) throws PhrescoException {
    if (isDebugEnabled) {
        LOGGER.debug("ComponentService.updatePilots : Entry");
        LOGGER.debug("ComponentService.findPilots", "remoteAddress=" + request.getRemoteAddr(),
                "endpoint=" + request.getRequestURI(), "user=" + request.getParameter("userId"));
    }
    saveOrUpdatePilot(pilotFile, pilotData);
}

From source file:com.photon.phresco.service.rest.api.ComponentService.java

/**
 * Creates the list of downloads//from   w w  w .ja  va  2  s  .  c om
 * @param downloads
 * @return 
 * @throws PhrescoException 
 */
@ApiOperation(value = " Creates new downloads ")
@ApiErrors(value = { @ApiError(code = 500, reason = "Failed to create") })
@RequestMapping(value = REST_API_DOWNLOADS, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        "multipart/mixed" }, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
public @ResponseBody void createDownloads(HttpServletResponse response, MultipartHttpServletRequest request,
        @RequestPart(value = "download", required = false) ByteArrayResource downloadFile,
        @RequestPart(value = "icon", required = false) ByteArrayResource iconFile,
        @RequestParam("downloads") byte[] downloadData) throws PhrescoException {
    if (isDebugEnabled) {
        LOGGER.debug("ComponentService.createDownloads : Entry");
        LOGGER.debug("ComponentService.createDownloads", "remoteAddress=" + request.getRemoteAddr(),
                "endpoint=" + request.getRequestURI(), "user=" + request.getParameter("userId"));
    }
    saveOrUpdateDownloads(downloadFile, iconFile, downloadData);
}

From source file:com.photon.phresco.service.rest.api.ComponentService.java

/**
 * Updates the list of downloadInfos//www.  j  a v a2s. c o m
 * @param downloads
 * @return
 * @throws PhrescoException 
 */
@ApiOperation(value = " Updates new downloads ")
@ApiErrors(value = { @ApiError(code = 500, reason = "Failed to update") })
@RequestMapping(value = REST_API_DOWNLOADS, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        "multipart/mixed" }, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT)
public @ResponseBody void updateDownloadInfo(HttpServletResponse response, MultipartHttpServletRequest request,
        @RequestPart(value = "download", required = false) ByteArrayResource downloadFile,
        @RequestPart(value = "icon", required = false) ByteArrayResource iconFile,
        @RequestParam("downloads") byte[] downloadData) throws PhrescoException {
    if (isDebugEnabled) {
        LOGGER.debug("ComponentService.updateDownloadInfo : Entry");
        LOGGER.debug("ComponentService.createDownloads", "remoteAddress=" + request.getRemoteAddr(),
                "endpoint=" + request.getRequestURI(), "user=" + request.getParameter("userId"));
    }
    saveOrUpdateDownloads(downloadFile, iconFile, downloadData);
}

From source file:com.photon.phresco.service.rest.api.ComponentService.java

/**
 * Updates the list of modules/*from w  w w. j a va2s  . com*/
 * @param modules
 * @return 
 * @return
 * @throws PhrescoException 
 */
@ApiOperation(value = " Updates features ")
@ApiErrors(value = { @ApiError(code = 500, reason = "Feature updation failed") })
@RequestMapping(value = REST_API_MODULES, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        "multipart/mixed" }, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT)
public @ResponseBody ArtifactGroup updateModules(HttpServletResponse response,
        MultipartHttpServletRequest request,
        @RequestPart(value = "feature", required = false) ByteArrayResource moduleFile,
        @RequestPart(value = "icon", required = false) ByteArrayResource iconFile,
        @RequestParam("data") byte[] artifactGroupData) throws PhrescoException {
    if (isDebugEnabled) {
        LOGGER.debug("ComponentService.updateModules :  Entry");
        LOGGER.debug("ComponentService.findModules", "remoteAddress=" + request.getRemoteAddr(),
                "endpoint=" + request.getRequestURI(), "user=" + request.getParameter("userId"));
    }
    String string = new String(artifactGroupData);
    ArtifactGroup artifactGroup = new Gson().fromJson(string, ArtifactGroup.class);
    if (moduleFile != null) {
        boolean saveArtifactFile = saveArtifactFile(artifactGroup, moduleFile.getByteArray());
        if (!saveArtifactFile) {
            throw new PhrescoException("Unable to create artifact");
        }
    }
    if (iconFile != null) {
        artifactGroup.setPackaging(ICON_EXT);
        boolean saveArtifactFile = saveArtifactFile(artifactGroup, iconFile.getByteArray());
        if (!saveArtifactFile) {
            throw new PhrescoException("Unable to create artifact");
        }
    }
    saveModuleGroup(artifactGroup);
    return artifactGroup;
}

From source file:com.photon.phresco.service.rest.api.ComponentService.java

/**
 * Creates the list of modules//from   w w w.  j  a  v  a 2 s . c  o  m
 * @param modules
 * @return 
 * @return 
 * @throws PhrescoException 
 * @throws IOException 
 */
@ApiOperation(value = " Creates new features ")
@ApiErrors(value = { @ApiError(code = 500, reason = "Feature creation failed") })
@RequestMapping(value = REST_API_MODULES, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        "multipart/mixed" }, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
public @ResponseBody ArtifactGroup createModules(HttpServletResponse response,
        MultipartHttpServletRequest request,
        @RequestPart(value = "feature", required = false) ByteArrayResource moduleFile,
        @RequestPart(value = "icon", required = false) ByteArrayResource iconFile,
        @RequestParam("moduleGroup") byte[] artifactGroupData) throws PhrescoException, IOException {
    if (isDebugEnabled) {
        LOGGER.debug("ComponentService.createModules : Entry");
        LOGGER.debug("ComponentService.findModules", "remoteAddress=" + request.getRemoteAddr(),
                "endpoint=" + request.getRequestURI(), "user=" + request.getParameter("userId"));
    }
    String string = new String(artifactGroupData);
    ArtifactGroup artifactGroup = new Gson().fromJson(string, ArtifactGroup.class);
    if (moduleFile != null) {
        boolean saveArtifactFile = saveArtifactFile(artifactGroup, moduleFile.getByteArray());
        if (!saveArtifactFile) {
            throw new PhrescoException("Unable to create artifact");
        }
    }
    if (iconFile != null) {
        //artifactGroup.setPackaging(ICON_EXT);
        boolean saveArtifactIcon = saveArtifactIcon(artifactGroup, iconFile.getByteArray(), ICON_EXT);
        if (!saveArtifactIcon) {
            throw new PhrescoException("Unable to create artifact");
        }
    }
    saveModuleGroup(artifactGroup);
    return artifactGroup;
}

From source file:com.prcsteel.platform.order.web.controller.cust.AccountController.java

@OpLog(OpType.SaveAccount)
@OpParam("account")
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ResponseBody/*from   ww w .  j  a va  2  s  .c o m*/
public HashMap<String, Object> saveAccount(ModelMap out, MultipartHttpServletRequest request, Account account) {
    HashMap<String, Object> result = new HashMap<String, Object>();
    if (account.getName() != null)
        account.setName(account.getName().replaceAll(" ", ""));
    if (account.getTaxCode().length() > 20) {
        result.put("data", "?20??");
        return result;
    }
    try {
        AccountType.valueOf(account.getType());
    } catch (Exception e) {
        result.put("data", "??");
        return result;
    }

    if (account.getId() == null) {
        if ("".equals(account.getName().replaceAll(" ", ""))) {
            result.put("data", "?");
            return result;
        } else {
            account.setName(account.getName().replaceAll(" ", ""));
        }
        if (accountService.selectAccountByName(account.getName().replaceAll(" ", "")) != null) {
            result.put("data", "?" + account.getName().replaceAll(" ", "")
                    + "??????");
            return result;
        }
    }
    AccountDto dto = new AccountDto();
    MultipartFile license = request.getFile("pic_license");
    MultipartFile orgCode = request.getFile("pic_org_code");
    MultipartFile taxReg = request.getFile("pic_tax_reg");
    MultipartFile taxpayerEvidence = request.getFile("pic_taxpayer_evidence");
    MultipartFile invoiceData = request.getFile("pic_invoice_data");
    MultipartFile legalID = request.getFile("pic_legal_ID");
    MultipartFile paymentData = request.getFile("pic_payment_data");
    List<MultipartFile> consignContract = request.getFiles("pic_consign_contract");
    MultipartFile enterpriseSurvey = request.getFile("pic_enterprise_survey");
    MultipartFile openAccountLicense = request.getFile("pic_open_account_license");

    List<MultipartFile> attachmentList = new ArrayList<MultipartFile>();
    if (license != null && !license.isEmpty()) {
        if (!checkUploadAttachment(license, result, attachmentList)) {
            return result;
        }
    }
    if (orgCode != null && !orgCode.isEmpty()) {
        if (!checkUploadAttachment(orgCode, result, attachmentList)) {
            return result;
        }
    }
    if (taxpayerEvidence != null && !taxpayerEvidence.isEmpty()) {
        if (!checkUploadAttachment(taxpayerEvidence, result, attachmentList)) {
            return result;
        }
    }
    if (taxReg != null && !taxReg.isEmpty()) {
        if (!checkUploadAttachment(taxReg, result, attachmentList)) {
            return result;
        }
    }
    if (invoiceData != null && !invoiceData.isEmpty()) {
        if (!checkUploadAttachment(invoiceData, result, attachmentList)) {
            return result;
        }
    }
    if (legalID != null && !legalID.isEmpty()) {
        if (!checkUploadAttachment(legalID, result, attachmentList)) {
            return result;
        }
    }
    if (paymentData != null && !paymentData.isEmpty()) {
        if (!checkUploadAttachment(paymentData, result, attachmentList)) {
            return result;
        }
    }
    if (consignContract != null && !consignContract.isEmpty()) {
        // ?????
        for (MultipartFile file : consignContract) {
            if (!checkUploadAttachment(file, result, attachmentList)) {
                return result;
            }
        }
        account.setConsignType("consign");// ??
    } else {
        if (account.getId() == null) {
            account.setConsignType("temp");// 
        }
    }
    if (enterpriseSurvey != null && !enterpriseSurvey.isEmpty()) {
        if (!checkUploadAttachment(enterpriseSurvey, result, attachmentList)) {
            return result;
        }
    }
    if (openAccountLicense != null && !openAccountLicense.isEmpty()) {
        if (!checkUploadAttachment(openAccountLicense, result, attachmentList)) {
            return result;
        }
    }
    dto.setManager(getLoginUser());
    account.setLicenseCode(StringToReplace.toReplaceAll(account.getLicenseCode()));
    account.setRegAddress(StringToReplace.toReplaceAll(account.getRegAddress()));
    account.setOrgCode(StringToReplace.toReplaceAll(account.getOrgCode()));
    account.setBankCode(StringToReplace.toReplaceAll(account.getBankCode()));
    account.setBankNameMain(StringToReplace.toReplaceAll(account.getBankNameMain()));
    account.setBankNameBranch(StringToReplace.toReplaceAll(account.getBankNameBranch()));
    account.setAccountCode(StringToReplace.toReplaceAll(account.getAccountCode()));
    account.setTaxCode(StringToReplace.toReplaceAll(account.getTaxCode()));

    account.setName(Tools.toDBC(account.getName()));//???? modify by wangxianjun
    dto.setAccount(account);
    // 
    try {
        AccountContact contact = null;
        if (account.getId() == null || account.getType().equals(AccountType.both.toString())) {
            contact = new AccountContact();
            contact.setIsMain(Integer.valueOf(Constant.YES));
            // contact.setAccountId(account.getId());
            contact.setManager(getLoginUser().getId());
            contact.setStatus(Integer.valueOf(Constant.YES));
            if (account.getId() == null) {
                contact.setType(account.getType());
            } else {
                contact.setType(AccountType.seller.toString());
            }
            contact.setName(request.getParameter("contactName").toString());
            contact.setTel(request.getParameter("contactTel").toString());
            contact.setDeptName(StringUtils.isBlank(request.getParameter("contactDeptName").toString()) ? null
                    : request.getParameter("contactDeptName").toString());
            contact.setEmail(StringUtils.isBlank(request.getParameter("contactEmail").toString()) ? null
                    : request.getParameter("contactEmail").toString());
            contact.setQq(StringUtils.isBlank(request.getParameter("contactQq").toString()) ? null
                    : request.getParameter("contactQq").toString());
            contact.setNote(StringUtils.isBlank(request.getParameter("contactNote").toString()) ? null
                    : request.getParameter("contactNote").toString());
        }
        if (account.getId() == null) {
            result.put("success", true);
            result = accountService.insert(dto, attachmentList, contact);
        } else {
            result = accountService.updateByPrimaryKeySelective(dto, attachmentList, contact);
        }
    } catch (BusinessException e) {
        result.put("success", false);
        result.put("data", e.getMsg());
    }

    return result;
}

From source file:org.auscope.portal.server.web.controllers.GridSubmitController.java

/**
 * Processes a file upload request returning a JSON object which indicates
 * whether the upload was successful and contains the filename and file
 * size./*w  ww  .jav  a2 s  . c  om*/
 *
 * @param request The servlet request
 * @param response The servlet response containing the JSON data
 *
 * @return null
 */
@RequestMapping("/uploadFile.do")
public ModelAndView uploadFile(HttpServletRequest request, HttpServletResponse response) {
    logger.debug("Entering upload.do ");
    String jobInputDir = (String) request.getSession().getAttribute("localJobInputDir");

    MultipartHttpServletRequest mfReq = (MultipartHttpServletRequest) request;
    String jobType = (String) mfReq.getParameter("jobType");
    String subJobId = (String) mfReq.getParameter("subJobId");

    boolean success = true;
    String error = null;
    FileInformation fileInfo = null;
    String destinationPath = null;

    MultipartFile f = mfReq.getFile("file");

    if (f != null) {
        String fileType = checkFileType(f.getOriginalFilename());
        //check if multiJob or not
        if (jobType.equals("single") || subJobId.equals(GridSubmitController.FOR_ALL)) {
            logger.debug("uploading file for single job ");
            subJobId = GridSubmitController.FOR_ALL;
            if (fileType.equals(GridSubmitController.TABLE_DIR)) {
                destinationPath = jobInputDir + GridSubmitController.TABLE_DIR + File.separator;
            } else {
                destinationPath = jobInputDir + GridSubmitController.RINEX_DIR + File.separator;
            }
        } else {
            logger.debug("uploading file for multi job ");

            String subJobInputDir = jobInputDir + subJobId.trim() + File.separator;
            if (createLocalSubJobDir(request, subJobInputDir, fileType, subJobId.trim())) {
                if (fileType.equals(GridSubmitController.TABLE_DIR)) {
                    destinationPath = subJobInputDir + GridSubmitController.TABLE_DIR + File.separator;
                } else {
                    destinationPath = subJobInputDir + GridSubmitController.RINEX_DIR + File.separator;
                }
            } else {

                logger.error("Could not create local subJob Directories.");
                success = false;
                error = new String("Could not create local subJob Directories.");
            }
        }
        if (jobInputDir != null && success) {

            logger.info("Saving uploaded file " + f.getOriginalFilename());
            //TO-DO allow to upload on tables directory as well. GUI functions to be added.
            File destination = new File(destinationPath + f.getOriginalFilename());
            if (destination.exists()) {
                logger.debug("Will overwrite existing file.");
            }
            try {
                f.transferTo(destination);
            } catch (IOException e) {
                logger.error("Could not move file: " + e.getMessage());
                success = false;
                error = new String("Could not process file.");
            }
            fileInfo = new FileInformation(f.getOriginalFilename(), f.getSize());

        } else {
            logger.error("Input directory not found or couldn't be created in current session!");
            success = false;
            error = new String("Internal error. Please reload the page.");
        }
    } else {
        logger.error("No file parameter provided.");
        success = false;
        error = new String("Invalid request.");
    }

    // We cannot use jsonView here since this is a file upload request and
    // ExtJS uses a hidden iframe which receives the response.
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    try {
        PrintWriter pw = response.getWriter();
        pw.print("{success:'" + success + "'");
        if (error != null) {
            pw.print(",error:'" + error + "'");
        }
        if (fileInfo != null) {
            pw.print(",name:'" + fileInfo.getName() + "',size:" + fileInfo.getSize() + ",subJob:'" + subJobId
                    + "'");
        }
        pw.print("}");
        pw.flush();
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
    return null;
}

From source file:org.kuali.coeus.propdev.impl.attachment.ProposalDevelopmentAttachmentController.java

@Transactional
@RequestMapping(value = "/proposalDevelopment", params = "methodToCall=addFileUploadLine")
public ModelAndView addFileUploadLine(@ModelAttribute("KualiForm") ProposalDevelopmentDocumentForm form,
        BindingResult result, MultipartHttpServletRequest request, HttpServletResponse response)
        throws Exception {
    final String selectedCollectionPath = request
            .getParameter(ProposalDevelopmentConstants.KradConstants.BINDING_PATH);

    addEditableCollectionLine(form, selectedCollectionPath);

    synchronized (ObjectPropertyUtils.getPropertyValue(form, selectedCollectionPath)) {
        return getFileControllerService().addFileUploadLine(form);
    }/*from w w  w .j av a 2  s.  c o  m*/
}