strbuf
May 20th, 2005, 02:42 AM
I'm trying to invoke method from session bean. All I know is doing it the usual way like this:
private net.streambuffer.FooHome getHome() throws NamingException {
return (net.streambuffer.FooHome) getContext().lookup(
net.streambuffer.FooHome.JNDI_NAME);
}
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://192.168.0.1:1099");
// This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
public void testBean() {
try {
net.streambuffer.Foo myBean = getHome().create();
//--------------------------------------
//This is the place you make your calls.
System.out.println(myBean.message("Hi"));
} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
}
Now does spring offer a better way to access EJB. I'm using spring web and deploying it on Tomcat. So the EJB will be on JBoss and on a different machine.
private net.streambuffer.FooHome getHome() throws NamingException {
return (net.streambuffer.FooHome) getContext().lookup(
net.streambuffer.FooHome.JNDI_NAME);
}
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://192.168.0.1:1099");
// This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
public void testBean() {
try {
net.streambuffer.Foo myBean = getHome().create();
//--------------------------------------
//This is the place you make your calls.
System.out.println(myBean.message("Hi"));
} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
}
Now does spring offer a better way to access EJB. I'm using spring web and deploying it on Tomcat. So the EJB will be on JBoss and on a different machine.