You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Rentius <Re...@gmail.com> on 2016/02/11 06:57:17 UTC

Calling separate EJB from Web project deployed on same server

Hi

I have a Web project and a EJB project running on the same TomEE sever, but
they are separate deploys.

I have deployed the EJB project in the apps folder of the TomEE server and
can see the EJB's are starting when the server starts.

/INFO: Jndi(name=DefaultRegistrationProcess) -->
Ejb(deployment-id=DefaultRegistrationProcess)/

Below is one of the @Stateless beans in the EJB project

/@Stateless(name = "DefaultRegistrationProcess")
public class DefaultRegistrationProcess implements RegistrationProcess {

    @Override
    public void process(Registration registration) {
        System.out.println("Hello from Default registration process!");
    }

}/

I have tried the following from the Web project

/new InitialContext().lookup("java:module/DefaultRegistrationProcess");
new InitialContext().lookup("java:global/DefaultRegistrationProcess");
new
InitialContext().lookup("java:global/ProjectName/DefaultRegistrationProcess");
new InitialContext().lookup("java:app/DefaultRegistrationProcess");/

For every above scenario I get the error: /Name
"java:?/DefaultRegistrationProcess" not found/

When packaging the EJB via Maven with the Web Project I can do the lookup by
using new
/InitialContext().lookup("java:module/DefaultRegistrationProcess");/

Is it possible to do a local JNDI call from my Web project to lookup the
DefaultRegistrationProcess bean in the separately deployed EJB module?



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Calling-separate-EJB-from-Web-project-deployed-on-same-server-tp4677588.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Calling separate EJB from Web project deployed on same server

Posted by Romain Manni-Bucau <rm...@gmail.com>.
If not in the same application it is the easiest yes because arguments will
be copied between classloaders to allow you to provide the same API in both
webapps. If your bean is not remote then it is avoided IIRC but parameters
need to be shared.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2016-02-12 6:39 GMT+01:00 Rentius <Re...@gmail.com>:

> Thank you Romain
> The global lookup is working.
>
> When using either the global or LocalInitialContextFactory must one always
> send serializable data types as parameters? It is running on the same TomEE
> server so in the same JVM.
>
> /Caused by: java.io.NotSerializableException: java.util.HashMap$EntrySet :
> The EJB specification restricts remote interfaces to only serializable data
> types./
>
> I have changed the interface to @Local but still the error persists.
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Calling-separate-EJB-from-Web-project-deployed-on-same-server-tp4677588p4677599.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Calling separate EJB from Web project deployed on same server

Posted by Rentius <Re...@gmail.com>.
Thank you Romain
The global lookup is working.

When using either the global or LocalInitialContextFactory must one always
send serializable data types as parameters? It is running on the same TomEE
server so in the same JVM.

/Caused by: java.io.NotSerializableException: java.util.HashMap$EntrySet :
The EJB specification restricts remote interfaces to only serializable data
types./

I have changed the interface to @Local but still the error persists.



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Calling-separate-EJB-from-Web-project-deployed-on-same-server-tp4677588p4677599.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Calling separate EJB from Web project deployed on same server

Posted by Romain Manni-Bucau <rm...@gmail.com>.
the last one looks ok if what is after ! is the interface you use.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2016-02-11 14:25 GMT+01:00 Rentius <Re...@gmail.com>:

> Hi Romain
>
> How would the call look like? I have tried but I think my syntax isn't
> right.
>
> When deploying the EJB module separately it shows the global JNDI path in
> the log:
>
> /INFO:
>
> Jndi(name=global/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess!com.registration.DefaultRegistrationProcess)
> --> Ejb(deployment-id=DefaultRegistrationProcess)
> Feb 11, 2016 3:33:05 PM org.apache.openejb.assembler.classic.JndiBuilder
> bind
> INFO: Jndi(name=global/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess) -->
> Ejb(deployment-id=DefaultRegistrationProcess)/
>
> If I want to call the DefaultRegistrationProcess EJB using global do I use;
>
> /new
>
> InitialContext().lookup("java:global/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess")/
> OR
> /new
>
> InitialContext().lookup("java:lobal/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess!com.registration.DefaultRegistrationProcess")/
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Calling-separate-EJB-from-Web-project-deployed-on-same-server-tp4677588p4677594.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Calling separate EJB from Web project deployed on same server

