You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by zecas <zz...@hotmail.com> on 2010/05/24 14:01:13 UTC

EJB in Apache Geronimo : Java client invokation

Hi,

I'm trying to connect a standalone java client application to an EJB in
Apache Geronimo, but with no success so far.

It's a starting project so I can learn something about EJB and remote
invocation, and ... well, I'll put some info and hope someone can put some
light on the matter.

My Geronimo has the following ports, which are displayed on console, when
starting up:


  Listening on Ports:
       0 0.0.0.0   Derby Connector
      80 0.0.0.0   Tomcat Connector HTTP BIO HTTP
    1099 0.0.0.0   RMI Naming
    1150 127.0.0.1 CORBA Naming Service
    2001 127.0.0.1 OpenEJB ORB Adapter
    4201 0.0.0.0   OpenEJB Daemon
    6882 127.0.0.1 OpenEJB ORB Adapter
    8009 0.0.0.0   Tomcat Connector AJP AJP
    8443 0.0.0.0   Tomcat Connector HTTPS BIO HTTPS
    9999 0.0.0.0   JMX Remoting Connector
   61613 0.0.0.0   ActiveMQ Transport Connector
   61616 0.0.0.0   ActiveMQ Transport Connector


I'm working with Apache Geronimo 2.1.2, in a windows system, installed
locally.

My EJB3 has the following definition:


@Stateful(name="test-bean", mappedName="test-bean-map")
public class TestBean implements TestLocal, TestRemote {

    public String hello(String user) {
        return "Hello " + user + ", welcome to this EJB!";
    }

    public List getList(String user) {
        ...
    }

}


And the interfaces, which are part of the EJB client JAR:


@Remote
public interface TestRemote {

    public String hello(String user);

}

@Local
public interface TestLocal {

    public List getList(String user);

}


The EAR has the EJB and a WAR module that successfully injects TestLocal and
uses it.

Now I've started a Java project from scratch, and inside a runnable class
main method I do something like:


        String hostName = "localhost";
        String port = "4201";

        Properties props = new Properties();

        props.setProperty("java.naming.factory.initial",
"org.openejb.client.RemoteInitialContextFactory");
        props.setProperty("java.naming.provider.url", hostName+":"+port);
//        props.setProperty("java.naming.security.principal", "username");
//        props.setProperty("java.naming.security.credentials", "passwd");

        Context ic = null;
        try {
            ic = new InitialContext(props);

            // java:comp/env/
            // @Stateful(name="test-bean", mappedName="test-bean-map")

            TestRemote testBean = (TestRemote) PortableRemoteObject.narrow(
                    ic.lookup("test-bean"),
                    TestRemote.class
                    );

            String result = testBean.hello( "peter" );
            log( result );

        } catch(Throwable ex) {
            ex.printStackTrace();
        } finally {
            if( ic!=null ) {
                ic.close();
            }
        }


The result:


java.lang.RuntimeException: Invalid response from server: -1
    at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:277)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)


I've tried using ports 1099, 1150 and 4201, with the same result. Shouldn't
I use port 4201 0.0.0.0   OpenEJB Daemon?

So what am I missing here?

In apache geronimo, where am I suppose to check the jndi name configured? I
can't seem to find it ... although it works on the webapp that goes with the
EJB (on the same EAR).

I've deployed the EAR to Geronimo, without any ejb descriptor and no
geronimo plan descriptor. The EJB uses annotations. But the webapp uses the
injected EJB dependency, so I assume it is properly configured.

Also, can anyone tell me where I should look for the available EJBs? In
JBoss I can check a tree of JNDI entries, and the EJB nammings can be found
there, but in Geronimo I cannot find this EJB name ... I searched in
console->Debug Views (JMX and JNDI) they both present a tree, but I didn't
find the EJB entry that was deployed.



Thanks
-- 
View this message in context: http://apache-geronimo.328035.n3.nabble.com/EJB-in-Apache-Geronimo-Java-client-invokation-tp839481p839481.html
Sent from the Users mailing list archive at Nabble.com.

Re: EJB in Apache Geronimo : Java client invokation

Posted by Łukasz Budnik <lu...@gmail.com>.
Hi there,

First of all try this:

tail -f geronimo.out

it will tell you everything.

Also, you may want to try Geronimo Console, Debug Views -> JNDI Viewer

Do you absolutely must not use default names and mappings? I'm just
using @Stateless and @Remote annotations and I don't have any problems
with remote access.

For example, in my integration tests I retrieve remote SLSB this way:

