Example usage for org.springframework.web.multipart MultipartFile getBytes

List of usage examples for org.springframework.web.multipart MultipartFile getBytes

Introduction

In this page you can find the example usage for org.springframework.web.multipart MultipartFile getBytes.

Prototype

byte[] getBytes() throws IOException;

Source Link

Document

Return the contents of the file as an array of bytes.

Usage

From source file:com.orchestra.portale.controller.EditEventController.java

@RequestMapping(value = "/updateevent", method = RequestMethod.POST)
public ModelAndView updateEvent(HttpServletRequest request, @RequestParam Map<String, String> params,
        @RequestParam(value = "file", required = false) MultipartFile[] files,
        @RequestParam(value = "cover", required = false) MultipartFile cover,
        @RequestParam(value = "fileprec", required = false) String[] fileprec,
        @RequestParam(value = "imgdel", required = false) String[] imgdel) throws InterruptedException {

    CompletePOI poi = pm.getCompletePoiById(params.get("id"));
    CoverImgComponent coverimg = new CoverImgComponent();
    ArrayList<AbstractPoiComponent> listComponent = new ArrayList<AbstractPoiComponent>();
    for (AbstractPoiComponent comp : poi.getComponents()) {

        //associazione delle componenti al model tramite lo slug
        String slug = comp.slug();
        int index = slug.lastIndexOf(".");
        String cname = slug.substring(index + 1).replace("Component", "").toLowerCase();
        if (cname.equals("coverimg")) {
            coverimg = (CoverImgComponent) comp;
        }/*from   w  ww  . jav a  2s  . co  m*/
    }
    ModelAndView model = new ModelAndView("editedpoi");

    poi.setId(params.get("id"));

    ModelAndView model2 = new ModelAndView("errorViewPoi");

    poi.setName(params.get("name"));
    poi.setVisibility("1");
    poi.setAddress(params.get("address"));
    double lat = Double.parseDouble(params.get("latitude"));
    double longi = Double.parseDouble(params.get("longitude"));
    poi.setLocation(new double[] { lat, longi });
    poi.setStart_date(params.get("datai"));
    poi.setEnd_date(params.get("dataf"));
    poi.setShortDescription(params.get("shortd"));
    int i = 1;
    ArrayList<String> categories = new ArrayList<String>();
    while (params.containsKey("category" + i)) {

        categories.add(params.get("category" + i));

        model.addObject("nome", categories.get(i - 1));
        i = i + 1;
    }
    poi.setCategories(categories);

    //componente cover
    if (!cover.isEmpty()) {

        coverimg.setLink("cover.jpg");

    }
    listComponent.add(coverimg);
    //componente galleria immagini
    ImgGalleryComponent img_gallery = new ImgGalleryComponent();
    ArrayList<ImgGallery> links = new ArrayList<ImgGallery>();
    i = 0;

    if (files != null && files.length > 0) {
        while (i < files.length) {
            ImgGallery img = new ImgGallery();
            Thread.sleep(100);
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyyhmmssSSa");
            String currentTimestamp = sdf.format(date);
            img.setLink("img_" + currentTimestamp + ".jpg");
            if (params.containsKey("newcredit" + (i + 1))) {
                img.setCredit(params.get("newcredit" + (i + 1)));
            }
            i = i + 1;
            links.add(img);
        }
    }
    int iximg = 0;
    if (fileprec != null && fileprec.length > 0) {
        while (iximg < fileprec.length) {
            ImgGallery img = new ImgGallery();
            img.setLink(fileprec[iximg]);
            if (params.containsKey("credit" + (iximg + 1))) {
                img.setCredit(params.get("credit" + (iximg + 1)));
            }
            iximg = iximg + 1;
            links.add(img);
        }
    }
    if ((fileprec != null && fileprec.length > 0) || (files != null && files.length > 0)) {
        img_gallery.setLinks(links);
        listComponent.add(img_gallery);
    }
    //componente contatti
    ContactsComponent contacts_component = new ContactsComponent();
    //Recapiti telefonici
    i = 1;
    boolean contacts = false;
    if (params.containsKey("tel" + i)) {
        ArrayList<PhoneContact> phoneList = new ArrayList<PhoneContact>();

        while (params.containsKey("tel" + i)) {
            PhoneContact phone = new PhoneContact();
            if (params.containsKey("tel" + i)) {
                phone.setLabel(params.get("desctel" + i));
            }
            phone.setNumber(params.get("tel" + i));
            phoneList.add(phone);
            i = i + 1;
        }
        contacts = true;
        contacts_component.setPhoneList(phoneList);
    }
    //Recapiti mail
    i = 1;
    if (params.containsKey("email" + i)) {
        ArrayList<EmailContact> emailList = new ArrayList<EmailContact>();

        while (params.containsKey("email" + i)) {
            EmailContact email = new EmailContact();
            if (params.containsKey("email" + i)) {
                email.setLabel(params.get("descemail" + i));
            }
            email.setEmail(params.get("email" + i));
            emailList.add(email);
            i = i + 1;
        }
        contacts = true;
        contacts_component.setEmailsList(emailList);
    }
    //Recapiti fax
    i = 1;
    if (params.containsKey("fax" + i)) {
        ArrayList<FaxContact> faxList = new ArrayList<FaxContact>();

        while (params.containsKey("fax" + i)) {
            FaxContact fax = new FaxContact();
            if (params.containsKey("fax" + i)) {
                fax.setLabel(params.get("descfax" + i));
            }
            fax.setFax(params.get("fax" + i));
            faxList.add(fax);
            i = i + 1;
        }
        contacts = true;
        contacts_component.setFaxList(faxList);
    }
    //Social predefiniti
    i = 1;
    if (params.containsKey("SN" + i)) {

        while (params.containsKey("SN" + i)) {
            if (params.get("SN" + i).equals("facebook")) {
                contacts = true;
                contacts_component.setFacebook(params.get("LSN" + i));
            }
            if (params.get("SN" + i).equals("twitter")) {
                contacts = true;
                contacts_component.setTwitter(params.get("LSN" + i));
            }
            if (params.get("SN" + i).equals("google")) {
                contacts = true;
                contacts_component.setGoogle(params.get("LSN" + i));
            }
            if (params.get("SN" + i).equals("skype")) {
                contacts = true;
                contacts_component.setSkype(params.get("LSN" + i));
            }
            i = i + 1;
        }
    }
    //Social personalizzati
    i = 1;
    if (params.containsKey("CSN" + i)) {
        ArrayList<GenericSocial> customsocial = new ArrayList<GenericSocial>();

        while (params.containsKey("CSN" + i)) {
            GenericSocial social = new GenericSocial();
            contacts = true;
            social.setLabel(params.get("CSN" + i));
            social.setSocial(params.get("LCSN" + i));
            customsocial.add(social);
            i = i + 1;
        }
        contacts_component.setSocialList(customsocial);
    }
    if (contacts == true) {
        listComponent.add(contacts_component);
    }
    //DESCRIPTION COMPONENT
    i = 1;
    if (params.containsKey("par" + i)) {
        ArrayList<Section> list = new ArrayList<Section>();

        while (params.containsKey("par" + i)) {
            Section section = new Section();
            if (params.containsKey("titolo" + i)) {
                section.setTitle(params.get("titolo" + i));
            }
            section.setDescription(params.get("par" + i));
            list.add(section);
            i = i + 1;

        }
        DescriptionComponent description_component = new DescriptionComponent();
        description_component.setSectionsList(list);
        listComponent.add(description_component);
    }
    //Orari
    i = 1;
    int k = 1;
    boolean ok = false;
    String gg = "";
    boolean[] aperto = new boolean[8];

    EventsDateComponent workingtime = new EventsDateComponent();
    if (params.containsKey("WD" + i + "start" + k + "H")) {
        ArrayList<EventsDates> workingdays = new ArrayList<EventsDates>();

        while (params.containsKey("WD" + i)) {
            ArrayList<EventsHours> Listwh = new ArrayList<EventsHours>();
            k = 1;
            while (params.containsKey("WD" + i + "start" + k + "H")) {
                EventsHours wh = new EventsHours();
                wh.setStart(params.get("WD" + i + "start" + k + "H") + ":"
                        + params.get("WD" + i + "start" + k + "M"));
                wh.setEnd(
                        params.get("WD" + i + "end" + k + "H") + ":" + params.get("WD" + i + "end" + k + "M"));
                Listwh.add(wh);
                k = k + 1;
            }
            EventsDates cwd = new EventsDates();
            cwd.setDate(params.get("WD" + i));
            cwd.setHours(Listwh);
            workingdays.add(cwd);
            i = i + 1;
        }

        workingtime.setDates(workingdays);
        listComponent.add(workingtime);
    }

    i = 1;
    if (params.containsKey("type" + i)) {

        PricesComponent pc = new PricesComponent();
        ArrayList<TicketPrice> tpList = new ArrayList<TicketPrice>();
        while (params.containsKey("type" + i)) {
            TicketPrice tp = new TicketPrice();
            tp.setType(params.get("type" + i));
            double dp = Double.parseDouble(params.get("price" + i));
            tp.setPrice(dp);
            tp.setType_description(params.get("typedesc" + i));
            tpList.add(tp);
            i = i + 1;
        }
        pc.setPrices(tpList);
        listComponent.add(pc);
    }

    i = 1;
    if (params.containsKey("SERV" + i)) {
        ArrayList<String> servList = new ArrayList<String>();
        while (params.containsKey("SERV" + i)) {
            servList.add(params.get("SERV" + i));
            i = i + 1;
        }
        ServicesComponent servicescomponent = new ServicesComponent();
        servicescomponent.setServicesList(servList);
        listComponent.add(servicescomponent);
    }
    poi.setComponents(listComponent);

    pm.savePoi(poi);

    CompletePOI poi2 = (CompletePOI) pm.findOneCompletePoiByName(poi.getName());

    // POI INGLESE 
    if (params.get("inglese").equals("true")) {
        addeng(params, poi2.getId(), coverimg, img_gallery);
    } else {
        EnCompletePOI enpoi = new EnCompletePOI();
        enpoi.setAddress(poi.getAddress());
        enpoi.setCategories(poi.getCategories());
        enpoi.setId(poi.getId());
        enpoi.setName(poi.getName());
        enpoi.setShortDescription(poi.getShortDescription());
        enpoi.setStart_date(poi.getStart_date());
        enpoi.setEnd_date(poi.getEnd_date());
        double enlat = Double.parseDouble(params.get("latitude"));
        double enlongi = Double.parseDouble(params.get("longitude"));
        poi.setLocation(new double[] { enlat, enlongi });
        enpoi.setComponents(listComponent);

        pm.saveEnPoi(enpoi);
    }
    for (int z = 0; z < files.length; z++) {
        MultipartFile file = files[z];

        try {
            byte[] bytes = file.getBytes();

            // Creating the directory to store file
            HttpSession session = request.getSession();
            ServletContext sc = session.getServletContext();

            File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "poi" + File.separator + "img"
                    + File.separator + poi2.getId());
            if (!dir.exists()) {
                dir.mkdirs();
            }

            // Create the file on server
            File serverFile = new File(dir.getAbsolutePath() + File.separator + links.get(z).getLink());
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();

        } catch (Exception e) {
            return model;
        }
    }
    if (!cover.isEmpty()) {
        MultipartFile file = cover;

        try {
            byte[] bytes = file.getBytes();

            // Creating the directory to store file
            HttpSession session = request.getSession();
            ServletContext sc = session.getServletContext();

            File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "poi" + File.separator + "img"
                    + File.separator + poi2.getId());
            if (!dir.exists()) {
                dir.mkdirs();
            }

            // Create the file on server
            File serverFile = new File(dir.getAbsolutePath() + File.separator + "cover.jpg");
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();

        } catch (Exception e) {
            return model;
        }
    }

    // DELETE IMMAGINI DA CANCELLARE
    if (imgdel != null && imgdel.length > 0) {
        for (int kdel = 0; kdel < imgdel.length; kdel++) {
            delimg(request, poi.getId(), imgdel[kdel]);
        }
    }
    return model;
}

