classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI:Implementing http://, ftp:// and file:// for org.omg.CO


From: Meskauskas Audrius
Subject: [cp-patches] FYI:Implementing http://, ftp:// and file:// for org.omg.CORBA.ORB.string_to_object(String)
Date: Sun, 06 Nov 2005 12:28:55 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

This patch adds support for the three protocols that must be supported by this method as defined in CORBA 3.0.3 (formal/04-03-12). The requirement is to read from the specified location a string that must be the address string, finally following one of the older standards of the stringified object reference.

2005-11-06  Audrius Meskauskas  <address@hidden>

   * gnu/CORBA/Minor.java (IOR_missing): New minor code.
   gnu/CORBA/NamingService/NameParser.java (corbaloc): Implemented
   file//, ftp:// and http:// support,
   gnu/javax/rmi/CORBA/UtilDelegateImpl.java (mapSystemException):
   Set the cause directly.
   org/omg/CORBA/DATA_CONVERSION.java,
   org/omg/CORBA/ORB.java (string_to_object): Documentation update.

Index: gnu/CORBA/Minor.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/CORBA/Minor.java,v
retrieving revision 1.2
diff -u -r1.2 Minor.java
--- gnu/CORBA/Minor.java        5 Oct 2005 16:25:42 -0000       1.2
+++ gnu/CORBA/Minor.java        6 Nov 2005 10:08:04 -0000
@@ -272,5 +272,11 @@
    * submitting large number of requests.
    */
   int Threads = 21 | vendor;
+  
+  /**
+   * The IOR starts with file://, http:// or ftp://, but this local or remote
+   * resource is not accessible.
+   */
+  int Missing_IOR = 22 | vendor;
 
 }
Index: gnu/CORBA/NamingService/NameParser.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/CORBA/NamingService/NameParser.java,v
retrieving revision 1.5
diff -u -r1.5 NameParser.java
--- gnu/CORBA/NamingService/NameParser.java     28 Oct 2005 14:05:21 -0000      
1.5
+++ gnu/CORBA/NamingService/NameParser.java     6 Nov 2005 11:00:26 -0000
@@ -38,6 +38,7 @@
 
 package gnu.CORBA.NamingService;
 
+import gnu.CORBA.Minor;
 import gnu.CORBA.OrbFunctional;
 import gnu.CORBA.IOR;
 import gnu.CORBA.Unexpected;
@@ -53,7 +54,13 @@
 import org.omg.CosNaming.NamingContext;
 import org.omg.CosNaming._NamingContextStub;
 
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.StringTokenizer;
@@ -88,6 +95,21 @@
    * The IOR prefix.
    */
   public static final String pxIOR = "ior";
+  
+  /**
+   * The file:// prefix.
+   */
+  public static final String pxFILE = "file://";
+  
+  /**
+   * The ftp:// prefix.
+   */
+  public static final String pxFTP = "ftp://";;
+  
+  /**
+   * The http:// prefix.
+   */
+  public static final String pxHTTP = "http://";;
 
   /**
    * Marks iiop protocol.
@@ -132,6 +154,9 @@
    * 2. corbaloc:rir:[/key] <br>
    * 3. corbaname:address@hidden:host[:port]/key <br>
    * 4. corbaname:rir:[/key] <br>
+   * 5. file://[file name]<br>
+   * 6. http://[url]<br>
+   * 7. ftp://[url]<br>
    * 
    * Protocol defaults to IOP, the object key defaults to the NameService.
    * 
@@ -144,6 +169,28 @@
     OrbFunctional orb)
     throws BAD_PARAM
   {
+    return corbaloc(corbaloc, orb, 0);
+  }
+  
+  /**
+   * Parse controlling against the infinite recursion loop.
+   */
+  private org.omg.CORBA.Object corbaloc(String corbaloc,
+    OrbFunctional orb, int recursion)
+  {
+    // The used CORBA specification does not state how many times we should to
+    //redirect, but the infinite loop may be used to knock out the system.
+    // by malicious attempt.
+    if (recursion > 10)
+      throw new DATA_CONVERSION("More than 10 redirections");
+    
+    if (corbaloc.startsWith(pxFILE))
+      return corbaloc(readFile(corbaloc.substring(pxFILE.length())), orb, 
recursion+1);
+    else if (corbaloc.startsWith(pxHTTP))
+      return corbaloc(readUrl(corbaloc), orb, recursion+1);
+    else if (corbaloc.startsWith(pxFTP))
+      return corbaloc(readUrl(corbaloc), orb, recursion+1);
+
     boolean corbaname;
 
     // The alternative addresses, if given.
@@ -301,6 +348,70 @@
 
     else
       throw new DATA_CONVERSION("Unsupported protocol '" + t[p] + "'");
+  }
+  
+  /**
+   * Read IOR from the file in the local file system.
+   */
+  String readFile(String file)
+  {
+    File f = new File(file);
+    if (!f.exists())
+      {
+        DATA_CONVERSION err = new DATA_CONVERSION(f.getAbsolutePath()
+          + " does not exist.");
+        err.minor = Minor.Missing_IOR;
+      }
+    try
+      {
+        char[] c = new char[(int) f.length()];
+        FileReader fr = new FileReader(f);
+        fr.read(c);
+        fr.close();
+        return new String(c).trim();
+      }
+    catch (IOException ex)
+      {
+        DATA_CONVERSION d = new DATA_CONVERSION();
+        d.initCause(ex);
+        d.minor = Minor.Missing_IOR;
+        throw (d);
+      }
+  }
+  
+  /**
+   * Read IOR from the remote URL.
+   */
+  String readUrl(String url)
+  {
+    URL u;
+    try
+      {
+        u = new URL(url);
+      }
+    catch (MalformedURLException mex)
+      {
+        throw new BAD_PARAM("Malformed URL: '" + url + "'");
+      }
+
+    try
+      {
+        InputStreamReader r = new InputStreamReader(u.openStream());
+
+        StringBuffer b = new StringBuffer();
+        int c;
+
+        while ((c = r.read()) > 0)
+          b.append((char) c);
+
+        return b.toString().trim();
+      }
+    catch (Exception exc)
+      {
+        DATA_CONVERSION d = new DATA_CONVERSION("Reading " + url + " failed.");
+        d.minor = Minor.Missing_IOR;
+        throw d;
+      }
   }
 
   private org.omg.CORBA.Object resolve(org.omg.CORBA.Object object)
