package com.vst.webapp.gateway.xml;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import com.vst.webapp.util.OSCmdRunner;
public class JsScriptSyncController extends AbstractController {
private String workDir;
private String scriptName;
public void setWorkDir(String workDir) {
this.workDir = workDir;
}
public void setScriptName(String scriptName) {
this.scriptName = scriptName;
}
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
try {
if (workDir == null || workDir.length() == 0) {
return new ModelAndView("textAnswer", "text",
"Can't run script working dirrectory not setting.");
}
if (scriptName == null || scriptName.length() == 0) {
return new ModelAndView("textAnswer", "text",
"Sorry script name not setting.");
}
OSCmdRunner runner = new OSCmdRunner();
runner.setWorkDir(workDir);
runner.setScriptName(scriptName);
int resCode = runner.execOsScript();
String answerText = "Script " + scriptName
+ " processed. Result code: " + resCode + ".";
return new ModelAndView("textAnswer", "text", answerText);
} catch (Exception e) {
return new ModelAndView("textAnswer", "text", e.getMessage());
}
}
}