summaryrefslogtreecommitdiff
path: root/gnu/CORBA
diff options
context:
space:
mode:
authorAudrius Meskauskas <audriusa@Bioinformatics.org>2005-11-06 11:32:31 +0000
committerAudrius Meskauskas <audriusa@Bioinformatics.org>2005-11-06 11:32:31 +0000
commit88f7e4891055e88e79871345f4bc7f6d4f37480e (patch)
treeacd526a36b197d63469299ec76d96044e1d1be9f /gnu/CORBA
parent8d49ae975c9dbf726a1b95eccc12907676f57ba9 (diff)
downloadclasspath-88f7e4891055e88e79871345f4bc7f6d4f37480e.tar.gz
2005-11-06 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* 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.
Diffstat (limited to 'gnu/CORBA')
-rw-r--r--gnu/CORBA/Minor.java6
-rw-r--r--gnu/CORBA/NamingService/NameParser.java111
2 files changed, 117 insertions, 0 deletions
diff --git a/gnu/CORBA/Minor.java b/gnu/CORBA/Minor.java
index fb5991dc9..511a34d55 100644
--- a/gnu/CORBA/Minor.java
+++ b/gnu/CORBA/Minor.java
@@ -272,5 +272,11 @@ public interface Minor
* 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;
}
diff --git a/gnu/CORBA/NamingService/NameParser.java b/gnu/CORBA/NamingService/NameParser.java
index 8fc75c6a5..422db1c58 100644
--- a/gnu/CORBA/NamingService/NameParser.java
+++ b/gnu/CORBA/NamingService/NameParser.java
@@ -38,6 +38,7 @@ exception statement from your version. */
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.CORBA.portable.ObjectImpl;
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 @@ public class NameParser
* 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 @@ public class NameParser
* 2. corbaloc:rir:[/key] <br>
* 3. corbaname:[iiop][version.subversion@]: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 @@ public class NameParser
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.
@@ -302,6 +349,70 @@ public class NameParser
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)
{