From source file:com.abixen.platform.core.domain.model.User.java

public void changeAvatar(String imageLibraryDirectory, MultipartFile avatarFile) throws IOException {
    final File currentAvatarFile = new File(imageLibraryDirectory + "/user-avatar/" + getAvatarFileName());
    if (currentAvatarFile.exists()) {
        if (!currentAvatarFile.delete()) {
            throw new FileExistsException();
        }/*from ww  w  .j  a  va 2s .  com*/
    }
    final PasswordEncoder encoder = new BCryptPasswordEncoder();
    final String newAvatarFileName = encoder.encode(avatarFile.getName() + new Date().getTime())
            .replaceAll("\"", "s").replaceAll("/", "a").replace(".", "sde");
    final File newAvatarFile = new File(imageLibraryDirectory + "/user-avatar/" + newAvatarFileName);
    final FileOutputStream out = new FileOutputStream(newAvatarFile);
    out.write(avatarFile.getBytes());
    out.close();
    setAvatarFileName(newAvatarFileName);
}

From source file:org.trpr.platform.batch.impl.spring.web.JobConfigController.java

/**
 * Controller for new job. Just adds an attribute jobName to the model. And redirects to the job edit page.
 *//*from   ww  w. j  av  a  2s.  c  om*/
@RequestMapping(value = "/configuration/modify_job", method = RequestMethod.POST)
public String addNewJob(ModelMap model, @RequestParam MultipartFile jobFile) {
    String jobFileName = jobFile.getOriginalFilename();
    //Check if file is empty or doesn't have an extension
    if (jobFile.isEmpty() || (jobFileName.lastIndexOf('.') < 0)) {
        model.remove("jobFile");
        model.addAttribute("Error", "File is Empty or invalid. Only .xml files can be uploaded");
        return "redirect:/configuration";
    } else if (!jobFileName.substring(jobFileName.lastIndexOf('.')).equals(".xml")) { //Check if file is .xml
        model.remove("jobFile");
        model.addAttribute("Error", "Only .xml files can be uploaded");
        return "redirect:/configuration";
    } else { //Read file to view
        boolean invalidJobFile = false;
        List<String> jobNameList = null;
        try {
            byte[] buffer = jobFile.getBytes();
            String XMLFileContents = new String(buffer);
            model.addAttribute("XMLFileContents", XMLFileContents);
            jobNameList = ConfigFileUtils.getJobName(new ByteArrayResource(jobFile.getBytes()));
            if (jobNameList == null || jobNameList.size() == 0) {
                throw new PlatformException("Empty list");
            }
        } catch (UnsupportedEncodingException e) {
            invalidJobFile = true;
        } catch (IOException e) {
            invalidJobFile = true;
        } catch (PlatformException p) {
            invalidJobFile = true;
        }
        for (String jobName : jobNameList) {
            if (jobName == null || invalidJobFile) {
                model.clear();
                model.addAttribute("Error", "invalid jobFile. Couldn't find job's name");
                return "redirect:/configuration";
            }
            if (jobService.contains(jobName)) {
                model.clear();
                model.addAttribute("Error",
                        "The JobName '" + jobName + "' already exists. Please choose another name");
                return "redirect:/configuration";
            }
        }
        model.addAttribute("jobName", jobNameList);
        return "configuration/modify/jobs/job";
    }
}

