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:grails.plugin.springsecurity.SpringSecurityUtils.java

/**
 * Check if the request was triggered by an Ajax call.
 * @param request the request/*  w  w  w. j a v  a  2 s. c o m*/
 * @return <code>true</code> if Ajax
 */
public static boolean isAjax(final HttpServletRequest request) {

    String ajaxHeaderName = (String) ReflectionUtils.getConfigProperty("ajaxHeader");

    // check the current request's headers
    if ("XMLHttpRequest".equals(request.getHeader(ajaxHeaderName))) {
        return true;
    }

    Object ajaxCheckClosure = ReflectionUtils.getConfigProperty("ajaxCheckClosure");
    if (ajaxCheckClosure instanceof Closure) {
        Object result = ((Closure<?>) ajaxCheckClosure).call(request);
        if (result instanceof Boolean && ((Boolean) result)) {
            return true;
        }
    }

    // look for an ajax=true parameter
    if ("true".equals(request.getParameter("ajax"))) {
        return true;
    }

    // process multipart requests
    MultipartHttpServletRequest multipart = ((MultipartHttpServletRequest) request
            .getAttribute("org.springframework.web.multipart.MultipartHttpServletRequest"));
    if (multipart != null && "true".equals(multipart.getParameter("ajax"))) {
        return true;
    }

    // check the SavedRequest's headers
    HttpSession httpSession = request.getSession(false);
    if (httpSession != null) {
        SavedRequest savedRequest = (SavedRequest) httpSession.getAttribute(SAVED_REQUEST);
        if (savedRequest != null) {
            return !savedRequest.getHeaderValues(ajaxHeaderName).isEmpty();
        }
    }

    return false;
}

From source file:com.microsoftopentechnologies.azchat.web.controllers.RegistrationController.java

/**
 * This method populate the userBean from ajax request.
 * /*from   ww  w  .  j ava  2s.  co  m*/
 * @param userBean
 * @param request
 */
private void populateUserBean(UserBean userBean, MultipartHttpServletRequest request) {
    userBean.setUserID(request.getParameter("loggedInUserID"));
    userBean.setFirstName(request.getParameter("firstName"));
    userBean.setLastName(request.getParameter("lastName"));
    userBean.setEmail(request.getParameter("email"));
    userBean.setMultipartFile(request.getFile("userProfileImage"));
    userBean.setCountryCD(request.getParameter("country"));
    userBean.setPhoneNo(request.getParameter("phone"));
    userBean.setNameID(request.getParameter("nameID"));
}

From source file:org.openxdata.server.servlet.FormSaveServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from w  ww.j ava 2s . c  o  m*/
        String filecontents = null;
        CommonsMultipartResolver multipartResover = new CommonsMultipartResolver(/*this.getServletContext()*/);
        if (multipartResover.isMultipart(request)) {
            MultipartHttpServletRequest multipartRequest = multipartResover.resolveMultipart(request);
            filecontents = multipartRequest.getParameter("filecontents");
            if (filecontents == null || filecontents.trim().length() == 0)
                return;
        }

        String filename = "filename.xml";
        if (request.getParameter("filename") != null) {
            filename = request.getParameter("filename") + ".xml";
            filename = filename.replace(" ", "-");
        }

        HttpSession session = request.getSession();
        session.setAttribute(KEY_FILE_NAME, filename);
        session.setAttribute(KEY_FILE_CONTENTS, filecontents);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.controller.MachinePartMultiUploadController.java

@ResponseBody
@RequestMapping(value = "/multiUploadFiles", method = RequestMethod.POST)
public void upload(MultipartHttpServletRequest request, HttpServletResponse response) {
    Long part = Long.parseLong(request.getParameter("partId"));
    Entity technology = dataDefinitionService
            .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(part);
    DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "machinePartAttachment");

    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;/*from   w  w w . j av  a2 s.  c  o m*/

    while (itr.hasNext()) {

        mpf = request.getFile(itr.next());

        String path = "";
        try {
            path = fileService.upload(mpf);
        } catch (IOException e) {
            logger.error("Unable to upload attachment.", e);
        }
        if (exts.contains(Files.getFileExtension(path).toUpperCase())) {
            Entity atchment = attachmentDD.create();
            atchment.setField(TechnologyAttachmentFields.ATTACHMENT, path);
            atchment.setField(TechnologyAttachmentFields.NAME, mpf.getOriginalFilename());
            atchment.setField("product", technology);
            atchment.setField(TechnologyAttachmentFields.EXT, Files.getFileExtension(path));
            BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext());
            BigDecimal divider = new BigDecimal(1024, numberService.getMathContext());
            BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP);
            atchment.setField(TechnologyAttachmentFields.SIZE, size);
            atchment = attachmentDD.save(atchment);
            atchment.isValid();
        }
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.controller.MaintenanceEventMultiUploadController.java

