You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Toni Bennasar <to...@gmail.com> on 2009/12/14 21:55:05 UTC

Get datasource from remote client

Hello. First of all, excuse my poor english, and thanks for your good
work.

I have a standalone client application working fine with OpenEJB 3.1.2.
OpenEjb is running standalone (not embedded), and the client is running
on other Java VM. It works getting EJBs from their remote interfaces, it
works running JPA things, but i have troubles retrieving a Datasource
from its JNDI name.

The openejb.xml datasource are:

<Resource id="fachibernate" type="DataSource">

    JdbcDriver com.mysql.jdbc.Driver
    JdbcUrl jdbc:mysql://localhost/fachibernate
    UserName foo
    Password bar
    JtaManaged true
</Resource>

<Resource id="fachibernatenojta" type="DataSource">

    JdbcDriver com.mysql.jdbc.Driver
    JdbcUrl jdbc:mysql://localhost/fachibernate
    UserName foo
    Password bar
    JtaManaged false
</Resource>

The JNDI properties I use:

java.naming.factory.initial=org.apache.openejb.client.RemoteInitialContextFactory
java.naming.provider.url=ejbd://localhost:4201

And here the evil line:

DataSource ds = (DataSource)contexto.lookup(poolJndiName);
...<here comes some SQL work with ds>

I have been test this with GlassFish and it worked, but I have some
problems / questions with OpenEjb:

1) I read the OpenEjb documentation about datasource JNDI names, and I
have tried to put poolJndiName="fachibernate",
poolJndiName="java:openejb/Resource/fachibernate" and
poolJndiName="java:comp/env/fachibernate" and they give me a 

javax.naming.NameNotFoundException: XXX does not exist in the system.
Check that the app was successfully deployed.
        at
org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:261)
...

that names only works on the same VM than Openejb? I'm new about J2EE,
so this probably is my fault.

2) I have tried poolJndiName="openejb:Resource/fachibernate" and it does
some different. It throws the exception:

javax.naming.NamingException: Expected an ejb proxy, found unknown
object: type=org.apache.openejb.resource.jdbc.BasicManagedDataSource,
toString=org.apache.openejb.resource.jdbc.BasicManagedDataSource@1f8a6890
        at
org.apache.openejb.server.ejbd.JndiRequestHandler.doLookup(JndiRequestHandler.java:354)
        at
org.apache.openejb.server.ejbd.JndiRequestHandler.processRequest(JndiRequestHandler.java:129)
        at
org.apache.openejb.server.ejbd.EjbDaemon.processJndiRequest(EjbDaemon.java:200)
        at
org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:153)
        at
org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:71)
        at org.apache.openejb.server.ejbd.KeepAliveServer
$Session.service(KeepAliveServer.java:213)
        at
org.apache.openejb.server.ejbd.KeepAliveServer.service(KeepAliveServer.java:233)
        at
org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:66)
        at org.apache.openejb.server.ServicePool
$2.run(ServicePool.java:91)
        at org.apache.openejb.server.ServicePool
$3.run(ServicePool.java:120)
        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)

"Expected an ejb proxy"... Is this out of the J2EE specification? Can I
only retrieve EJBs from a remote OpenEjb? I'm doing something wrong? 

(where it says "fachibernate", I have tried too "fachibernatenojta" and
it give me the same result)

Thanks.



Re: Get datasource from remote client

Posted by Andy Gumbrecht <an...@orprovision.com>.
Toni,