Index: gnu/javax/rmi/CORBA/UtilDelegateImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/javax/rmi/CORBA/UtilDelegateImpl.java,v
retrieving revision 1.8
diff -u -r1.8 UtilDelegateImpl.java
--- gnu/javax/rmi/CORBA/UtilDelegateImpl.java   28 Oct 2005 14:05:22 -0000      
1.8
+++ gnu/javax/rmi/CORBA/UtilDelegateImpl.java   6 Nov 2005 11:17:46 -0000
@@ -518,7 +518,7 @@
     else if (ex instanceof INV_OBJREF)
       {
         rex = new NoSuchObjectException(message);
-        rex.initCause(ex);
+        rex.detail = ex;
       }
     else if (ex instanceof NO_PERMISSION)
       rex = new AccessException(message, ex);
@@ -529,22 +529,22 @@
     else if (ex instanceof OBJECT_NOT_EXIST)
       {
         rex = new NoSuchObjectException(message);
-        rex.initCause(ex);
+        rex.detail = ex;
       }
     else if (ex instanceof TRANSACTION_REQUIRED)
       {
         rex = new TransactionRequiredException(message);
-        rex.initCause(ex);
+        rex.detail = ex;
       }
     else if (ex instanceof TRANSACTION_ROLLEDBACK)
       {
         rex = new TransactionRolledbackException(message);
-        rex.initCause(ex);
+        rex.detail = ex;
       }
     else if (ex instanceof INVALID_TRANSACTION)
       {
         rex = new InvalidTransactionException(message);
-        rex.initCause(ex);
+        rex.detail = ex;
       }
     else if (ex instanceof UNKNOWN)
       rex = wrapException(ex.getCause());
Index: org/omg/CORBA/DATA_CONVERSION.java
===================================================================
RCS file: /cvsroot/classpath/classpath/org/omg/CORBA/DATA_CONVERSION.java,v
retrieving revision 1.4
diff -u -r1.4 DATA_CONVERSION.java
--- org/omg/CORBA/DATA_CONVERSION.java  2 Jul 2005 20:32:56 -0000       1.4
+++ org/omg/CORBA/DATA_CONVERSION.java  6 Nov 2005 10:10:16 -0000
@@ -44,6 +44,26 @@
  * Means that the ORB cannot convert between the marshalled and
  * native data representation.
  * 
+ * In GNU Classpath, this exception may have the following minor codes:
+ * 
+ * <table border="1">
+ * <tr>
+ * <td>Hex</td>
+ * <td>Dec</td>
+ * <td>Minor</td>
+ * <td>Name</td>
+ * <td>Case</td>
+ * </tr>
+ * <td>47430016</td>
+ * <td>1195573270</td>
+ * <td>22</td>
+ * <td>Missing_IOR</td>
+ * <td>The object URL is such that the IOR string must be read from some
+ * local or remote resource (file or network), but this resource is not
+ * reacheable.</td>
+ * </tr>
+ * </table> 
+ * 
  * @author Audrius Meskauskas (address@hidden)
  */
 public class DATA_CONVERSION
Index: org/omg/CORBA/ORB.java
===================================================================
RCS file: /cvsroot/classpath/classpath/org/omg/CORBA/ORB.java,v
retrieving revision 1.23
diff -u -r1.23 ORB.java
--- org/omg/CORBA/ORB.java      28 Oct 2005 12:04:40 -0000      1.23
+++ org/omg/CORBA/ORB.java      6 Nov 2005 09:47:58 -0000
@@ -1024,6 +1024,12 @@
    * that runs on the given host at the given port. The ORB expects to find 
    * there the address@hidden org.omg.CosNaming.NamingContext} under the key 
    * "NameService.<br>
+   * 7. file://[file name] Read the object definition string from the 
+   * file system<br>
+   * 8. http://[url] Read the object definition string from the provided
+   * url.<br>
+   * 9. ftp://[url] Read the object definition string from the provided
+   * url.<br>
    * 
    * <p>The default port is always 2809. The default iiop version is 1.0
    * that now may not always be supported, so we would recommend to specify

reply via email to

[Prev in Thread] Current Thread [Next in Thread]