38 |
|
|
39 |
package gnu.CORBA.NamingService; |
package gnu.CORBA.NamingService; |
40 |
|
|
41 |
|
import gnu.CORBA.Minor; |
42 |
import gnu.CORBA.OrbFunctional; |
import gnu.CORBA.OrbFunctional; |
43 |
import gnu.CORBA.IOR; |
import gnu.CORBA.IOR; |
44 |
import gnu.CORBA.Unexpected; |
import gnu.CORBA.Unexpected; |
54 |
import org.omg.CosNaming.NamingContext; |
import org.omg.CosNaming.NamingContext; |
55 |
import org.omg.CosNaming._NamingContextStub; |
import org.omg.CosNaming._NamingContextStub; |
56 |
|
|
57 |
|
import java.io.File; |
58 |
|
import java.io.FileReader; |
59 |
|
import java.io.IOException; |
60 |
|
import java.io.InputStreamReader; |
61 |
import java.io.UnsupportedEncodingException; |
import java.io.UnsupportedEncodingException; |
62 |
|
import java.net.MalformedURLException; |
63 |
|
import java.net.URL; |
64 |
import java.net.URLDecoder; |
import java.net.URLDecoder; |
65 |
import java.util.ArrayList; |
import java.util.ArrayList; |
66 |
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
95 |
* The IOR prefix. |
* The IOR prefix. |
96 |
*/ |
*/ |
97 |
public static final String pxIOR = "ior"; |
public static final String pxIOR = "ior"; |
98 |
|
|
99 |
|
/** |
100 |
|
* The file:// prefix. |
101 |
|
*/ |
102 |
|
public static final String pxFILE = "file://"; |
103 |
|
|
104 |
|
/** |
105 |
|
* The ftp:// prefix. |
106 |
|
*/ |
107 |
|
public static final String pxFTP = "ftp://"; |
108 |
|
|
109 |
|
/** |
110 |
|
* The http:// prefix. |
111 |
|
*/ |
112 |
|
public static final String pxHTTP = "http://"; |
113 |
|
|
114 |
/** |
/** |
115 |
* Marks iiop protocol. |
* Marks iiop protocol. |
154 |
* 2. corbaloc:rir:[/key] <br> |
* 2. corbaloc:rir:[/key] <br> |
155 |
* 3. corbaname:[iiop][version.subversion@]:host[:port]/key <br> |
* 3. corbaname:[iiop][version.subversion@]:host[:port]/key <br> |
156 |
* 4. corbaname:rir:[/key] <br> |
* 4. corbaname:rir:[/key] <br> |
157 |
|
* 5. file://[file name]<br> |
158 |
|
* 6. http://[url]<br> |
159 |
|
* 7. ftp://[url]<br> |
160 |
* |
* |
161 |
* Protocol defaults to IOP, the object key defaults to the NameService. |
* Protocol defaults to IOP, the object key defaults to the NameService. |
162 |
* |
* |
169 |
OrbFunctional orb) |
OrbFunctional orb) |
170 |
throws BAD_PARAM |
throws BAD_PARAM |
171 |
{ |
{ |
172 |
|
return corbaloc(corbaloc, orb, 0); |
173 |
|
} |
174 |
|
|
175 |
|
/** |
176 |
|
* Parse controlling against the infinite recursion loop. |
177 |
|
*/ |
178 |
|
private org.omg.CORBA.Object corbaloc(String corbaloc, |
179 |
|
OrbFunctional orb, int recursion) |
180 |
|
{ |
181 |
|
// The used CORBA specification does not state how many times we should to |
182 |
|
//redirect, but the infinite loop may be used to knock out the system. |
183 |
|
// by malicious attempt. |
184 |
|
if (recursion > 10) |
185 |
|
throw new DATA_CONVERSION("More than 10 redirections"); |
186 |
|
|
187 |
|
if (corbaloc.startsWith(pxFILE)) |
188 |
|
return corbaloc(readFile(corbaloc.substring(pxFILE.length())), orb, recursion+1); |
189 |
|
else if (corbaloc.startsWith(pxHTTP)) |
190 |
|
return corbaloc(readUrl(corbaloc), orb, recursion+1); |
191 |
|
else if (corbaloc.startsWith(pxFTP)) |
192 |
|
return corbaloc(readUrl(corbaloc), orb, recursion+1); |
193 |
|
|
194 |
boolean corbaname; |
boolean corbaname; |
195 |
|
|
196 |
// The alternative addresses, if given. |
// The alternative addresses, if given. |
349 |
else |
else |
350 |
throw new DATA_CONVERSION("Unsupported protocol '" + t[p] + "'"); |
throw new DATA_CONVERSION("Unsupported protocol '" + t[p] + "'"); |
351 |
} |
} |
352 |
|
|
353 |
|
/** |
354 |
|
* Read IOR from the file in the local file system. |
355 |
|
*/ |
356 |
|
String readFile(String file) |
357 |
|
{ |
358 |
|
File f = new File(file); |
359 |
|
if (!f.exists()) |
360 |
|
{ |
361 |
|
DATA_CONVERSION err = new DATA_CONVERSION(f.getAbsolutePath() |
362 |
|
+ " does not exist."); |
363 |
|
err.minor = Minor.Missing_IOR; |
364 |
|
} |
365 |
|
try |
366 |
|
{ |
367 |
|
char[] c = new char[(int) f.length()]; |
368 |
|
FileReader fr = new FileReader(f); |
369 |
|
fr.read(c); |
370 |
|
fr.close(); |
371 |
|
return new String(c).trim(); |
372 |
|
} |
373 |
|
catch (IOException ex) |
374 |
|
{ |
375 |
|
DATA_CONVERSION d = new DATA_CONVERSION(); |
376 |
|
d.initCause(ex); |
377 |
|
d.minor = Minor.Missing_IOR; |
378 |
|
throw (d); |
379 |
|
} |
380 |
|
} |
381 |
|
|
382 |
|
/** |
383 |
|
* Read IOR from the remote URL. |
384 |
|
*/ |
385 |
|
String readUrl(String url) |
386 |
|
{ |
387 |
|
URL u; |
388 |
|
try |
389 |
|
{ |
390 |
|
u = new URL(url); |
391 |
|
} |
392 |
|
catch (MalformedURLException mex) |
393 |
|
{ |
394 |
|
throw new BAD_PARAM("Malformed URL: '" + url + "'"); |
395 |
|
} |
396 |
|
|
397 |
|
try |
398 |
|
{ |
399 |
|
InputStreamReader r = new InputStreamReader(u.openStream()); |
400 |
|
|
401 |
|
StringBuffer b = new StringBuffer(); |
402 |
|
int c; |
403 |
|
|
404 |
|
while ((c = r.read()) > 0) |
405 |
|
b.append((char) c); |
406 |
|
|
407 |
|
return b.toString().trim(); |
408 |
|
} |
409 |
|
catch (Exception exc) |
410 |
|
{ |
411 |
|
DATA_CONVERSION d = new DATA_CONVERSION("Reading " + url + " failed."); |
412 |
|
d.minor = Minor.Missing_IOR; |
413 |
|
throw d; |
414 |
|
} |
415 |
|
} |
416 |
|
|
417 |
private org.omg.CORBA.Object resolve(org.omg.CORBA.Object object) |
private org.omg.CORBA.Object resolve(org.omg.CORBA.Object object) |
418 |
{ |
{ |