import WebFlow.*; import WebFlow.event.*; import WebFlow.xml.*; import WebFlow.submitJob2.*; import WebFlow.ATD.*; //import Webflow.hashtable.*; import WebFlow.RemoteFile.*; import WebFlow.FileBrowser.*; import org.omg.CORBA.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*; public class Troubles extends JInternalFrame { String selectedServer; desktop d; JTextArea debugTA; ORB orb; String IorURL; WebFlowContext master; org.omg.CORBA.Object oxml,oatd,osj,ocd,orf,ofb; submitJob2 submit; XmlServer parser; XmlATD atdParser; //ContextData cd; RemoteFile rf; FileBrowser fb; public Troubles(desktop d) { super("Run Application", true, true, true, true); this.d = d; IorURL = d.IORfileURL; this.selectedServer = d.selectedServer; JPanel bck = new JPanel(); bck.setLayout(new BorderLayout()); getContentPane().add(bck); JPanel upper = new JPanel(); JPanel center = new JPanel(); JPanel lower = new JPanel(); upper.setLayout(new GridLayout(3,1)); upper.add(new JLabel(" ")); JLabel ttt = new JLabel("Trobuleshooting the server",JLabel.CENTER); ttt.setForeground(Color.red); upper.add(ttt); upper.add(new JLabel(" ")); debugTA = new JTextArea(15,50); JScrollPane scroller = new JScrollPane(debugTA,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); center.add(scroller); lower.setLayout(new GridLayout(1,2)); ActionListener bListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); if(what.startsWith("connect")) { connect(); } else { reset(); } } }; JButton b1 = new JButton("connect to the server"); JButton b2 = new JButton("reset display"); b1.addActionListener(bListener); b2.addActionListener(bListener); lower.add(b1); lower.add(b2); bck.add(upper, BorderLayout.NORTH); bck.add(center, BorderLayout.CENTER); bck.add(lower, BorderLayout.SOUTH); } public void reset() { debugTA.setText(""); } public void startOver(String s) { debugTA.setText(s); } public void appendText(String s) { debugTA.append("\n"+s); } public void appendResult(String s) { debugTA.append(" "+s); } public void connect() { startOver("initialize ORB:"); initializeORB(); if(orb==null) appendText("Cannot instantiate ORB"); else appendText(" OK"); appendText("connect to the master:"); master = getMasterServer(); if(master==null) appendText("Cannot connect to the master server"); else { appendText("master server name is: "); appendResult(master.getObjectID()); appendText("create a new context:"); try { WebFlowContext c = WebFlowContextHelper.narrow( master.addNewContext("slave")); if(c==null)appendResult("is null"); else appendResult(c.getObjectID()+" OK"); }catch(Exception ee) { appendResult(" exception rised!"); appendText(ee.toString()); } appendText("attach XmlServer"); oxml = master.addNewModule("XmlServer"); parser = XmlServerHelper.narrow(oxml); if(parser==null) appendResult("the module is null"); else appendResult("OK"); parser.test(); appendText("test completed"); /* appendText("attach ContextData"); ocd = master.addNewModule("ContextData"); cd = ContextDataHelper.narrow(ocd); if(cd==null) appendResult("the module is null"); else appendResult("OK"); cd.test(); appendText("test completed"); */ appendText("attach remotefile"); orf = master.addNewModule("remotefile"); rf = RemoteFileHelper.narrow(orf); if(rf==null) appendResult("the module is null"); else appendResult("OK"); rf.test(); appendText("test completed"); appendText("attach filebrowser"); ofb = master.addNewModule("filebrowser"); fb = FileBrowserHelper.narrow(ofb); if(fb==null) appendResult("the module is null"); else appendResult("OK"); fb.test(); appendText("test completed"); appendText("attach ATDServer"); oatd = master.addNewModule("ATDServer"); atdParser = XmlATDHelper.narrow(oatd); if(atdParser==null) appendResult("the module is null"); else appendResult("OK"); atdParser.test(); appendText("test completed"); /* add submitJob module */ osj = master.addNewModule("submitJob"); submit = submitJob2Helper.narrow(osj); if(submit==null) appendResult("the module is null"); else appendResult("OK"); submit.test(); appendText("test completed"); } } public void initializeORB() { Properties props = System.getProperties(); props.put("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB"); props.put("org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton"); System.setProperties(props); String[] args = new String[1]; args[0]=IorURL; orb = ORB.init(args, props); } public WebFlowContext getMasterServer(){ WebFlowContext ws = null; try { appendText("IorURL:"); appendResult(IorURL); String masterIOR = getIORFromURL(IorURL); appendText("masterIOR:"); appendResult(masterIOR); org.omg.CORBA.Object o = orb.string_to_object(masterIOR); appendText("Master object:"); if(o==null) appendResult(" is null"); appendResult(" is OK"); ws = WebFlowContextHelper.narrow(o); appendText("master server:"); if(ws==null) appendResult(" is null"); else appendResult("is OK"); } catch (Exception e) {System.out.println("getMasterServer: "+e);} return ws; } public String getIORFromURL(String urlString){ String masterServerIOR=""; String thisLine=null; try { URL u = new URL(urlString); try { DataInputStream theHTML = new DataInputStream(u.openStream()); try { while ((thisLine = theHTML.readLine()) != null) { masterServerIOR += thisLine; } } catch (Exception e) { System.out.println("getIORfromURL:"+e); } } catch (Exception e) { System.out.println("getIORfromURL:"+e); } } catch (MalformedURLException e) { System.out.println("getIORfromURL:"+urlString + " is not a parseable URL"); System.out.println("getIORfromURL:"+e); } return masterServerIOR; } public synchronized void waitFor(long howLong){ try { wait(howLong); } catch (Exception e) { System.out.println(e);} } }