User: starksm
Date: 01/04/22 23:06:23
Modified: src/main/org/jnp/client Main.java
Log:
Update tests of the jnp: url usage
Revision Changes Path
1.3 +44 -17 jnp/src/main/org/jnp/client/Main.java
Index: Main.java
===================================================================
RCS file: /cvsroot/jboss/jnp/src/main/org/jnp/client/Main.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Main.java 2000/11/02 15:14:06 1.2
+++ Main.java 2001/04/23 06:06:23 1.3
@@ -31,8 +31,9 @@
* The JNDI configuration is provided in the jndi.properties file.
*
* @see NamingContext
- * @author $Author: oberg $
- * @version $Revision: 1.2 $
+ * @author $Author: starksm $
+ * @author [EMAIL PROTECTED]
+ * @version $Revision: 1.3 $
*/
public class Main
implements Runnable
@@ -64,10 +65,9 @@
{
Context ctx = (Context)new InitialContext().lookup("");
Name n = ctx.getNameParser("").parse(name);
-
+ System.out.println("'"+name+"'.size = "+n.size());
for (int i = 0; i < n.size(); i++)
- System.out.print("#"+n.get(i));
- System.out.println("#");
+ System.out.println(" ["+i+"]"+n.get(i));
}
/**
@@ -95,12 +95,15 @@
try
{
printName("jnp://localhost/");
+ printName("jnp://localhost:1099/");
+ printName("jnp://localhost:1099/root");
printName("jnp://localhost");
printName("jnp:/localhost/");
printName("jnp:localhost/");
// Locate naming service (environment/setup is provided through the
jndi.properties file)
- Context ctx = (Context)new InitialContext();
+ InitialContext iniCtx = new InitialContext();
+ Context ctx = iniCtx;
// Create subcontext
Context test = ctx.createSubcontext("test");
@@ -123,13 +126,15 @@
// Lookup object
Object server = ctx.lookup("test/server2");
System.out.println("test/server2 lookup:"+server);
+ server = ctx.lookup("jnp://localhost/test/server2");
+ System.out.println("jnp://localhost/test/server2 lookup:"+server);
// Lookup object
test = (Context)ctx.lookup("test");
Object server2 = test.lookup("server");
// Rebind object
- new InitialContext().rebind("test/server2", hello2);
+ iniCtx.rebind("test/server2", hello2);
System.out.println("test/server2 rebound");
showTree(ctx);
@@ -154,20 +159,20 @@
showTree(ctx);
// Try URL context factory
- ctx = (Context)new InitialContext().lookup("jnp://localhost/");
+ ctx = (Context) iniCtx.lookup("jnp://localhost/");
System.out.println("Looked up URL context");
showTree(ctx);
-
+
// Try complete URL
- System.out.println("Looked up using URL: " +new
InitialContext().lookup("jnp://localhost:1099/test/server3"));
+ System.out.println("Looked up using URL: "
+iniCtx.lookup("jnp://localhost:1099/test/server3"));
// Bind using complete URL
- new InitialContext().bind("jnp://localhost/helloserver",hello2);
+ iniCtx.bind("jnp://localhost/helloserver",hello2);
System.out.println("Bound helloserver");
// Rename using URL
- new
InitialContext().rename("helloserver","jnp://localhost/test/helloserver");
+ iniCtx.rename("helloserver","jnp://localhost/test/helloserver");
System.out.println("Renamed helloserver to test/helloserver");
// Bind to root using absolute and relative names
@@ -190,7 +195,7 @@
// Show root context using listBindings
System.out.println();
System.out.println("Show root bindings");
- ctx = new InitialContext();
+ ctx = iniCtx;
NamingEnumeration enum = ctx.listBindings("");
while (enum.hasMoreElements())
{
@@ -199,10 +204,32 @@
}
showTree(ctx);
-
- ctx.close();
-
- } catch (Exception e)
+ iniCtx.close();
+
+ // Create an initial context that is rooted at /test
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
+ env.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
+ env.setProperty(Context.PROVIDER_URL, "jnp://localhost/test");
+ System.out.println("+++ Test jnp URL passed as PROVIDER_URL");
+ ctx = new InitialContext(env);
+ server = ctx.lookup("server");
+ System.out.println("+ PROVIDER_URL=jnp://localhost/test
lookup(server):"+server);
+ env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099/test");
+ ctx = new InitialContext(env);
+ server = ctx.lookup("server");
+ System.out.println("+ PROVIDER_URL=jnp://localhost:1099/test
lookup(server):"+server);
+ env.setProperty(Context.PROVIDER_URL, "jnp://localhost");
+ ctx = new InitialContext(env);
+ server = ctx.lookup("test/server");
+ System.out.println("+ PROVIDER_URL=jnp://localhost
lookup(test/server):"+server);
+ env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099/");
+ ctx = new InitialContext(env);
+ server = ctx.lookup("test/server");
+ System.out.println("+ PROVIDER_URL=jnp://localhost:1099/
lookup(test/server):"+server);
+
+ }
+ catch (Exception e)
{
e.printStackTrace(System.err);
}
@@ -237,4 +264,4 @@
}
// Inner classes -------------------------------------------------
-}
\ No newline at end of file
+}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development