From source file:mx.edu.um.mateo.activos.web.ActivoController.java

@RequestMapping(value = "/subeActivos", method = RequestMethod.POST)
public String sube(HttpServletResponse response, RedirectAttributes redirectAttributes, MultipartFile archivo,
        @RequestParam Integer codigo) throws IOException, ActivoNoCreadoException {
    redirectAttributes.addFlashAttribute("message", "activo.sube.archivo.message");
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition",
            "attachment; filename='errores-" + archivo.getOriginalFilename() + "'");
    OutputStream out = response.getOutputStream();
    activoDao.sube(archivo.getBytes(), ambiente.obtieneUsuario(), response.getOutputStream(), codigo);
    out.flush();/*from   ww  w. jav a  2 s .  c  o m*/

    return "redirect:/activoFijo/activo";
}

From source file:com.denimgroup.threadfix.service.DocumentServiceImpl.java

@Override
public String saveFileToVuln(Integer vulnId, MultipartFile file) {
    if (vulnId == null || file == null) {
        log.warn("The document upload file failed to save, it had null input.");
        return null;
    }//from   w  ww . j av  a 2 s . co m

    if (!contentTypeService.isValidUpload(file.getContentType())) {
        log.warn("Invalid filetype for upload: " + file.getContentType());
        return null;
    }

    Vulnerability vulnerability = vulnerabilityDao.retrieveById(vulnId);

    if (vulnerability == null) {
        log.warn("Unable to retrieve Vulnerability - document save failed.");
        return null;
    }

    Document doc = new Document();
    String fileFullName = file.getOriginalFilename();
    doc.setVulnerability(vulnerability);
    doc.setName(getFileName(fileFullName));
    doc.setType(getFileType(fileFullName));
    doc.setContentType(contentTypeService.translateContentType(file.getContentType()));
    try {
        Blob blob = new SerialBlob(file.getBytes());
        doc.setFile(blob);

        List<Document> appDocs = vulnerability.getDocuments();
        if (appDocs == null)
            appDocs = new ArrayList<Document>();
        appDocs.add(doc);

        documentDao.saveOrUpdate(doc);
        vulnerabilityDao.saveOrUpdate(vulnerability);

    } catch (SQLException | IOException e) {
        log.warn("Unable to save document - exception occurs.");
        return null;
    }

    return fileFullName;
}