You cannot get a DataSource from a remote client - your test under 
Glassfish was most definitely accessing that DataSource from a local 
context (try accessing it from a remote or virtual machine, and be 
assured it won't work).

What you should be doing is creating some kind of interface (in the 
non-literal sense) for clients to access remotely. EJBs (Enterprise Java 
Beans) are more than likely the interface (in a literal sense) that you 
should be using - there are several ways to access remote information, 
EJBs, Web Services and Remoting to name just a few.

So, your clients access EJBs remotely using JNDI lookups - they (the 
EJBs) in turn either access the DataSource directly to provide retrieved 
information, or you could have a JPA layer to create and access Entity 
Beans - which are by nature intended to cross remote boundaries.

JVM1-Client/JNDI <----> JVM2-EJB(3) /DataSource/JPA <----> Database

Have fun,

Andy.

PS. The centre of the the bridge in the example above is going to be OpenEJB

> Hello. First of all, excuse my poor english, and thanks for your good
> work.
>
> I have a standalone client application working fine with OpenEJB 3.1.2.
> OpenEjb is running standalone (not embedded), and the client is running
> on other Java VM. It works getting EJBs from their remote interfaces, it
> works running JPA things, but i have troubles retrieving a Datasource
> from its JNDI name.
>
> The openejb.xml datasource are:
>
> <Resource id="fachibernate" type="DataSource">
>
>      JdbcDriver com.mysql.jdbc.Driver
>      JdbcUrl jdbc:mysql://localhost/fachibernate
>      UserName foo
>      Password bar
>      JtaManaged true
> </Resource>
>
> <Resource id="fachibernatenojta" type="DataSource">
>
>      JdbcDriver com.mysql.jdbc.Driver
>      JdbcUrl jdbc:mysql://localhost/fachibernate
>      UserName foo
>      Password bar
>      JtaManaged false
> </Resource>
>
> The JNDI properties I use:
>
> java.naming.factory.initial=org.apache.openejb.client.RemoteInitialContextFactory
> java.naming.provider.url=ejbd://localhost:4201
>
> And here the evil line:
>
> DataSource ds = (DataSource)contexto.lookup(poolJndiName);
> ...<here comes some SQL work with ds>
>
> I have been test this with GlassFish and it worked, but I have some
> problems / questions with OpenEjb:
>
> 1) I read the OpenEjb documentation about datasource JNDI names, and I
> have tried to put poolJndiName="fachibernate",
> poolJndiName="java:openejb/Resource/fachibernate" and
> poolJndiName="java:comp/env/fachibernate" and they give me a
>
> javax.naming.NameNotFoundException: XXX does not exist in the system.
> Check that the app was successfully deployed.
>          at
> org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:261)
> ...
>
> that names only works on the same VM than Openejb? I'm new about J2EE,
> so this probably is my fault.
>
> 2) I have tried poolJndiName="openejb:Resource/fachibernate" and it does
> some different. It throws the exception:
>
> javax.naming.NamingException: Expected an ejb proxy, found unknown
> object: type=org.apache.openejb.resource.jdbc.BasicManagedDataSource,
> toString=org.apache.openejb.resource.jdbc.BasicManagedDataSource@1f8a6890
>          at
> org.apache.openejb.server.ejbd.JndiRequestHandler.doLookup(JndiRequestHandler.java:354)
>          at
> org.apache.openejb.server.ejbd.JndiRequestHandler.processRequest(JndiRequestHandler.java:129)
>          at
> org.apache.openejb.server.ejbd.EjbDaemon.processJndiRequest(EjbDaemon.java:200)
>          at
> org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:153)
>          at
> org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:71)
>          at org.apache.openejb.server.ejbd.KeepAliveServer
> $Session.service(KeepAliveServer.java:213)
>          at
> org.apache.openejb.server.ejbd.KeepAliveServer.service(KeepAliveServer.java:233)
>          at
> org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:66)
>          at org.apache.openejb.server.ServicePool
> $2.run(ServicePool.java:91)
>          at org.apache.openejb.server.ServicePool
> $3.run(ServicePool.java:120)
>          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)
>
> "Expected an ejb proxy"... Is this out of the J2EE specification? Can I
> only retrieve EJBs from a remote OpenEjb? I'm doing something wrong?
>
> (where it says "fachibernate", I have tried too "fachibernatenojta" and
> it give me the same result)
>
> Thanks.
>
>
>
>
>    


-- 
------------------------------------------------------------------------

*Andy Gumbrecht*
Software Developer
Orpro Vision GmbH
Hefehof 8, 31785, Hameln

Tel +49 (0) 5151 809 44 21
Cell +49 (0) 174 1800 381
Email andy.gumbrecht@orprovision.com
Web www.orprovision.com


            Orpro Vision GmbH
            Sitz der Gesellschaft: 31785, Hameln
            USt-Id-Nr: DE264453214
            Amtsgericht Hannover HRB204336
            Geschaeftsfuehrer: Roberto Gatti

------------------------------------------------------------------------


            Diese E-Mail enthält vertrauliche und/oder rechtlich
            geschützte Informationen. Wenn Sie nicht der richtige
            Adressat sind oder diese E-Mail irrtümlich erhalten haben,
            informieren Sie bitte sofort den Absender und vernichten Sie
            diese Mail. Das unerlaubte Kopieren, jegliche anderweitige
            Verwendung sowie die unbefugte Weitergabe dieser Mail ist
            nicht gestattet.

