facebook

How do I create I client for an EJB?

  1. MyEclipse Archived
  2.  > 
  3. Documentation
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #226260 Reply

    Alejandro Barrero
    Participant

    I have not been able to find anything in the documentation. I am trying
    public class TestEJB {
    public static void main(String[] args) {
    InitialContext jndiContext = null;
    try {
    jndiContext = getContext();
    } catch (NamingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    Object o;
    try {
    o = jndiContext.lookup(“ejb/Stateless”);
    } catch (NamingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    System.out.println(“No problem.”);
    }

    public static InitialContext getContext() throws NamingException {
    Hashtable props = new Hashtable();
    props.put(Context.INITIAL_CONTEXT_FACTORY,”org.jnp.interfaces.NamingContextFactory”);
    props.put(Context.PROVIDER_URL, “localhost:8080”);
    props.put(“java.naming.factory.url.pkgs”, “org.jboss.naming”);
    return new InitialContext(props);
    }
    }
    But I am getting
    javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]

    Any help will be greatly appreciated.

    Alejandro Barrero

    #226275 Reply

    Riyad Kalla
    Member
    #226310 Reply

    Alejandro Barrero
    Participant

    Thank you very much for the tutorials; in particular, the properties for the initial context are invaluable. I modified my program as specified; my ejb now shows in the JMX MBean Operation Result page. Unfortunately i am getting the exception:
    javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.util.id.GUID; local class incompatible: stream classdesc serialVersionUID = 6926421946503004889, local class serialVersionUID = 3289509836244263718]
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:663)

    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
    at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
    at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:51)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:566)
    It looks like the class in the client does not match the class in the server. I am puzzled, because I an using the j2ee.jar from the same jdk I am using on JBoss and in the debugger.

    I will apreciate your help.

    Alejandro barrero

    #226312 Reply

    Alejandro Barrero
    Participant

    Thank you very much for the tutorials; in particular, the properties for the initial context are invaluable. I modified my program as specified; my ejb now shows in the JMX MBean Operation Result page. Unfortunately i am getting the exception:
    javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.util.id.GUID; local class incompatible: stream classdesc serialVersionUID = 6926421946503004889, local class serialVersionUID = 3289509836244263718]
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:663)

    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
    at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
    at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:51)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:566)
    It looks like the class in the client does not match the class in the server. I am puzzled, because I an using the j2ee.jar from the same jdk I am using on JBoss and in the debugger.

    I will apreciate your help.

    Alejandro barrero

    #226313 Reply

    Riyad Kalla
    Member

    You aren’t deploying the J2EE library JARs with your project out into your WEB-INF/lib dir are you?

    #226329 Reply

    Alejandro Barrero
    Participant

    The code to access an EJB in JBoss from a client is:
    //Set up the initial context for JBoss.
    InitialContext jndiContext = null;
    Hashtable properties = new Hashtable();
    properties.put(Context.INITIAL_CONTEXT_FACTORY,”org.jnp.interfaces.NamingContextFactory”);
    properties.put(Context.PROVIDER_URL, “jnp://localhost:1099”);
    properties.put(“java.naming.factory.url.pkgs”, “org.jboss.naming:org.jnp.interfaces”);
    properties.put(“jnp.disableDiscovery”, “true”);
    try {
    jndiContext = new InitialContext(properties);
    } catch (NamingException e) {
    e.printStackTrace();
    }
    //Retrieve the home object.
    Stateless statelessSession = null;
    try {
    Object obj = jndiContext.lookup(“Stateless”);
    StatelessHome home = (StatelessHome) PortableRemoteObject.narrow(obj, StatelessHome.class);
    statelessSession = home.create();
    System.out.println(statelessSession.sayHello());
    } catch (Exception e1) {
    e1.printStackTrace();
    }

    The jars needed are:
    j2sdkee1.4x\lib\j2ee.jar
    jboss-4.0.1sp1\client\jboss-common-client.jar
    jboss-4.0.1sp1\client\jbossx-client.jar
    jboss-4.0.1sp1\client\jboss-transaction-client.jar
    jboss-4.0.1sp1\client\jpn-client.jar

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: How do I create I client for an EJB?

You must be logged in to post in the forum log in