• Post Reply Bookmark Topic Watch Topic
  • New Topic

Struts to EJB using RMI

 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an EJB project.
I have a Struts project.

I know I'm supposed to access my EJB project business classes from within my struts Action class using RMI.

But from there I get a bit lost.

I have a client test class that is able to hit my ejb just fine, but only because it's inside of the same project.

Because my struts project is totally separate, I don't have the luxury of being able to import my ejb package and working with that package directly.

here is my auto-generated EJB test client (using Eclipse/Lomboz):

=======

package com.test;

import java.rmi.RemoteException;
import java.util.Hashtable;
import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class TestClient {

private com.test.TestSessionHome getHome() throws NamingException {
return (com.test.TestSessionHome) getContext().lookup(
com.test.TestSessionHome.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://127.0.0.1:1099");


InitialContext initialContext = new InitialContext(props);
return initialContext;
}

public void testBean() {

try {
com.test.TestSession myBean = getHome().create();

//--------------------------------------
//This is the place you make your calls.
//System.out.println(myBean.callYourMethod());

System.out.println("test = " + myBean.test("TEST"));

} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
TestClient test = new TestClient();
test.testBean();

}
}

===========

I can't just copy this and paste this into my action class in my struts project - it has no idea what package "com.test" is.

Does this mean I have to take a copy of my "test.jar" and add it to my struts project to have access to the business classes in my EJB project?
 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
figured it out - need to include jboss client and project jars in my project classpath.

Then the client test code created by Lomboz works (90% anyway, new post coming...) in my struts action class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!