standalone client with websphere 4.0

Discussions

EJB programming & troubleshooting: standalone client with websphere 4.0

  1. standalone client with websphere 4.0 (1 messages)

    Hi,
    I've created a Rental.ear, with the mehtods given at webspherepro.com. This contains RentalSesseion.jar and Rental.war. I've successfully tested the application using web client i.e. by typing http://localhost:9080/rental/RentACar

    I want to test the deployment using a standalone thin client (not sure whether the jargon is correct or not). This is my client program:

    package rental.client;

    import rental.ejb.session.*;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import java.util.Properties;

    public class
    CarClient {

    public static void main (String args []) throws Exception {

    Properties props = new Properties();

    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
    props.put(Context.PROVIDER_URL, "iiop://localhost:900");

    Context ctx = new InitialContext(props);

    Object obj =
    ctx.lookup("java:comp/env/ejb/RentalClerkHome");


    RentalClerkHome home = (RentalClerkHome) javax.rmi.PortableRemoteObject.narrow (obj,RentalClerkHome.class);

    RentalClerk rclrk = home.create ();

    rclrk.rentVehicle ("1");

    }
    }
    I am getting following error while running the cient:

    javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
    at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:98)
    at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:78)
    at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:591)
    at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:540)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:287)
    at javax.naming.InitialContext.lookup(InitialContext.java:359)
    at rental.client.CarClient.main(CarClient.java:20)
    Exception in thread "P=574692:O=0:CT"
  2. This is because JNDI names starting with 'java:' are actually URLs. To be able to access objects in JNDI through URLs you must first set corresponding JNDI URL context factories. They are usually set up by J2EE environment (client or server) for you.

    The simplest and the most right way is to use <WAS_Home>\bin\launchClient.bat utility to launch you client (I don't know if it has the same name in new versions of WAS). The utility initializes J2EE client environment and, as part of the process, sets up URL context factories for JNDI so that you can now use JNDI names starting with 'java:'.

    But before you launch the client make sure you defined mappings of JNDI references (names starting with java:) used in your client to actual JNDI names as you usually do for the server side components.

    You can also remove code that sets JNDI properties. Context.INITIAL_CONTEXT_FACTORY property is automatically set up by the client environment and you can specify provider URL as command line argument of the launchClient.bat.