Changeset 2135 for trunk/java-client/org/nzdl/gsdl
- Timestamp:
- 2001-03-08T14:28:31+13:00 (23 years ago)
- Location:
- trunk/java-client/org/nzdl/gsdl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-client/org/nzdl/gsdl/SimpleClient.java
r2131 r2135 55 55 import org.nzdl.gsdl.service.NzdlService; 56 56 import org.nzdl.gsdl.service.NzdlServiceClient; 57 import org.nzdl.gsdl.util.NzdlIORs; 57 58 58 59 /** … … 82 83 public class SimpleClient implements Cloneable, Serializable { 83 84 84 /** The collection of CORBA IORs we know about */85 protected Properties knownIORs = null;86 85 /** The underlying CORBA inferface */ 87 86 NzdlService nzdl = null; 88 /** The name of the properties file */89 String propertiesFileName = "knownIORs.properties";90 /** The name of the file we look for IOR's in */91 String IORFileName = "/tmp/localcorba.objid";92 87 /** Look for an IOR in the file first */ 93 88 boolean useFileFirst = false; … … 96 91 /** The URL that was specified on the commandline */ 97 92 String URLFromCommandLine = null; 93 /** The name of the file we look for IOR's in */ 94 static String IORFileName = "/tmp/localcorba.objid"; 98 95 /** The collection to query */ 99 96 String collectionNameToQuery = ""; … … 136 133 */ 137 134 protected void init(String [] args) { 138 135 139 136 // read our prevously seed IORs ... 140 knownIORs = new Properties();141 137 String IOR = null; 142 138 143 139 // try a URL from the command line 144 140 if (URLFromCommandLine != null) { 145 IOR = getIORfromURL(URLFromCommandLine);141 IOR = NzdlIORs.getIORfromURL(URLFromCommandLine); 146 142 attemptToInitialise(args, null, IOR); 147 143 } … … 149 145 // try an IOR from the command line 150 146 if (IORFromCommandLine != null && nzdl == null) { 151 IOR = IORFromCommandLine;147 IOR = NzdlIORs. registerIOR(IORFromCommandLine); 152 148 attemptToInitialise(args, null, IOR); 153 149 } 154 150 155 151 // try an IOR from a file (the filename may have been 156 152 // given from teh commandline 157 153 if (nzdl == null) { 158 IOR = getIorKey(IORFileName);154 IOR = NzdlIORs.getIORfromFile(IORFileName); 159 155 attemptToInitialise(args, null, IOR); 160 156 } … … 163 159 if (nzdl == null) { 164 160 for (int i=0;( i<urlsCompiledIn.length && nzdl == null );i++) { 165 IOR = getIORfromURL(urlsCompiledIn[i]);161 IOR = NzdlIORs.getIORfromURL(urlsCompiledIn[i]); 166 162 attemptToInitialise(args, null,IOR); 167 163 } 168 164 } 169 165 170 166 // the knownIORs is the last resort 171 167 if (nzdl == null) { 172 File file = new File(propertiesFileName); 173 try { 174 if (file.exists()) { 175 knownIORs.load(new FileInputStream(file)); 176 } 177 } catch (IOException i) { 178 System.err.println("Error reading properties file:" + i); 179 } 180 181 Enumeration e = knownIORs.keys(); 182 while (e.hasMoreElements() && nzdl == null) { 183 IOR = (String) e.nextElement(); 184 attemptToInitialise(args, null, IOR); 185 } 186 } 187 188 knownIORs.put(IOR,""); 189 } 190 191 public String getIORfromURL(String str) 192 { 193 194 String ior = null; 195 196 try { 197 System.err.println("Looking for a URL at:" + str); 198 URL url = new URL(str); 199 InputStream his = url.openStream(); 200 DataInputStream dhis = new DataInputStream(his) ; 201 ior = dhis.readLine(); 202 return ior; 203 } catch (Throwable throwable) { 204 System.err.println("NzdlHosts::getIOR() unable to construct or read URL \"" + 205 str + "\", \"" + ior + "\": " + throwable); 206 return ""; 207 } 208 } 209 210 public void finalize(){ 211 tidy(); 212 } 213 214 void tidy() { 215 try { 216 File file = new File(propertiesFileName); 217 knownIORs.store(new FileOutputStream(file),"These are CORBA IOR's that the SimpleClient has seen and will check again..."); 218 } catch (IOException i) { 219 System.err.println("Error writing properties file:" + i); 220 } 221 } 222 223 /** 224 * Pre: Accept SourceOfID as either: URL or IOR string or Filename 225 * Post: extract localcorba.objid from source of ID 226 */ 227 private String getIorKey(String sourceOfID) { 228 String ior = null; 229 try { 230 sourceOfID = sourceOfID.trim(); 231 System.err.println("Reading IOR from: " + sourceOfID); 232 233 String firstChars = sourceOfID.substring(0, Math.min(4,sourceOfID.length())).toUpperCase(); 234 // if sourceOfID is a URL --------------------------------------- 235 if (sourceOfID.length() > 4 && firstChars.equalsIgnoreCase("HTTP")) { 236 URL myUrl = new URL(sourceOfID); 237 BufferedReader input =new 238 BufferedReader(new InputStreamReader(myUrl.openStream())); 239 ior = input.readLine(); 240 } 241 242 // if sourceOfID is an IOR -------------------------------------- 243 else if (sourceOfID.length() > 4 && firstChars.equalsIgnoreCase("IOR:")) { 244 ior = sourceOfID; 245 } 246 247 // else assume sourceOfID is a file name ------------------------ 248 else { 249 BufferedReader input 250 = new BufferedReader(new FileReader(sourceOfID)); 251 ior = input.readLine(); 252 } 253 } //end of try 254 catch (java.io.IOException e) { 255 System.err.println("Error reading IOR key:\n" + e); 256 } 257 return ior; 258 } // end of getIorKey 259 260 168 IOR = NzdlIORs.getFirstValid(); 169 attemptToInitialise(args, null, IOR); 170 } 171 } 261 172 262 173 private boolean attemptToInitialise(String [] _args, … … 509 420 client.runQuery(); 510 421 511 client.tidy();512 422 } //main 513 423 -
trunk/java-client/org/nzdl/gsdl/SimpleServer.java
r2119 r2135 22 22 23 23 // java standard library classes used 24 import java.io. Serializable;24 import java.io.*; 25 25 //import java.util.*; 26 26 … … 39 39 import org.nzdl.gsdl.service.NzdlServiceClient; 40 40 import org.nzdl.gsdl.util.NzdlCorbaFactory; 41 import org.nzdl.gsdl.util.NzdlIORs; 41 42 42 43 … … 56 57 public class SimpleServer implements Serializable, Cloneable 57 58 { 59 static String IORFileName = "/tmp/localcorba.proxy.objid"; 60 61 58 62 /** 59 63 * Starts up a trivial server. … … 63 67 public static void main(String args[]) 64 68 { 69 corbaComErrorHolder error = NzdlCorbaFactory.createComErrorHolder(); 65 70 try{ 71 SimpleClient client = new SimpleClient(); 66 72 67 73 ORB orb = ORB.init(args, null); 68 74 69 75 // Create the servant and register it with the ORB 70 NzdlServiceServer simpleRef = new NzdlServiceServer(); 76 NzdlServiceServer simpleRef = new NzdlServiceServer(client.nzdl); 77 78 simpleRef.initialise(error); 79 if (error.value.value() != corbaComError._corbaNoError) { 80 System.err.println("CORBA error after initialisation:" + error.value.value()); 81 } 82 71 83 orb.connect(simpleRef); 84 System.err.println(orb.object_to_string(simpleRef)); 85 86 NzdlIORs.registerIOR(orb.object_to_string(simpleRef)); 87 88 try { 89 BufferedWriter output 90 = new BufferedWriter(new FileWriter(IORFileName)); 91 output.write(orb.object_to_string(simpleRef)); 92 output.flush(); 93 } catch (java.io.IOException e) { 94 System.err.println("Error reading IOR file:\n" + e); 95 } 72 96 73 // Get the root naming context 74 org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 75 NamingContext ncRef = NamingContextHelper.narrow(objRef); 76 77 // Bind the object reference in naming 78 NameComponent nc = new NameComponent("Hello", ""); 79 NameComponent path[] = {nc}; 80 ncRef.rebind(path, simpleRef); 81 97 98 82 99 // Wait for invocations from clients 83 100 java.lang.Object sync = new java.lang.Object(); … … 87 104 88 105 } catch(Exception e) { 106 System.err.println("CORBA error:" + error.value.value()); 89 107 System.err.println("ERROR: " + e); 90 108 e.printStackTrace(System.out); 91 } 109 } 110 92 111 } 93 112 } -
trunk/java-client/org/nzdl/gsdl/util/Makefile
r2121 r2135 15 15 CLASSFILES=NzdlConstants.class \ 16 16 NzdlCorbaFactory.class \ 17 NzdlHosts.class 17 NzdlHosts.class \ 18 NzdlIORs.class 18 19 19 20 all: $(CLASSFILES)
Note:
See TracChangeset
for help on using the changeset viewer.