summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/demo/Ice/applet/HelloApplet.java8
-rw-r--r--java/demo/Ice/applet/build.xml4
-rw-r--r--java/demo/Ice/applet/config.applet7
-rw-r--r--java/src/Ice/PropertiesI.java111
-rw-r--r--java/src/IceInternal/Util.java36
-rw-r--r--java/src/IceSSL/Instance.java49
6 files changed, 93 insertions, 122 deletions
diff --git a/java/demo/Ice/applet/HelloApplet.java b/java/demo/Ice/applet/HelloApplet.java
index dd351a7918d..7f7100cf668 100644
--- a/java/demo/Ice/applet/HelloApplet.java
+++ b/java/demo/Ice/applet/HelloApplet.java
@@ -42,13 +42,7 @@ public class HelloApplet extends JApplet
{
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = Ice.Util.createProperties();
- initData.properties.setProperty("Ice.ACM.Client", "10");
- initData.properties.setProperty("Ice.Trace.Network", "3");
- initData.properties.setProperty("IceSSL.Trace.Security", "3");
- initData.properties.setProperty("IceSSL.Password", "password");
- initData.properties.setProperty("IceSSL.Keystore", "client.jks");
- initData.properties.setProperty("IceSSL.Truststore", "client.jks");
- initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory");
+ initData.properties.load("config.applet");
_communicator = Ice.Util.initialize(initData);
}
catch(Throwable ex)
diff --git a/java/demo/Ice/applet/build.xml b/java/demo/Ice/applet/build.xml
index 7744ee7b327..37c630b7ece 100644
--- a/java/demo/Ice/applet/build.xml
+++ b/java/demo/Ice/applet/build.xml
@@ -49,6 +49,9 @@
<jar jarfile="Hello.jar" update="true" basedir="${certs.dir}">
<include name="client.jks"/>
</jar>
+ <jar jarfile="Hello.jar" update="true" basedir=".">
+ <include name="config.applet"/>
+ </jar>
</target>
<target name="proguard-jar" depends="jar" if="proguard-found">
@@ -75,6 +78,7 @@
<proguard configuration="applet.pro">
<injar path="${class.dir}"/>
<injar path="${certs.dir}/client.jks"/>
+ <injar path="config.applet"/>
<injar refid="ice.classpath" filter="!META-INF/**"/>
<outjar path="Hello.jar"/>
<libraryjar path="${library.jars}"/>
diff --git a/java/demo/Ice/applet/config.applet b/java/demo/Ice/applet/config.applet
new file mode 100644
index 00000000000..d2e6ff71f6b
--- /dev/null
+++ b/java/demo/Ice/applet/config.applet
@@ -0,0 +1,7 @@
+Ice.ACM.Client=10
+Ice.Trace.Network=3
+Ice.Plugin.IceSSL=IceSSL.PluginFactory
+IceSSL.Trace.Security=3
+IceSSL.Password=password
+IceSSL.Keystore=client.jks
+IceSSL.Truststore=client.jks
diff --git a/java/src/Ice/PropertiesI.java b/java/src/Ice/PropertiesI.java
index b187c358865..78846e25241 100644
--- a/java/src/Ice/PropertiesI.java
+++ b/java/src/Ice/PropertiesI.java
@@ -32,49 +32,31 @@ public final class PropertiesI implements Properties
public synchronized String
getProperty(String key)
{
- String result = null;
PropertyValue pv = _properties.get(key);
- if(pv == null)
+ if(pv != null)
{
- try
- {
- result = System.getProperty(key, "");
- }
- catch(java.lang.SecurityException ex)
- {
- result = "";
- }
+ pv.used = true;
+ return pv.value;
}
else
{
- pv.used = true;
- result = pv.value;
+ return "";
}
- return result;
}
public synchronized String
getPropertyWithDefault(String key, String value)
{
- String result = null;
PropertyValue pv = _properties.get(key);
- if(pv == null)
+ if(pv != null)
{
- try
- {
- result = System.getProperty(key, value);
- }
- catch(java.lang.SecurityException ex)
- {
- result = value;
- }
+ pv.used = true;
+ return pv.value;
}
else
{
- pv.used = true;
- result = pv.value;
+ return value;
}
- return result;
}
public int
@@ -86,38 +68,23 @@ public final class PropertiesI implements Properties
public synchronized int
getPropertyAsIntWithDefault(String key, int value)
{
- String result = null;
PropertyValue pv = _properties.get(key);
- if(pv == null)
+ if(pv != null)
{
+ pv.used = true;
+
try
{
- result = System.getProperty(key);
+ return Integer.parseInt(pv.value);
}
- catch(java.lang.SecurityException ex)
+ catch(NumberFormatException ex)
{
+ Ice.Util.getProcessLogger().warning("numeric property " + key +
+ " set to non-numeric value, defaulting to " + value);
}
}
- else
- {
- pv.used = true;
- result = pv.value;
- }
- if(result == null)
- {
- return value;
- }
- try
- {
- return Integer.parseInt(result);
- }
- catch(NumberFormatException ex)
- {
- Ice.Util.getProcessLogger().warning("numeric property " + key +
- " set to non-numeric value, defaulting to " + value);
- return value;
- }
+ return value;
}
public String[]
@@ -134,39 +101,28 @@ public final class PropertiesI implements Properties
value = new String[0];
}
- String result = null;
PropertyValue pv = _properties.get(key);
- if(pv == null)
+ if(pv != null)
{
- try
- {
- result = System.getProperty(key);
- }
- catch(java.lang.SecurityException ex)
- {
- }
+ pv.used = true;
+
+ String[] result = splitString(pv.value, ", \t\r\n");
if(result == null)
{
+ Ice.Util.getProcessLogger().warning("mismatched quotes in property " + key
+ + "'s value, returning default value");
return value;
}
+ if(result.length == 0)
+ {
+ result = value;
+ }
+ return result;
}
else
{
- pv.used = true;
- result = pv.value;
- }
-
- String[] arr = splitString(result, ", \t\r\n");
- if(arr == null)
- {
- Ice.Util.getProcessLogger().warning("mismatched quotes in property " + key
- + "'s value, returning default value");
return value;
}
- else
- {
- return arr;
- }
}
public synchronized java.util.Map<String, String>
@@ -332,8 +288,14 @@ public final class PropertiesI implements Properties
{
try
{
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.io.InputStreamReader isr = new java.io.InputStreamReader(fis, "UTF-8");
+ java.io.InputStream is = IceInternal.Util.openResource(getClass().getClassLoader(), file);
+ if(is == null)
+ {
+ FileException fe = new FileException();
+ fe.path = file;
+ throw fe;
+ }
+ java.io.InputStreamReader isr = new java.io.InputStreamReader(is, "UTF-8");
java.io.BufferedReader br = new java.io.BufferedReader(isr);
parse(br);
}
@@ -657,7 +619,8 @@ public final class PropertiesI implements Properties
//
// Split string helper; returns null for unmatched quotes
//
- private String[] splitString(String str, String delim)
+ private String[]
+ splitString(String str, String delim)
{
java.util.List<String> l = new java.util.ArrayList<String>();
char[] arr = new char[str.length()];
diff --git a/java/src/IceInternal/Util.java b/java/src/IceInternal/Util.java
index fbfc49e1c0f..2a1f70ce69c 100644
--- a/java/src/IceInternal/Util.java
+++ b/java/src/IceInternal/Util.java
@@ -23,4 +23,40 @@ public final class Util
{
return new ProtocolPluginFacadeI(communicator);
}
+
+ //
+ // Given a path name, first try to open it as a class path resource (the path is
+ // treated as absolute). If that fails, fall back to the file system. Returns null
+ // if the file does not exist and raises IOException if an error occurs.
+ //
+ public static java.io.InputStream
+ openResource(ClassLoader cl, String path)
+ throws java.io.IOException
+ {
+ //
+ // Calling getResourceAsStream on the class loader means all paths are absolute,
+ // whereas calling it on the class means all paths are relative to the class
+ // unless the path has a leading forward slash. We call it on the class loader.
+ //
+ // getResourceAsStream returns null if the resource can't be found.
+ //
+ java.io.InputStream stream = cl.getResourceAsStream(path);
+ if(stream == null)
+ {
+ try
+ {
+ java.io.File f = new java.io.File(path);
+ if(f.exists())
+ {
+ stream = new java.io.FileInputStream(f);
+ }
+ }
+ catch(java.lang.SecurityException ex)
+ {
+ // Ignore - a security manager may forbid access to the local file system.
+ }
+ }
+
+ return stream;
+ }
}
diff --git a/java/src/IceSSL/Instance.java b/java/src/IceSSL/Instance.java
index e0af23f18f4..7314a839fe1 100644
--- a/java/src/IceSSL/Instance.java
+++ b/java/src/IceSSL/Instance.java
@@ -1087,53 +1087,20 @@ class Instance
throws java.io.IOException
{
//
- // We resolve the path as follows:
- //
- // 1. Try to open it as a class path resource
- // 2. Try to open it in the file system
- // 3. Prepend the value of IceSSL.DefaultDir (if defined) and try to open
- // it in the file system
+ // This method wraps a call to IceInternal.Util.openResource. If the first call fails and
+ // IceSSL.DefaultDir is defined, prepend the default directory and try again.
//
+ java.io.InputStream stream = IceInternal.Util.openResource(getClass().getClassLoader(), path);
+ if(stream == null && _defaultDir.length() > 0)
+ {
+ stream = IceInternal.Util.openResource(getClass().getClassLoader(),
+ _defaultDir + java.io.File.separator + path);
+ }
- //
- // Calling getResourceAsStream on the class loader means all paths are absolute,
- // whereas calling it on the class requires you to prepend "/" to the path in
- // order to make it absolute, otherwise the path is interpreted relative to the
- // class.
- //
- // getResourceAsStream returns null if the resource can't be found.
- //
- java.io.InputStream stream = getClass().getClassLoader().getResourceAsStream(path);
if(stream != null)
{
stream = new java.io.BufferedInputStream(stream);
}
- else
- {
- try
- {
- java.io.File f = new java.io.File(path);
- if(f.exists())
- {
- stream = new java.io.BufferedInputStream(new java.io.FileInputStream(f));
- }
- else
- {
- if(_defaultDir.length() > 0)
- {
- f = new java.io.File(_defaultDir + java.io.File.separator + path);
- if(f.exists())
- {
- stream = new java.io.BufferedInputStream(new java.io.FileInputStream(f));
- }
- }
- }
- }
- catch(java.lang.SecurityException ex)
- {
- // Ignore - a security manager may forbid access to the local file system.
- }
- }
return stream;
}