Properties env = new Properties();
		env.put(Context.INITIAL_CONTEXT_FACTORY,
				"org.apache.openejb.client.RemoteInitialContextFactory");
		env.put(Context.PROVIDER_URL, "ejbd://localhost:4201");
		ctx = new InitialContext(env);
		broker = (RemoteProcessInvocationBroker) ctx
				.lookup("RemoteProcessInvocationBrokerImplRemote");

RemoteProcessInvocationBroker is a remote interface,
RemoteProcessInvocationBrokerImpl is a class implementing it, and
RemoteProcessInvocationBrokerImplRemote is its JNDI name.

cheers,
Łukasz

On 6 June 2010 23:55, Billy Vandory <bi...@yahoo.com> wrote:
>
> just looked at our code, if you are using ejb3 (i assume you are with that
> @Stateless annotation), test it with:
>
> BeanRemote bean = (BeanRemote) initial.lookup("BeanRemote");
>
>
> --
> View this message in context: http://apache-geronimo.328035.n3.nabble.com/EJB-in-Apache-Geronimo-Java-client-invokation-tp839481p874779.html
> Sent from the Users mailing list archive at Nabble.com.
>

Re: EJB in Apache Geronimo : Java client invokation

Posted by Billy Vandory <bi...@yahoo.com>.
just looked at our code, if you are using ejb3 (i assume you are with that
@Stateless annotation), test it with:

BeanRemote bean = (BeanRemote) initial.lookup("BeanRemote");


-- 
View this message in context: http://apache-geronimo.328035.n3.nabble.com/EJB-in-Apache-Geronimo-Java-client-invokation-tp839481p874779.html
Sent from the Users mailing list archive at Nabble.com.

Re: EJB in Apache Geronimo : Java client invokation

Posted by zecas <zz...@hotmail.com>.

Shawn J wrote:
> 
> The provide url should be like this:
> 
> props.setProperty("java.naming.provider.url", "ejbd:"+hostName+":"+port);
> 
> -- 
> Shawn
> 
> 


I thought that too, but in that case I receive:

24/Mai/2010 16:00:33 org.apache.openejb.client.StickyConnectionStrategy
connect
WARNING: Failover: Cannot connect to server(s): ejbd://ejbd:localhost:4201
Exception: Cannot  connect to server: 'ejbd://ejbd:localhost:4201' due to an
unkown exception in the OpenEJB client: java.lang.IllegalArgumentException :
port out of range:-1.  Trying next.
javax.naming.NamingException: Cannot lookup '/TaskBean/remote'. [Root
exception is java.rmi.RemoteException: Unable to connect; nested exception
is: 
	java.rmi.RemoteException: Cannot connect to any servers: Server #0:
ejbd://ejbd:localhost:4201]
	at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:224)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)

It seems it automatically adds that "ejbd://" prefix. Changed to:

props.setProperty("java.naming.provider.url", "ejbd://"+hostName+":"+port);

Will give the same error as before:

java.lang.RuntimeException: Invalid response from server: -1
	at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:277)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)


In the meantime, I found the following error on Geronimo console:

15:55:13,406 ERROR [remote] "null  OEJ/0.0" FAIL "Unexpected error - For
input string: "/""
java.lang.NumberFormatException: For input string: "/"
        at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:449)
        at java.lang.Integer.parseInt(Integer.java:499)
        at
org.apache.openejb.client.ProtocolMetaData.init(ProtocolMetaData.java:56)
        at
org.apache.openejb.client.ProtocolMetaData.readExternal(ProtocolMetaData.java:92)
        at
org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:103)
        at
org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:84)
        at
org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:60)
        at org.apache.openejb.server.ServicePool$2.run(ServicePool.java:78)
        at org.apache.openejb.server.ServicePool$3.run(ServicePool.java:101)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)

It appears when receive the "Invalid response from server: -1" on client
side.

Is it required to have an openejb definition file (openejb-jar.xml) on the
EJB so geronimo makes it available to the client apps?


Any help appreciated.


Thanks
-- 
View this message in context: http://apache-geronimo.328035.n3.nabble.com/EJB-in-Apache-Geronimo-Java-client-invokation-tp839481p839839.html
Sent from the Users mailing list archive at Nabble.com.

Re: EJB in Apache Geronimo : Java client invokation

Posted by Shawn Jiang <ge...@gmail.com>.
The provide url should be like this:

props.setProperty("java.naming.provider.url", "ejbd:"+hostName+":"+port);

On Mon, May 24, 2010 at 8:01 PM, zecas <zz...@hotmail.com> wrote:

