Changeset 2135


Ignore:
Timestamp:
2001-03-08T14:28:31+13:00 (23 years ago)
Author:
say1
Message:

proxying now appears to work ...

Location:
trunk/java-client/org/nzdl/gsdl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleClient.java

    r2131 r2135  
    5555import org.nzdl.gsdl.service.NzdlService;
    5656import org.nzdl.gsdl.service.NzdlServiceClient;
     57import org.nzdl.gsdl.util.NzdlIORs;
    5758
    5859/**
     
    8283public class SimpleClient implements Cloneable, Serializable {
    8384
    84   /** The collection of CORBA IORs we know about */
    85   protected Properties knownIORs = null;
    8685  /** The underlying CORBA inferface */
    8786  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";
    9287  /** Look for an IOR in the file first */
    9388  boolean useFileFirst = false;
     
    9691  /** The URL that was specified on the commandline */
    9792  String URLFromCommandLine = null;
     93  /** The name of the file we look for IOR's in */
     94  static String IORFileName = "/tmp/localcorba.objid";
    9895  /** The collection to query */
    9996  String collectionNameToQuery = "";
     
    136133   */
    137134  protected void init(String [] args)  {
    138 
     135   
    139136    // read our prevously seed IORs ...
    140     knownIORs = new Properties();
    141137    String IOR = null;
    142138   
    143139    // try a URL from the command line
    144140    if (URLFromCommandLine != null) {
    145       IOR = getIORfromURL(URLFromCommandLine);
     141      IOR = NzdlIORs.getIORfromURL(URLFromCommandLine);
    146142      attemptToInitialise(args, null, IOR);
    147143    }
     
    149145    // try an IOR from the command line
    150146    if (IORFromCommandLine != null && nzdl == null) {
    151       IOR = IORFromCommandLine;
     147      IOR = NzdlIORs. registerIOR(IORFromCommandLine);
    152148      attemptToInitialise(args, null, IOR);
    153149    }
    154 
     150   
    155151    // try an IOR from a file (the filename may have been
    156152    // given from teh commandline
    157153    if (nzdl == null) {
    158       IOR = getIorKey(IORFileName);
     154      IOR = NzdlIORs.getIORfromFile(IORFileName);
    159155      attemptToInitialise(args, null, IOR);
    160156    }
     
    163159    if (nzdl == null) {
    164160      for (int i=0;( i<urlsCompiledIn.length && nzdl == null );i++) {
    165     IOR = getIORfromURL(urlsCompiledIn[i]);
     161    IOR = NzdlIORs.getIORfromURL(urlsCompiledIn[i]);
    166162    attemptToInitialise(args, null,IOR);
    167163      }
    168164    }
    169 
     165   
    170166    // the knownIORs is the last resort
    171167    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  }
    261172
    262173  private boolean attemptToInitialise(String [] _args,
     
    509420    client.runQuery();
    510421   
    511     client.tidy();
    512422  } //main
    513423
  • trunk/java-client/org/nzdl/gsdl/SimpleServer.java

    r2119 r2135  
    2222
    2323// java standard library classes used
    24 import java.io.Serializable;
     24import java.io.*;
    2525//import java.util.*;
    2626
     
    3939import org.nzdl.gsdl.service.NzdlServiceClient;
    4040import org.nzdl.gsdl.util.NzdlCorbaFactory;
     41import org.nzdl.gsdl.util.NzdlIORs;
    4142
    4243
     
    5657public class SimpleServer implements Serializable, Cloneable
    5758{
     59  static String IORFileName = "/tmp/localcorba.proxy.objid";
     60
     61
    5862  /**
    5963   * Starts up a trivial server.
     
    6367  public static void main(String args[])
    6468  {
     69    corbaComErrorHolder error = NzdlCorbaFactory.createComErrorHolder();
    6570    try{
     71      SimpleClient client = new SimpleClient();
    6672   
    6773      ORB orb = ORB.init(args, null);
    6874     
    6975      // 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     
    7183      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      }
    7296     
    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
    8299      // Wait for invocations from clients
    83100      java.lang.Object sync = new java.lang.Object();
     
    87104     
    88105    } catch(Exception e) {
     106      System.err.println("CORBA error:" + error.value.value());     
    89107      System.err.println("ERROR: " + e);
    90108      e.printStackTrace(System.out);
    91     } 
     109    }
     110   
    92111  }
    93112}
  • trunk/java-client/org/nzdl/gsdl/util/Makefile

    r2121 r2135  
    1515CLASSFILES=NzdlConstants.class  \
    1616     NzdlCorbaFactory.class  \
    17      NzdlHosts.class 
     17     NzdlHosts.class  \
     18     NzdlIORs.class
    1819
    1920all: $(CLASSFILES)
Note: See TracChangeset for help on using the changeset viewer.