ElhakimZ Bl0gz

Hi, this is my rants regarding computer sciences and socials. Currently my profession is a software developer, I love creating things that purposeful using computer , and to boldly go where no man has gone before. Delights? I am ..mostly caffeinated ;)

Thursday, December 30, 2004

 
EJB access from Jython

I have programmed some EJBs and wanted to test it out for some conditions and values,I need to do it fast, by scripting my logic and generate values from the EJB withoutmany codings.
My problems and expectations solved as I chose jython as the Java's implementation of Python. So I started by downloading the jython-21.class from http://www.jython.org/ and run it's setup. Because my EJB container is OC4J from Oracle, I asked some suggestions from my programming colleague John Rambo . the first step is set the admin password for oc4j by


then I create jndi.properties and META-INF directory in my jython directory script,
#contents of jndi.properties

java.naming.factory.initial=com.evermind.server.ApplicationClientInitialContextFactory
java.naming.provider.url=ormi://localhost/[your-ejb-app]
java.naming.security.principal=admin
java.naming.security.credentials=[yourpass]


<?xml version="1.0"?>

<!DOCTYPE application-client PUBLIC "-//Sun Microsystems,Inc.//DTD J2EE Application Client 1.2//EN" "http://java.sun.com/j2ee/dtds/application-client_1_2.dtd">

<application-client>

<display-name>Foo</display-name>
<ejb-ref>
<ejb-ref-name>com.foo.ejb.FooHome</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.foo.ejb.FooHome</home>
<remote>com.foo.ejb.Foo</remote>
</ejb-ref>
</application-client>

After I defined those files, I created a jython script "ejbtest.jy"

from java.util import Hashtable
from javax.naming import *
from javax.rmi import *
from com.acc.treasury.fundraising.drawdown.ejb import *

class FooEjb:

def __init__(self):
print "Initializing Context.."
self.context=InitialContext()
print "Getting EJB: com.acc.foo.ejb.FooHome.."
self.ejb= self.context.lookup("com.acc.foo.ejb.FooHome").create()

def print(self):
print self.ejb


FooObject=FooEjb()
FooObject.print()

It's that simple..yea! I had tested it in OC4j but for JBoss, WebLogic or WebSphere might seemed not much different .





Comments: Post a Comment



<< Home

Archives

12/26/2004 - 01/02/2005   01/02/2005 - 01/09/2005   02/20/2005 - 02/27/2005   08/28/2005 - 09/04/2005   09/04/2005 - 09/11/2005   09/25/2005 - 10/02/2005   10/02/2005 - 10/09/2005   10/23/2005 - 10/30/2005   11/06/2005 - 11/13/2005   11/13/2005 - 11/20/2005   12/04/2005 - 12/11/2005   12/11/2005 - 12/18/2005   12/18/2005 - 12/25/2005   12/25/2005 - 01/01/2006   01/01/2006 - 01/08/2006   01/08/2006 - 01/15/2006   01/22/2006 - 01/29/2006   01/29/2006 - 02/05/2006   02/05/2006 - 02/12/2006   02/26/2006 - 03/05/2006   03/05/2006 - 03/12/2006   07/09/2006 - 07/16/2006   09/23/2007 - 09/30/2007  

This page is powered by Blogger. Isn't yours?