>
> Hi,
>
> I'm trying to connect a standalone java client application to an EJB in
> Apache Geronimo, but with no success so far.
>
> It's a starting project so I can learn something about EJB and remote
> invocation, and ... well, I'll put some info and hope someone can put some
> light on the matter.
>
> My Geronimo has the following ports, which are displayed on console, when
> starting up:
>
>
>  Listening on Ports:
>       0 0.0.0.0   Derby Connector
>      80 0.0.0.0   Tomcat Connector HTTP BIO HTTP
>    1099 0.0.0.0   RMI Naming
>    1150 127.0.0.1 CORBA Naming Service
>    2001 127.0.0.1 OpenEJB ORB Adapter
>    4201 0.0.0.0   OpenEJB Daemon
>    6882 127.0.0.1 OpenEJB ORB Adapter
>    8009 0.0.0.0   Tomcat Connector AJP AJP
>    8443 0.0.0.0   Tomcat Connector HTTPS BIO HTTPS
>    9999 0.0.0.0   JMX Remoting Connector
>   61613 0.0.0.0   ActiveMQ Transport Connector
>   61616 0.0.0.0   ActiveMQ Transport Connector
>
>
> I'm working with Apache Geronimo 2.1.2, in a windows system, installed
> locally.
>
> My EJB3 has the following definition:
>
>
> @Stateful(name="test-bean", mappedName="test-bean-map")
> public class TestBean implements TestLocal, TestRemote {
>
>    public String hello(String user) {
>        return "Hello " + user + ", welcome to this EJB!";
>    }
>
>    public List getList(String user) {
>        ...
>    }
>
> }
>
>
> And the interfaces, which are part of the EJB client JAR:
>
>
> @Remote
> public interface TestRemote {
>
>    public String hello(String user);
>
> }
>
> @Local
> public interface TestLocal {
>
>    public List getList(String user);
>
> }
>
>
> The EAR has the EJB and a WAR module that successfully injects TestLocal
> and
> uses it.
>
> Now I've started a Java project from scratch, and inside a runnable class
> main method I do something like:
>
>
>        String hostName = "localhost";
>        String port = "4201";
>
>        Properties props = new Properties();
>
>        props.setProperty("java.naming.factory.initial",
> "org.openejb.client.RemoteInitialContextFactory");
>        props.setProperty("java.naming.provider.url", hostName+":"+port);
> //        props.setProperty("java.naming.security.principal", "username");
> //        props.setProperty("java.naming.security.credentials", "passwd");
>
>        Context ic = null;
>        try {
>            ic = new InitialContext(props);
>
>            // java:comp/env/
>            // @Stateful(name="test-bean", mappedName="test-bean-map")
>
>            TestRemote testBean = (TestRemote) PortableRemoteObject.narrow(
>                    ic.lookup("test-bean"),
>                    TestRemote.class
>                    );
>
>            String result = testBean.hello( "peter" );
>            log( result );
>
>        } catch(Throwable ex) {
>            ex.printStackTrace();
>        } finally {
>            if( ic!=null ) {
>                ic.close();
>            }
>        }
>
>
> The result:
>
>
> java.lang.RuntimeException: Invalid response from server: -1
>    at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:277)
>    at javax.naming.InitialContext.lookup(InitialContext.java:392)
>
>
> I've tried using ports 1099, 1150 and 4201, with the same result. Shouldn't
> I use port 4201 0.0.0.0   OpenEJB Daemon?
>
> So what am I missing here?
>
> In apache geronimo, where am I suppose to check the jndi name configured? I
> can't seem to find it ... although it works on the webapp that goes with
> the
> EJB (on the same EAR).
>
> I've deployed the EAR to Geronimo, without any ejb descriptor and no
> geronimo plan descriptor. The EJB uses annotations. But the webapp uses the
> injected EJB dependency, so I assume it is properly configured.
>
> Also, can anyone tell me where I should look for the available EJBs? In
> JBoss I can check a tree of JNDI entries, and the EJB nammings can be found
> there, but in Geronimo I cannot find this EJB name ... I searched in
> console->Debug Views (JMX and JNDI) they both present a tree, but I didn't
> find the EJB entry that was deployed.
>
>
>
> Thanks
> --
> View this message in context:
> http://apache-geronimo.328035.n3.nabble.com/EJB-in-Apache-Geronimo-Java-client-invokation-tp839481p839481.html
> Sent from the Users mailing list archive at Nabble.com.
>



-- 
Shawn