From source file:mx.edu.um.mateo.activos.web.ActivoController.java

@RequestMapping("/subeImagen")
public String subeImagen(@RequestParam Long activoId,
        @RequestParam(value = "imagen", required = false) MultipartFile archivo,
        RedirectAttributes redirectAttributes) {
    log.debug("Subiendo imagen para activo {}", activoId);
    try {//from  www.ja v  a 2 s .c  om
        if (archivo != null && !archivo.isEmpty()) {
            Usuario usuario = ambiente.obtieneUsuario();
            Activo activo = activoDao.obtiene(activoId);
            Imagen imagen = new Imagen(archivo.getOriginalFilename(), archivo.getContentType(),
                    archivo.getSize(), archivo.getBytes());
            activo.getImagenes().add(imagen);
            activoDao.subeImagen(activo, usuario);
        }
        redirectAttributes.addFlashAttribute("message", "activo.sube.imagen.message");
        redirectAttributes.addFlashAttribute("messageStyle", "alert-success");
    } catch (IOException e) {
        log.error("Hubo un problema al intentar subir la imagen del activo", e);
    }
    return "redirect:/activoFijo/activo/ver/" + activoId;
}

From source file:it.geosolutions.opensdi.operations.OperationEngineController.java

/**
 * Handler for plupload files//  w w  w. j a v  a 2 s.c o  m
 * 
 * @param operationId
 * @param gotHeaders
 * @param file uploaded
 * @param request
 * @param model
 * @return
 */