------------------------------------------------------------------------


            This e-mail may contain confidential and/or privileged
            information. If you are not the intended recipient (or have
            received this e-mail in error) please notify the sender
            immediately and destroy this e-mail. Any unauthorized
            copying, disclosure, distribution or other use of the
            material or parts thereof is strictly forbidden.

------------------------------------------------------------------------



Re: Get datasource from remote client

Posted by Gurkan Erdogdu <cg...@gmail.com>.
You are not able to get DataSource from remote clients.

2009/12/14 Toni Bennasar <to...@gmail.com>

> Hello. First of all, excuse my poor english, and thanks for your good
> work.
>
> I have a standalone client application working fine with OpenEJB 3.1.2.
> OpenEjb is running standalone (not embedded), and the client is running
> on other Java VM. It works getting EJBs from their remote interfaces, it
> works running JPA things, but i have troubles retrieving a Datasource
> from its JNDI name.
>
> The openejb.xml datasource are:
>
> <Resource id="fachibernate" type="DataSource">
>
>    JdbcDriver com.mysql.jdbc.Driver
>    JdbcUrl jdbc:mysql://localhost/fachibernate
>    UserName foo
>    Password bar
>    JtaManaged true
> </Resource>
>
> <Resource id="fachibernatenojta" type="DataSource">
>
>    JdbcDriver com.mysql.jdbc.Driver
>    JdbcUrl jdbc:mysql://localhost/fachibernate
>    UserName foo
>    Password bar
>    JtaManaged false
> </Resource>
>
> The JNDI properties I use:
>
>
> java.naming.factory.initial=org.apache.openejb.client.RemoteInitialContextFactory
> java.naming.provider.url=ejbd://localhost:4201
>
> And here the evil line:
>
> DataSource ds = (DataSource)contexto.lookup(poolJndiName);
> ...<here comes some SQL work with ds>
>
> I have been test this with GlassFish and it worked, but I have some
> problems / questions with OpenEjb:
>
> 1) I read the OpenEjb documentation about datasource JNDI names, and I
> have tried to put poolJndiName="fachibernate",
> poolJndiName="java:openejb/Resource/fachibernate" and
> poolJndiName="java:comp/env/fachibernate" and they give me a
>
> javax.naming.NameNotFoundException: XXX does not exist in the system.
> Check that the app was successfully deployed.
>        at
> org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:261)
> ...
>
> that names only works on the same VM than Openejb? I'm new about J2EE,
> so this probably is my fault.
>
> 2) I have tried poolJndiName="openejb:Resource/fachibernate" and it does
> some different. It throws the exception:
>
> javax.naming.NamingException: Expected an ejb proxy, found unknown
> object: type=org.apache.openejb.resource.jdbc.BasicManagedDataSource,
> toString=org.apache.openejb.resource.jdbc.BasicManagedDataSource@1f8a6890
>        at
>
> org.apache.openejb.server.ejbd.JndiRequestHandler.doLookup(JndiRequestHandler.java:354)
>        at
>
> org.apache.openejb.server.ejbd.JndiRequestHandler.processRequest(JndiRequestHandler.java:129)
>        at
>
> org.apache.openejb.server.ejbd.EjbDaemon.processJndiRequest(EjbDaemon.java:200)
>        at
> org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:153)
>        at
> org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:71)
>        at org.apache.openejb.server.ejbd.KeepAliveServer
> $Session.service(KeepAliveServer.java:213)
>        at
>
> org.apache.openejb.server.ejbd.KeepAliveServer.service(KeepAliveServer.java:233)
>        at
> org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:66)
>        at org.apache.openejb.server.ServicePool
> $2.run(ServicePool.java:91)
>        at org.apache.openejb.server.ServicePool
> $3.run(ServicePool.java:120)
>        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)
>
> "Expected an ejb proxy"... Is this out of the J2EE specification? Can I
> only retrieve EJBs from a remote OpenEjb? I'm doing something wrong?
>
> (where it says "fachibernate", I have tried too "fachibernatenojta" and
> it give me the same result)
>
> Thanks.
>
>
>


-- 
Gurkan Erdogdu
http://gurkanerdogdu.blogspot.com