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) since it works.
I do have the application-client.xml empty for the
fully package qualified name reference attempt:
<application-client>
</application-client>
and here is the application-client.xml used for the
JNDI lookup attempts:
<application-client>
<ejb-ref>
<ejb-ref-name>ejb/HelloHome</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>hello.ejb.HelloHome</home>
<remote>hello.ejb.Hello</remote>
</ejb-ref>
</application-client>
I also make sure the application-client.xml is in a
META-INF directory under the directory where I am running
the standalone client program from.
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 and where/what the application-client.xml was. Also if
anyone 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 ;
// Returns null because:
// java:comp/env namespace is only available from within a J2EE
component
home = getHelloHome("java:comp/env/ejb/hello/ejb/HelloHome") ;
// Returns null because:
// java:comp/env namespace is only available from within a J2EE
component
if (home == null)
home = getHelloHome("java:comp/env/ejb/HelloHome") ;
// Returns null because:
// hello/ejb/HelloHome not found
if (home == null)
home = getHelloHome("hello/ejb/HelloHome") ;
// Returns null because:
// ejb/HelloHome not found
if (home == null)
home = getHelloHome("ejb/HelloHome") ;
// Returns null because:
// HelloHome not found
if (home == null)
home = getHelloHome("HelloHome") ;
// Returns null because:
// hello.ejb.HelloHome not found
if (home == null)
home = getHelloHome("hello.ejb.HelloHome") ;
// Unfortunately home is null from all above attempts (sigh...)
if (home == null) {
System.out.println("All HelloHome lookup attempts failed.")
;
}
else {
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 HelloHome getHelloHome(String name)
{
try {
InitialContext ctx = new InitialContext(getProperties());
Object ref = ctx.lookup(name) ;
HelloHome narrowedObj =
(HelloHome)PortableRemoteObject.narrow(ref,
HelloHome.class);
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 ;
}
}