//Project Webflow //Leader Tom Haupt import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import WebFlow.*; import WebFlow.event.*; import org.omg.CORBA.*; public class slave1 extends HttpServlet { // private String sMasterRef = new String("/home/T11F/webflow/WEBFLOW/JIGSAW/Jigsaw/WWW/Praveen/slave.ref"); private String cmd_line = "java WebFlow.Server /home/T11F/webflow/WEBFLOW/JIGSAW/Jigsaw/WWW/Praveen/QSslave.conf"; private WebFlowContext ws; private HttpServletResponse res; private ORB orb; String newLine; protected void doGet(HttpServletRequest req, HttpServletResponse r) throws ServletException, IOException { String status = new String(); String command = req.getParameter("command"); res=r; //----if URL is osprey4.npac.syr.edu:2956/servlets/fm3?command=start //----starts the WebFlowServer------------------------------------ System.out.println("out"); System.err.println("err"); try { Process prc_module_fac = Runtime.getRuntime().exec(cmd_line); status = "Executed: \n " + cmd_line; System.err.println(status); /* DataInputStream os= new DataInputStream(prc_module_fac.getInputStream()); System.err.println("os"); while( (newLine=os.readLine()) != null){ System.err.println(newLine);} */ PrintInBrowser(status); } catch (Exception ex) { System.err.println("Error in starting WebFlowServer :"+ex); status = "Cannot start " + cmd_line; } } //-------Prints the string status for the applet window------ public void PrintPlainText(String status) throws IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println(status); out.close(); } //-------Prints the string status in the browser window------ public void PrintInBrowser(String status) throws IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("Hello Client!"+ "

Hello Client! -0.0

" + status + ""); out.close(); } //------Pings the WebFlowServer with sObjRef reference ----------- protected WebFlowContext StringtoObj(String sObjRef) { String[] args = new String[1]; args[0] = new String(""); orb = ORB.init(args, new java.util.Properties()); if(orb == null) { System.err.println("ORB connecting error"); return null ; //"ORB connecting error"; } else { System.err.println("ORB is created successfully"); org.omg.CORBA.Object obj = orb.string_to_object(sObjRef); ; return WebFlowContextHelper.narrow(obj); } } //----------------reads object reference from a file------------ public String ReadStringFromFile(String sMasterRef) throws FileNotFoundException, IOException { //open a file FileInputStream theFile; BufferedReader fileReader; String sObjRef; try { theFile=new FileInputStream(sMasterRef); fileReader=new BufferedReader(new InputStreamReader(theFile)); } catch(FileNotFoundException e){ return ""; } //read a reference string try { sObjRef=fileReader.readLine(); System.err.println("Got the reference: "+sObjRef); } catch (IOException e) { return ""; } theFile.close(); fileReader.close(); //return the reference string return sObjRef; } public String getServletInfo() { return "fm1 -0.0 by Leha & Farhad"; } }