@ResponseBody
@RequestMapping(value = "/multiUploadFilesForEvent", method = RequestMethod.POST)
public void upload(MultipartHttpServletRequest request, HttpServletResponse response) {
    Long eventId = Long.parseLong(request.getParameter("eventId"));
    Entity event = dataDefinitionService
            .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT)
            .get(eventId);//from ww  w  .jav a2s  . c  o  m
    DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "eventAttachment");

    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;

    while (itr.hasNext()) {

        mpf = request.getFile(itr.next());

        String path = "";
        try {
            path = fileService.upload(mpf);
        } catch (IOException e) {
            logger.error("Unable to upload attachment.", e);
        }
        if (exts.contains(Files.getFileExtension(path).toUpperCase())) {
            Entity atchment = attachmentDD.create();
            atchment.setField(TechnologyAttachmentFields.ATTACHMENT, path);
            atchment.setField(TechnologyAttachmentFields.NAME, mpf.getOriginalFilename());
            atchment.setField("maintenanceEvent", event);
            atchment.setField(TechnologyAttachmentFields.EXT, Files.getFileExtension(path));
            BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext());
            BigDecimal divider = new BigDecimal(1024, numberService.getMathContext());
            BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP);
            atchment.setField(TechnologyAttachmentFields.SIZE, size);
            atchment = attachmentDD.save(atchment);
            atchment.isValid();
        }
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.controller.PlannedEventMultiUploadController.java

@ResponseBody
@RequestMapping(value = "/multiUploadFilesForPlannedEvent", method = RequestMethod.POST)
public void upload(MultipartHttpServletRequest request, HttpServletResponse response) {
    Long eventId = Long.parseLong(request.getParameter("eventId"));
    Entity event = dataDefinitionService
            .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT)
            .get(eventId);// w  w  w  .  j a v  a2 s . com
    DataDefinition attachmentDD = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER,
            CmmsMachinePartsConstants.MODEL_PLANNED_EVENT_ATTACHMENT);

    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;

    while (itr.hasNext()) {

        mpf = request.getFile(itr.next());

        String path = "";
        try {
            path = fileService.upload(mpf);
        } catch (IOException e) {
            logger.error("Unable to upload attachment.", e);
        }
        if (exts.contains(Files.getFileExtension(path).toUpperCase())) {
            Entity atchment = attachmentDD.create();
            atchment.setField(PlannedEventAttachmentFields.ATTACHMENT, path);
            atchment.setField(PlannedEventAttachmentFields.NAME, mpf.getOriginalFilename());
            atchment.setField(PlannedEventAttachmentFields.PLANNED_EVENT, event);
            atchment.setField(PlannedEventAttachmentFields.EXT, Files.getFileExtension(path));
            BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext());
            BigDecimal divider = new BigDecimal(1024, numberService.getMathContext());
            BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP);
            atchment.setField(PlannedEventAttachmentFields.SIZE, size);
            atchment = attachmentDD.save(atchment);
            atchment.isValid();
        }
    }
}

From source file:com.qcadoo.mes.basic.controllers.WorkstationMultiUploadController.java

@ResponseBody
@RequestMapping(value = "/multiUploadFiles", method = RequestMethod.POST)
public void upload(MultipartHttpServletRequest request, HttpServletResponse response) {
    Long workstationId = Long.parseLong(request.getParameter("techId"));
    Entity workstation = dataDefinitionService
            .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION).get(workstationId);
    DataDefinition attachmentDD = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER,
            BasicConstants.MODEL_WORKSTATION_ATTACHMENT);

    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;//from   w  w w .j av  a  2  s . co m

    while (itr.hasNext()) {

        mpf = request.getFile(itr.next());

        String path = "";
        try {
            path = fileService.upload(mpf);
        } catch (IOException e) {
            logger.error("Unable to upload attachment.", e);
        }
        if (exts.contains(Files.getFileExtension(path).toUpperCase())) {
            Entity atchment = attachmentDD.create();
            atchment.setField(WorkstationAttachmentFields.ATTACHMENT, path);
            atchment.setField(WorkstationAttachmentFields.NAME, mpf.getOriginalFilename());
            atchment.setField(WorkstationAttachmentFields.WORKSTATION, workstation);
            atchment.setField(WorkstationAttachmentFields.EXT, Files.getFileExtension(path));
            BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext());
            BigDecimal divider = new BigDecimal(1024, numberService.getMathContext());
            BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP);
            atchment.setField(WorkstationAttachmentFields.SIZE, size);
            attachmentDD.save(atchment);
        }
    }
}