Posted by Rentius <Re...@gmail.com>.
Hi Romain

How would the call look like? I have tried but I think my syntax isn't
right.

When deploying the EJB module separately it shows the global JNDI path in
the log:

/INFO:
Jndi(name=global/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess!com.registration.DefaultRegistrationProcess)
--> Ejb(deployment-id=DefaultRegistrationProcess)
Feb 11, 2016 3:33:05 PM org.apache.openejb.assembler.classic.JndiBuilder
bind
INFO: Jndi(name=global/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess) -->
Ejb(deployment-id=DefaultRegistrationProcess)/

If I want to call the DefaultRegistrationProcess EJB using global do I use;

/new
InitialContext().lookup("java:global/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess")/
OR
/new
InitialContext().lookup("java:lobal/myApp-1.0-SNAPSHOT/DefaultRegistrationProcess!com.registration.DefaultRegistrationProcess")/



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Calling-separate-EJB-from-Web-project-deployed-on-same-server-tp4677588p4677594.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Calling separate EJB from Web project deployed on same server

Posted by Romain Manni-Bucau <rm...@gmail.com>.
App or global lookups work but it is not the names you used. Check the log
for the exact one.
Le 11 févr. 2016 09:12, "Rentius" <Re...@gmail.com> a écrit :

> Hi
>
> I have a Web project and a EJB project running on the same TomEE sever, but
> they are separate deploys.
>
> I have deployed the EJB project in the apps folder of the TomEE server and
> can see the EJB's are starting when the server starts.
>
> /INFO: Jndi(name=DefaultRegistrationProcess) -->
> Ejb(deployment-id=DefaultRegistrationProcess)/
>
> Below is one of the @Stateless beans in the EJB project
>
> /@Stateless(name = "DefaultRegistrationProcess")
> public class DefaultRegistrationProcess implements RegistrationProcess {
>
>     @Override
>     public void process(Registration registration) {
>         System.out.println("Hello from Default registration process!");
>     }
>
> }/
>
> I have tried the following from the Web project
>
> /new InitialContext().lookup("java:module/DefaultRegistrationProcess");
> new InitialContext().lookup("java:global/DefaultRegistrationProcess");
> new
>
> InitialContext().lookup("java:global/ProjectName/DefaultRegistrationProcess");
> new InitialContext().lookup("java:app/DefaultRegistrationProcess");/
>
> For every above scenario I get the error: /Name
> "java:?/DefaultRegistrationProcess" not found/
>
> When packaging the EJB via Maven with the Web Project I can do the lookup
> by
> using new
> /InitialContext().lookup("java:module/DefaultRegistrationProcess");/
>
> Is it possible to do a local JNDI call from my Web project to lookup the
> DefaultRegistrationProcess bean in the separately deployed EJB module?
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Calling-separate-EJB-from-Web-project-deployed-on-same-server-tp4677588.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Calling separate EJB from Web project deployed on same server

Posted by Rentius <Re...@gmail.com>.
I had to add @Remote to my business interface which my
DefaultRegistrationProcess class implement.

/@Remote
public interface RegistrationProcess {

    public void process(Registration registration);

}/

After that I could make a JNDI lookup using the LocalInitialContextFactory
property and the JNDI name of DefaultRegistrationProcessRemote.

/ Properties p = new Properties();

p.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.LocalInitialContextFactory");
 new InitialContext(p).lookup("DefaultRegistrationProcessRemote");/



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Calling-separate-EJB-from-Web-project-deployed-on-same-server-tp4677588p4677590.html
Sent from the TomEE Users mailing list archive at Nabble.com.