head 1.3;
access;
symbols;
locks
webflow:1.3; strict;
comment @# @;
1.3
date 99.05.26.18.23.58; author webflow; state Exp;
branches;
next 1.2;
1.2
date 99.05.06.21.26.53; author webflow; state Exp;
branches;
next 1.1;
1.1
date 99.04.21.17.33.29; author webflow; state Exp;
branches;
next ;
desc
@Administrator servlet
Starts/kills QSmaster server
@
1.3
log
@changed test.Server into Server; added title to xwindow
@
text
@//Project Webflow
//Leader Tom Haupt
//Prepared by Farhad Mamedbokov
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import WebFlow.*;
import WebFlow.event.*;
import org.omg.CORBA.*;
public class Admin extends HttpServlet
{
private String sMasterRef = new String("/npac/home/webflow/WEBFLOW/JIGSAW/Jigsaw/WWW/IOR/master.txt");
private String cmd_line = "java WebFlow.Server /npac/home/webflow/WEBFLOW/JIGSAW/Jigsaw/WWW/WFconf/QSmaster.txt";
private HttpServletResponse res;
protected void doGet(HttpServletRequest req, HttpServletResponse r)
throws ServletException, IOException
{
res=r;
String command = req.getParameter("command");
if (command==null) command=" ";
String status = new String();
if(command.equals("start"))
status = startServer (cmd_line);
else if(command.equals("read"))
status= readServer(sMasterRef);
else if(command.equals("ping"))
status=pingServer(sMasterRef);
else if(command.equals("kill"))
status=killServer(sMasterRef);
else
status = getHelpLine();
PrintPlainText(status);
}
//-------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 Str2Obj(String sObjRef)
{
String[] args = new String[1];
args[0] = new String("");
ORB 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 ReadSTRFromFile(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 "";
}
try {
theFile.close();
fileReader.close();
}
catch (IOException e) {}
//return the reference string
return sObjRef;
}
//----if URL is osprey4.npac.syr.edu:2956/servlets/Admin?command=start
//----starts the WebFlowServer------------------------------------
public String startServer( String cmd_line)
{
System.err.println("Starting WebFlowServer");
try
{
Process prc_module_fac = Runtime.getRuntime().exec("xterm -d aga.npac.syr.edu:0 -title WebFlow_Master -e "+cmd_line);
return ("Executed: \n " + cmd_line);
}
catch (Exception ex)
{
System.err.println("Error in starting WebFlowServer :"+ex);
return ("Cannot start " + cmd_line);
}
}
//---if URL is osprey4.npac.syr.edu:2956/servlets/fm3?command=read
//---gets the server reference String to the server--------------
public String readServer(String sMasterRef)
{
System.err.println("Reading the String from a file "+sMasterRef);
String MasterRef = ReadSTRFromFile(sMasterRef);
return (MasterRef.equals(""))? "Cannot read from the file\n"+sMasterRef
: "Reference line is:\n"+MasterRef;
}
//----if URL is osprey4.npac.syr.edu:2956/servlets/fm3?command=ping
//-----pings the server to see if its alive
public String pingServer (String sMasterRef)
{
String MasterRef = ReadSTRFromFile(sMasterRef);
System.err.println("Pinging the server");
if (MasterRef.equals(""))
return ("Cannot read reference from the file\n" + sMasterRef);
else
{
WebFlowContext ws=Str2Obj(MasterRef);
if (ws == null)
return "Cannot Connect to Object";
else
{
boolean non_exist = true;
try{
non_exist = ws._non_existent();
}
catch(org.omg.CORBA.COMM_FAILURE ex){}
catch(org.omg.CORBA.OBJECT_NOT_EXIST ex){}
if (!non_exist)
return ("Reference String in the file\n " + sMasterRef + "\nis:\n " + MasterRef + "\n" + "Object is active");
else
return ("Reference String in the file\n " + sMasterRef + "\nis:\n " + MasterRef + "\n" + "Object is NOT ACTIVE");
}
} //else
} //pingServer
//----if URL is osprey4.npac.syr.edu:2956/servlets/Admin?command=kill
//-----pings the server to see if its alive
public String killServer( String sMasterRef)
{
System.out.println("Killing the server");
String MasterRef = ReadSTRFromFile(sMasterRef);
if (MasterRef.equals(""))
return "Cannot read reference from the file\n" + sMasterRef;
else
{
WebFlowContext ws = Str2Obj(MasterRef);
if (ws==null)
return "ws is null";
else
{
try {
ws.removeMyself();
return "Server is killed";
}
catch (org.omg.CORBA.COMM_FAILURE ex) {
return "Server is killed";
//status+=" " + ex;
}
catch (Exception ex) {
return ("Something wrong with terminating method: "+ex);
}
} //else
} //else
} //kill
//----- if URL is osprey4.npac.syr.edu:2956/servlets/fm3
//------or some erroneuos command-----------------------
public String getHelpLine()
{
return "Available commands are:\n" +
" ?command=start to start server\n" +
" ?command=read to read server reference String\n" +
" ?command=ping to ping server\n" +
" ?command=kill to kill server\n";
} //getHelpLine
public String getServletInfo()
{
return "fm1 -0.0 by Leha & Farhad";
}
}
@
1.2
log
@udated due to changes in the NPAC file system.
opens a new window
@
text
@d18 1
a18 1
private String cmd_line = "java WebFlow.test.Server /npac/home/webflow/WEBFLOW/JIGSAW/Jigsaw/WWW/WFconf/QSmaster.txt";
d133 1
a133 1
Process prc_module_fac = Runtime.getRuntime().exec("xterm -d aga.npac.syr.edu:0 -e "+cmd_line);
@
1.1
log
@Initial revision
@
text
@d17 2
a18 2
private String sMasterRef = new String("/home/T11F/webflow/WEBFLOW/JIGSAW/Jigsaw/WWW/IOR/master.txt");
private String cmd_line = "java WebFlow.test.Server /home/T11F/webflow/WEBFLOW/JIGSAW/Jigsaw/WWW/WFconf/QSmaster.txt";
d133 1
a133 1
Process prc_module_fac = Runtime.getRuntime().exec(cmd_line);
@