@RequestMapping(value = "/operation/{operationId}/upload", method = RequestMethod.POST)
public String issuePostToOperation(@PathVariable(value = "operationId") String operationId,
        @RequestHeader HttpHeaders gotHeaders, @RequestParam MultipartFile file, @RequestParam String name,
        @RequestParam(required = false, defaultValue = "-1") int chunks,
        @RequestParam(required = false, defaultValue = "-1") int chunk, HttpServletRequest request,
        ModelMap model) {

    FileUpload uploadFile = new FileUpload();
    List<MultipartFile> files = new LinkedList<MultipartFile>();
    if (chunks > 0) {
        List<byte[]> uploadedChunks = this.uploadedChunks.get(name);
        if (uploadedChunks == null) {
            // init bytes for the chunk upload
            uploadedChunks = new LinkedList<byte[]>();
        }
        try {
            // add chunk on its position
            uploadedChunks.add(chunk, file.getBytes());
            this.uploadedChunks.put(name, uploadedChunks);
        } catch (IOException e) {
            LOGGER.error("Error on file upload", e);
        }
        if (chunk == chunks - 1) {
            // Create the upload file to be handled
            MultipartFile composedUpload = new CommonsMultipartFile(getFileItem(file, uploadedChunks, name));
            files.add(composedUpload);
            uploadFile.setFiles(files);
        }
    } else {
        // Create the upload file to be handled
        files.add(file);
        uploadFile.setFiles(files);
    }

    return issuePostToOperation(operationId, null, gotHeaders, uploadFile, request, model);
}

From source file:com.alehuo.wepas2016projekti.controller.UploadController.java

/**
 * Kuvan latauksen ksittely/* www  .  j  a va 2 s  .  com*/
 * @param a Autentikointi
 * @param m Malli
 * @param formData Lomakkeen data
 * @param bs BindingResult
 * @param l Locale
 * @return
 */
