All Examples  This Package

Class examples.jndi.WebLogicContextExample


public class WebLogicContextExample
extends Object
This example illustrates how to obtain and use a WebLogic naming context. The same code will work on both a client and a server. If it is run on a client, it will delegate to a remote context running on the server specified by java.naming.provider.url. If it is run on the server specified by the java.naming.provider.url, a local context is used. If it is run on some other server, the context will again delegate to a context located on the server specified by java.naming.provider.url.

The example first creates a default naming context, then binds an object into that context under a newly created subcontext, and finally looks up the object. Note that the binding created here will be available for the life of the server to any client that obtains a WebLogic InitialContext through the same server.

Build the example:

  1. Set up your development shell, as described in Setting up your environment.
  2. Compile the files in this directory as shown in this example for Windows NT:
      $ javac -d %CLIENT_CLASSES%
Run the example:
  1. In your development shell, run the client with the following command:
      $ java examples.jndi.WebLogicContextExample t3://hostname:port
    Host name of the WebLogic Server
    Port where the WebLogic Server is listening for connections (weblogic.system.ListenPort).
    If no argument is provided, the URL defaults to "t3://localhost:7001".

Try running this example a second time within the same WebLogic Server session. Note that although the JDNI binding has already been created (the first time you ran this example), no exception in thrown when the subcontext is re-created. WebLogic's context implementation does not throw an exception if the object that is bound to an existing name is identical to the current object that is bound to that name. This example generates a unique string (using the date) for the bound object. When binding this object for the second time, an NameAlreadyBoundException is thrown since the object is not identical to the object that is currently bound to the same name. Now, the rebind() method must be used to successfully bind the new object.

The key to creating an InitialContext is correctly specifying the required properties. The java.naming.factory.initial property (referred to here via the static InitialContext.INITIAL_CONTEXT_FACTORY) specifies the factory that is used to create the context. Other properties (like java.naming.provider.url) are used to pass on parameters to the specified factory.

These properties can either be provided as system properties or passed explicitly to the InitialContext constructor. This example creates and passes the properties explicitly for clarity. Note that passing the properties explicitly is the only alternative when working in an applet, since an applet is not allowed to modify or read all system properties.

@author Copyright (c) 1998-2000 by BEA Systems, Inc. All Rights Reserved.

Constructor Index

 o WebLogicContextExample()

Method Index

 o main(String[])
Runs this example from the command line.


 o WebLogicContextExample
 public WebLogicContextExample()


 o main
 public static void main(String args[])
Runs this example from the command line.

All Examples  This Package