package com.eastcom_sw.stream.webservices.controller; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.eastcom_sw.common.web.BaseController; @Controller @RequestMapping(value = "/reenDataController") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class ReenDataController extends BaseController { /** * <p>Description:重启tomcat </p> * <p>Title: resetTomcat</p> * @param session * @param request * @param response */ @RequestMapping(value="/resetTomcat") public void resetTomcat(HttpSession session, HttpServletRequest request, HttpServletResponse response){ String message=""; BufferedReader br= null; Process process = null; try { String shPath= "/home/tomcat_ws/bin/start_tomcatws.sh"; //tomecat启动脚本路径 System.out.println("=============启动脚本路径:"+shPath); process = Runtime.getRuntime().exec(shPath.toString()); br = new BufferedReader(new InputStreamReader(process.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sb.append(line).append(" "); } String result = sb.toString(); System.out.println("=============启动脚本-执行结果:"+result); if(process != null){ int extValue = process.waitFor(); //返回码 0 表示正常退出 1表示异常退出 if(0 == extValue){ System.out.println("=============启动脚本-执行完毕!"); }else{ System.out.println("=============启动脚本-执行异常!"); message="启动脚本执行异常"; } } this.addResultInfo(SUCCESS,message,""); }catch (IOException e) { // TODO Auto-generated catch block message= "启动脚本执行异常"; e.printStackTrace(); this.addResultInfo(FAILURE, message, ""); } catch (InterruptedException e) { // TODO Auto-generated catch block message= "启动脚本异常退出 "; e.printStackTrace(); this.addResultInfo(FAILURE, message, ""); }finally { try { br.close(); process.destroy(); } catch (Exception e) { log.error("流或process销毁异常",e.getMessage()); } } this.responseResult(response, this.getResultJSONStr()); } }