Below is a test to access orion-primer example bean from
a standalone client.

I can not get this to work and have looked through the
mail archive and web to find any working examples of
this type of access.  The lookup portion fails and I have
tried a number of variations.

Since the orion-primer example is used in the Orion
documentation and does work when I access the bean from
a servlet it seems that this bean is a good candidate
for being accessed from a standalone app (ie, any of the
mechanical issues regarding the bean creation and deployment
are moot).

I do have the application-client.xml empty for the
fully package qualified name reference attempt and have
the refs set correctly when using the JDNI name lookup.

I have verified that the host, application, username/password
etc... are correct and do work.  I have tried on 1.3.8 and
1.4.5, I am using JDK 1.2.2.

Please augment and/or modify or give hints to get this code to
access the HelloBean. I have spent a good amount of time trying
to make this work and really need some help.  Thanks ahead.

PS. let me know what version of Orion you use to get it to
work.  Also if you have a simple JNDI name dump utility so
I can "see" what Orion has done during its deployment would
be a great help.

    MrP

Mark Palaima - [EMAIL PROTECTED]

/*
    S T A N D A L O N E    B E A N    T E S T
*/
package test.beans ;

import hello.ejb.* ;
import java.util.Properties ;
import javax.naming.Context ;
import javax.naming.InitialContext;
import javax.naming.NamingException ;
import javax.rmi.PortableRemoteObject;

public class PrimerClient {

   public static void main(String[] args) {
       try {
            HelloHome home ;

            // GETS EXCEPTION:
            // java:comp/env namespace is only available from within a J2EE
component
            // Any variation of java:comp/env will get this exception.
            home = (HelloHome)getNarrowedName(
                "java:comp/env/ejb/hello/ejb/HelloHome",
                HelloHome.class) ;

            // GETS EXCEPTION:
            // java:comp/env namespace is only available from within a J2EE
component
            home = (HelloHome)getNarrowedName(
                "java:comp/env/ejb/HelloHome",
                HelloHome.class) ;

            // GETS EXCEPTION:
            // hello/ejb/HelloHome not found
            home = (HelloHome)getNarrowedName(
                "hello/ejb/HelloHome",
                HelloHome.class) ;

            // GETS EXCEPTION
            // hello.ejb.HelloHome not found
            home = (HelloHome)getNarrowedName(
                "hello.ejb.HelloHome",
                HelloHome.class) ;

            Hello bizObj = home.create();

            System.out.println("response: " + bizObj.sayHello()) ;

            bizObj.remove();

       } catch(Exception ex) {
            System.err.println("errmsg: " + ex.getMessage()) ;
       }
   }

    // There are 2 ways to lookup the ejb homes:
    //
    // 1. The name is FQN like home.ejb.ErrorHome.  This does not
    //    require any support from the application-client.xml
    //
    // 2. The JDNI name like:
    //        hello/ejb/HelloHome                  or
    //        java:com/env/ejb/hello/ejb/HelloHome
    //    requires an <ejb-ref> entry in the application-client.xml file
    //
    private static java.lang.Object getNarrowedName(String name, Class cls)
    {
        try {
            InitialContext ctx = new InitialContext(getProperties());
            Object ref = ctx.lookup(name) ;
            Object narrowedObj = PortableRemoteObject.narrow(ref, cls);
            return narrowedObj ;
        }
        catch(Exception e) {
            System.out.println("Failed to find & narrow.\n" +
e.getMessage()) ;
            System.out.println("") ;
        }

        return null ;
   }

   // Required since we are accessing the Orion JNDI tree from the outside
   // of the appserver.
   private static Properties getProperties() {
        Properties p = new Properties();

        p.setProperty(Context.PROVIDER_URL,
"ormi://localhost/orion-primer");
        p.setProperty(
            Context.INITIAL_CONTEXT_FACTORY,
            "com.evermind.server.ApplicationClientInitialContextFactory");

        // orion\config\principals.xml, set deactivated="false" for admin
user
        p.setProperty(Context.SECURITY_PRINCIPAL,   "admin");
        p.setProperty(Context.SECURITY_CREDENTIALS, "123");

        return p ;
   }
}


Reply via email to