From source file:com.qcadoo.mes.technologies.controller.TechnologyMultiUploadController.java

@ResponseBody
@RequestMapping(value = "/multiUploadFiles", method = RequestMethod.POST)
public void upload(MultipartHttpServletRequest request, HttpServletResponse response) {
    Long technologyId = Long.parseLong(request.getParameter("techId"));
    Entity technology = dataDefinitionService
            .get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY)
            .get(technologyId);/*from   w ww . j a v a2s .com*/
    DataDefinition attachmentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER,
            TechnologiesConstants.MODEL_TECHNOLOGY_ATTACHMENT);

    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;

    while (itr.hasNext()) {

        mpf = request.getFile(itr.next());

        String path = "";
        try {
            path = fileService.upload(mpf);
        } catch (IOException e) {
            logger.error("Unable to upload attachment.", e);
        }
        if (exts.contains(Files.getFileExtension(path).toUpperCase())) {
            Entity atchment = attachmentDD.create();
            atchment.setField(TechnologyAttachmentFields.ATTACHMENT, path);
            atchment.setField(TechnologyAttachmentFields.NAME, mpf.getOriginalFilename());
            atchment.setField(TechnologyAttachmentFields.TECHNOLOGY, technology);
            atchment.setField(TechnologyAttachmentFields.EXT, Files.getFileExtension(path));
            BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext());
            BigDecimal divider = new BigDecimal(1024, numberService.getMathContext());
            BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP);
            atchment.setField(TechnologyAttachmentFields.SIZE, size);
            attachmentDD.save(atchment);
        }
    }
}

From source file:com.qcadoo.mes.basic.controllers.SubassemblyMultiUploadController.java

@ResponseBody
@RequestMapping(value = "/multiUploadFilesForSubassembly", method = RequestMethod.POST)
public void upload(MultipartHttpServletRequest request, HttpServletResponse response) {
    Long subassemblyId = Long.parseLong(request.getParameter("techId"));
    Entity subassembly = dataDefinitionService
            .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBASSEMBLY).get(subassemblyId);
    DataDefinition attachmentDD = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER,
            BasicConstants.MODEL_SUBASSEMBLY_ATTACHMENT);

    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;// w ww  . j ava2s . c  om

    while (itr.hasNext()) {

        mpf = request.getFile(itr.next());

        String path = "";
        try {
            path = fileService.upload(mpf);
        } catch (IOException e) {
            logger.error("Unable to upload attachment.", e);
        }
        if (exts.contains(Files.getFileExtension(path).toUpperCase())) {
            Entity atchment = attachmentDD.create();
            atchment.setField(SubassemblyAttachmentFields.ATTACHMENT, path);
            atchment.setField(SubassemblyAttachmentFields.NAME, mpf.getOriginalFilename());
            atchment.setField(SubassemblyAttachmentFields.SUBASSEMBLY, subassembly);
            atchment.setField(SubassemblyAttachmentFields.EXT, Files.getFileExtension(path));
            BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext());
            BigDecimal divider = new BigDecimal(1024, numberService.getMathContext());
            BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP);
            atchment.setField(SubassemblyAttachmentFields.SIZE, size);
            attachmentDD.save(atchment);
        }
    }
}

From source file:org.freeeed.ep.web.controller.ProcessingController.java

public ModelAndView execute() {
    log.info("request received... ");
    if (!(request instanceof MultipartHttpServletRequest)) {
        valueStack.put("status", "error");

        return new ModelAndView(WebConstants.PROCESS_REQUEST_RESPONSE);
    }//from   ww w.j a va 2s .co m

    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    MultipartFile file = multipartRequest.getFile("file");
    String taskId = multipartRequest.getParameter("taskId");

    ProcessingResult result = null;

    try {
        File uploadDirFile = new File(uploadDir);
        uploadDirFile.mkdirs();

        String fileName = uploadDir + File.separator + file.getOriginalFilename();
        File destination = new File(fileName);

        log.info("File transfer started... ");

        file.transferTo(destination);

        NSFTask task = new NSFTask(destination.getAbsolutePath(), workDir);
        result = processor.submitTask(taskId, task);
    } catch (Exception e) {
        log.error("Problem uploading file: ", e);
        result = new ProcessingResult();
        result.setStatus(ProcessingStatus.ERROR);
    }

    Gson gson = new Gson();
    String data = gson.toJson(result);

    valueStack.put("status", data);

    log.info("File submitted for processing!");

    return new ModelAndView(WebConstants.PROCESS_REQUEST_RESPONSE);
}