|
From: Garcia, M. <mg...@Bu...> - 2001-04-04 15:02:16
|
Hey Thomas, Here is what works for me. Its a small client to an EJB: Code follows: =========================================== import java from java.lang import Object,StringBuffer,String from javax.naming import * from java.util import * from javax.rmi import * from java.io import * from com.oppen.pb.ejb.Mailer import * class Client: def __init__(self): self.doNothing = 0 self.p = Properties() self.jndiContext = InitialContext() self.ref = Object() def getInitialContext(self): self.p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.TengahInitialContextFactory") self.p.put(Context.PROVIDER_URL, "t3://localhost:7001") return InitialContext(self.p) def getRemote(self,jndiContext): self.jndiContext = self.getInitialContext() # self.ref = jndiContext.lookup("CompositionControllerHome") # home = PortableRemoteObject.narrow(self.ref,CompositionControllerHome.class) #Create a remote reference to the stateless bean home = jndiContext.lookup("MailerHome") mailer = home.create() print 'CONNECTION SUCCESS!!' return mailer if __name__ == '__main__': print 'in the body of app' a = Client() print 'object creation' ctx = a.getInitialContext() rem = a.getRemote(ctx) print rem.testReturn() to = [".com",".com"] frm = ".com" cc = [".com"] bcc = [".com"] subject = "Not a whole lot!" message = "Test message from mailer EJB." rem.sendMessage(to,frm,cc,bcc,subject,message)============================== ============= Hope this helps. The jist is that in main I instantiate a new Client, then call getInitialContext which returns an InitialContext. Then I call getRemote passing it the InitialContext from the previous call. getRemote gives me the remote reference I need to then call a test method rem.testReturn(). The last thing I do (this is an java mail bean by the way) is set up some variables and pass it to rem.sendMessage() which sends an email. have fun. Mick -----Original Message----- From: Thomas Bang Biilmann To: Jython Dev (E-mail) Sent: 4/4/01 7:54 AM Subject: [Jython-dev] RE: EJB access from Jython In addition to the question posted previously, I can now add the following: I've tried something like this: ... from vm import SimpleBean from vm import SimpleBeanHome from javax.naming import Context from javax.naming import InitialContext from javax.rmi import PortableRemoteObject initCtx = InitialContext() sbHomeRef = initCtx.lookup('ejb/SimpleBean') ... from within my Jython script. Until this point, everything works fine. This is very similar to the "standard" way of looking up an EJB from a J2EE program. However, when you in Java at this point would write: sbHome = (SimpleBeanHome) PortableRemoteObject.narrow(sbHomeRef, SimpleBeanHome.class); sb = sbHome.create(); next, in Jython I'm not sure how to go about this? How can I get the remote interface created? Cheers, Thomas > -----Original Message----- > From: Thomas Bang Biilmann > Sent: 3. april 2001 16:50 > To: Jython Dev (E-mail) > Subject: EJB access from Jython > > Hi. > > I'm currently experimenting with Jython scripting inside an > EJB deployed to Borland AppServer 4.5. The EJB (a stateful > session bean) is up and running, e.g. I can issue a simple > Jython script from the client and get the script executed on > the server. Now, I need to get access to other EJBs from the > bean implementing Jython scripting. I know that in the case > of beans (not EJBs, but JavaBeans), this is done via > registerBean/lookupBean or declareBean, but when it comes to > "looking up" an EJB, I'm lacking knowledge. How can this be done? > > /Thomas _______________________________________________ Jython-dev mailing list Jyt...@li... http://lists.sourceforge.net/lists/listinfo/jython-dev |