Package com.vst.webapp.action

Source Code of com.vst.webapp.action.UpdateFormController

package com.vst.webapp.action;


import com.vst.util.FileHelper;
import com.vst.webapp.util.FTPUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class UpdateFormController implements Controller {
    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse httpServletResponse) throws Exception {
        ModelAndView mav = new ModelAndView("updateForm");
        if (request.getParameter("update") != null) {

            Properties properties = new Properties();
            properties.load(new FileInputStream(FileHelper.getCurrentPath(request) + "WEB-INF/classes/ApplicationResources.properties"));

            FTPUtil ftpUtil = new FTPUtil(
                    properties.getProperty("update.ftpAddress"),
                    properties.getProperty("update.ftpUser"),
                    properties.getProperty("update.ftpPassword"));

            ftpUtil.setIgnoreFiles(properties.getProperty("update.ignoreFiles"));
            ftpUtil.setLogFile(properties.getProperty("update.logFile"));
            ftpUtil.copyFromFTP(
                    properties.getProperty("update.ftpFolder"),
                    FileHelper.getCurrentPath(request));

            mav.addObject("message", "Updated!");

            File batRestartFile = new File(FileHelper.getCurrentPath(request) + "restart_tomcat.bat");

            try {
                new ProcessBuilder(batRestartFile.getAbsolutePath()).start();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
        return mav;
    }
}
TOP

Related Classes of com.vst.webapp.action.UpdateFormController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.