@RequestMapping(method = RequestMethod.POST)
public String processUpload(Authentication a, Model m, @Valid @ModelAttribute ImageUploadFormData formData,
        BindingResult bs, Locale l) {
    //Hae autentikointi
    UserAccount u = userService.getUserByUsername(a.getName());
    m.addAttribute("user", u);
    if (bs.hasErrors()) {
        LOG.log(Level.WARNING,
                "Kayttaja ''{0}'' yritti ladata kuvaa, mutta syotteita ei validoitu. Onko otsikko tyhja?",
                a.getName());
        return "upload";
    }
    MultipartFile file = formData.getFile();
    String description = formData.getDescription();

    //Tiedostomuodon tarkistus
    if (!(file.getContentType().equals("image/jpg") || file.getContentType().equals("image/png")
            || file.getContentType().equals("image/jpeg") || file.getContentType().equals("image/bmp")
            || file.getContentType().equals("image/gif"))) {
        if (l.toString().equals("fi")) {
            bs.rejectValue("file", "error.file", "Tiedostomuotoa ei sallita.");
        } else {
            bs.rejectValue("file", "error.file", "File type not permitted.");
        }

        if (bs.hasErrors()) {
            LOG.log(Level.WARNING,
                    "Kayttaja ''{0}'' yritti ladata kuvaa, mutta tiedostomuotoa ''{1}'' ei sallita.",
                    new Object[] { a.getName(), file.getContentType() });
            return "upload";
        }
    } else {
        //Tallenna kuva
        Image i;
        try {
            i = imageService.addImage(u, file.getBytes(), file.getContentType(), description);
            LOG.log(Level.INFO, "Kayttaja ''{0}'' latasi uuden kuvan palveluun. Kuvan tunniste: ''{1}''",
                    new Object[] { a.getName(), i.getUuid() });
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
            LOG.log(Level.SEVERE,
                    "Kayttaja ''{0}'' yritti ladata kuvaa palveluun, mutta tapahtui palvelinvirhe.",
                    a.getName());
            if (l.toString().equals("fi")) {
                bs.rejectValue("file", "error.file", "Kuvan lhetys eponnistui.");
            } else {
                bs.rejectValue("file", "error.file", "Image upload failed.");
            }

            return "upload";
        }

    }

    return "redirect:/";
}

From source file:com.jaspersoft.jasperserver.war.action.DataSourceAction.java

public Event uploadJDBCDrivers(RequestContext context) throws Exception {
    String driverClassName = context.getRequestParameters().get("className");
    if (driverClassName == null || driverClassName.isEmpty()) {
        throw new Exception("Class name is empty.");
    }/* w w w.  ja va  2  s . co  m*/

    Map<String, byte[]> driverFilesData = new HashMap<String, byte[]>();

    int i = 0;
    MultipartFile multipartFile = context.getRequestParameters().getMultipartFile(UPLOAD_DRIVER_PREFIX + i);
    while (multipartFile != null) {
        driverFilesData.put(multipartFile.getOriginalFilename(), multipartFile.getBytes());

        i++;
        multipartFile = context.getRequestParameters().getMultipartFile(UPLOAD_DRIVER_PREFIX + i);
    }

    String errorMessage = "";
    try {
        jdbcDriverService.setDriver(driverClassName, driverFilesData);
    } catch (NoClassDefFoundError e) {
        errorMessage = messages.getMessage("resource.dataSource.jdbc.classNotFound",
                new String[] { e.getMessage() }, LocaleContextHolder.getLocale());
        logger.error(errorMessage);
    } catch (ClassNotFoundException e) {
        errorMessage = messages.getMessage("resource.dataSource.jdbc.classNotFound",
                new String[] { e.getMessage() }, LocaleContextHolder.getLocale());
        logger.error(errorMessage);
    } catch (Exception e) {
        errorMessage = e.getMessage();
        logger.error(errorMessage);
    }

    Map<String, Map<String, Object>> availableDrivers = getAvailableJdbcDrivers();

    JSONObject json = new JSONObject();
    json.put("result", isEmpty(errorMessage));
    json.put("errorMessage", errorMessage);
    json.put(JDBC_DRIVERS_JSON_KEY, JSONUtil.toJSON(availableDrivers));
    context.getRequestScope().put(AJAX_RESPONSE_MODEL, json.toString());
    context.getFlowScope().put(JDBC_DRIVERS_JSON_KEY, JSONUtil.toJSON(availableDrivers));

    return success();
}