Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Communicate with a remote EJB3 server through JNDI Sam E July 12, 2009 5:26 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 12, 2009 6:02 AM
RE: Communicate with a remote EJB3 server through JNDI gofri _ July 12, 2009 3:06 PM
RE: Communicate with a remote EJB3 server through JNDI Victor Zorin July 12, 2009 6:01 PM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 12, 2009 9:53 PM
RE: Communicate with a remote EJB3 server through JNDI Victor Zorin July 12, 2009 10:41 PM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 2:40 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 3:01 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 4:55 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 5:14 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 5:38 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 5:58 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 6:00 AM
RE: Communicate with a remote EJB3 server through JNDI Victor Zorin July 13, 2009 4:29 PM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 6:30 PM
RE: Communicate with a remote EJB3 server through JNDI Victor Zorin July 13, 2009 6:53 PM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 7:24 PM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 13, 2009 8:28 PM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 14, 2009 2:46 AM
RE: Communicate with a remote EJB3 server through JNDI Victor Zorin July 14, 2009 4:34 AM
RE: Communicate with a remote EJB3 server through JNDI Sam E July 14, 2009 6:14 AM
RE: Communicate with a remote EJB3 server through JNDI Gianmarco Morelli October 27, 2010 2:52 PM
RE: Communicate with a remote EJB3 server through JNDI M s May 12, 2011 2:58 AM
RE: Communicate with a remote EJB3 server through JNDI M s May 12, 2011 2:58 AM
Sam E
Communicate with a remote EJB3 server through JNDI
July 12, 2009 5:26 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi,

I want to add some code in my current portlet application to communicate with an EJB3 bean which located in another remote server through the use of JNDI. How do I supposed to do that?

Thanks
Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 12, 2009 6:02 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

I just realised that I may need to add some jboss codes into the build.xml file when building my portlet client to communicate wtih remote EJB3 through JNDI. But I don't know what should be added and modified in the current build.xml file. It is a portlet that built by ant/struts.

Any idea is very much appreciated.

Thanks
Sam
gofri _
RE: Communicate with a remote EJB3 server through JNDI
July 12, 2009 3:06 PM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

I am not sure, but I think you must add JBoss EJB client libraries (jars) in liferay server,
Maybe you should search Jboss site how to write a regular EJB client and convert it to a portlet.
Victor Zorin
RE: Communicate with a remote EJB3 server through JNDI
July 12, 2009 6:01 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1183

Join Date: April 14, 2008

Recent Posts

Sam, have a look how this service locator class does detection of EJB stateless session object. It uses JFig to locate service location host, you would not need this, take it out of code.
 1
 2// MyOffice24x7, ServiceLocator
 3package com.myoffice.common.client;
 4
 5import javax.naming.Context;
 6import javax.naming.InitialContext;
 7import org.igfay.jfig.JFig;
 8import java.util.*;
 9import org.apache.commons.logging.LogFactory;
10import org.apache.commons.logging.Log;
11
12public class ServiceLocator {
13    private Map<String, java.lang.Object> cache;
14    private static ServiceLocator ourInstance = new ServiceLocator();
15    private static final Log logger = LogFactory
16        .getLog(ServiceLocator.class);
17
18    public static ServiceLocator getInstance() {
19        return ourInstance;
20    }
21
22    private ServiceLocator() {
23        this.cache = Collections.synchronizedMap(
24                new HashMap<String, java.lang.Object>());
25    }
26
27    public java.lang.Object getService(String serviceName) {
28        String serviceHost;
29        if (this.cache.containsKey(serviceName)) {
30            return this.cache.get(serviceName);
31        } else {
32            try {
33                serviceHost = JFig.getInstance().getValue(
34                        "service-location",
35                        serviceName);
36            } catch (Exception e) {
37                logger.warn("Location is not configured for service " +
38                                   serviceName +
39                                   ". Using localhost.", e);
40                serviceHost = "localhost";
41            } catch (Throwable e) {
42                logger.warn("Location is not configured for service " +
43                                   serviceName +
44                                   ". Using localhost.", e);
45                serviceHost = "localhost";
46            }
47        }
48
49            try {
50                java.lang.Object service = this.getContext(
51                        serviceHost).lookup(
52                                serviceName + "Bean/remote");
53                cache.put(serviceName, service);
54                return service;
55            } catch (Exception e) {
56                e.printStackTrace();
57                logger.error("Unable to bind to service "
58                                   + serviceName + ". Hostname: " + serviceHost, e);
59                return null;
60            } catch (Throwable e) {
61                e.printStackTrace();
62                logger.error("Unable to bind to service "
63                                   + serviceName + ". Hostname: " + serviceHost, e);
64                return null;
65            }
66
67    }
68
69    public java.lang.Object getService(String serviceName, String serviceHost) {
70        String key = serviceHost + "." + serviceName;
71        if (this.cache.containsKey(key)) {
72            return this.cache.get(key);
73        } else {
74            try {
75                java.lang.Object service = this.getContext(
76                        serviceHost).lookup(
77                                serviceName + "Bean/remote");
78                cache.put(key, service);
79                return service;
80            } catch (Exception e) {
81                logger.error("Unable to bind to service "
82                                   + serviceName + ". Hostname: " + serviceHost);
83                return null;
84            }
85        }
86    }
87
88    private Context getContext(String serviceHost) throws javax.naming.NamingException
89    {
90        Properties properties = new Properties();
91        properties.put(Context.INITIAL_CONTEXT_FACTORY,
92                       "org.jnp.interfaces.NamingContextFactory");
93        properties.put(Context.URL_PKG_PREFIXES,
94                       "org.jboss.naming:org.jnp.interfaces");
95        properties.put(Context.PROVIDER_URL, serviceHost + ":1099");
96        return new InitialContext(properties);
97    }
98}


In your client code, use this service locator the following way:
 1
 2    private YourEjbInterface  getSession() throws SystemErrorException {
 3        YourEjbInterface  mgr = null;
 4        mgr = (YourEjbInterface) ServiceLocator.getInstance().getService(
 5                "YourEjbInterface");
 6        if (mgr == null) {
 7            throw new SystemErrorException("Unable to connect to service");
 8        } else {
 9            return mgr;
10        }
11    }
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 12, 2009 9:53 PM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi Victor,

Thanks for the sample codes.
It looks like I don't need to modify my existing liferay ext development environment at all. Is it? This is awesome.
By the way, how have you been?

Thanks very much
Sam
Victor Zorin
RE: Communicate with a remote EJB3 server through JNDI
July 12, 2009 10:41 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1183

Join Date: April 14, 2008

Recent Posts

No, you do not have to modify anything in your devel. environment. It will also cover all your communication needs when you switch over to a server farm, EJB3 use samples are also ready for publishing on online manual.
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 2:40 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi Victor

To follow the Calculator example in JBOSS ejb3 tutorial,
there are 2 interfaces are there, which one should be put in liferay project path is unsure yet:

1. Calculator.java
 1
 2package org.jboss.tutorial.stateless.bean;
 3
 4public interface Calculator
 5{
 6   int add(int x, int y);
 7
 8   int subtract(int x, int y);
 9}


2.CalculatorLocal.java
 1
 2package org.jboss.tutorial.stateless.bean;
 3
 4import javax.ejb.Local;
 5
 6@Local
 7public interface CalculatorLocal extends Calculator
 8{
 9}


3. CalculatorRemote.java
 1
 2package org.jboss.tutorial.stateless.bean;
 3
 4import javax.ejb.Remote;
 5
 6@Remote
 7public interface CalculatorRemote extends Calculator
 8{
 9
10}


4. CalculatorBean.java
package org.jboss.tutorial.stateless.bean;

import javax.ejb.Stateless;

@Stateless
 1
 2public class CalculatorBean implements CalculatorRemote, CalculatorLocal
 3{
 4   public int add(int x, int y)
 5   {
 6      return x + y;
 7   }
 8
 9   public int subtract(int x, int y)
10   {
11      return x - y;
12   }
13}


Which interface class should I move it to the liferay development project environment?

source code path:
# pwd
/usr/java-source/ejb3-tutorial/source/stateless/src/org/jboss/tutorial/stateless/bean
# ls
./ ../ Calculator.java CalculatorBean.java CalculatorLocal.java CalculatorRemote.java

Thanks
Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 3:01 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Opps... I may be known already. emoticon
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 4:55 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi Victor,

How do you include ejb jar file in liferay run-time?

I got error "javax.ejb does not exist" when I compiled my portlet.

Thanks
Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 5:14 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hi Victor,

I have resolved the compile time error. Will test its functionaltiy soon.

Thanks alot
Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 5:38 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Hmm.. got run-time error about "Cannot instantiate class: org.jnp.interfaces.NamingContextFactory".

Should I copy all jboss jar files into
"/usr/liferay-portal-5.2.3/tomcat-6.0.18/lib/ext"
or
"/usr/liferay-portal-5.2.3/tomcat-6.0.18/lib/" ?

Just dont' want to mess up the directory before get a confirmation .

Thanks very much
Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 5:58 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

I got the following run-time error:

javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

NOt sure if I need to copy jboss jar files into the tomcat lib or ext directory?

Thanks very much
Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 6:00 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Sam Wan:
I got the following run-time error:

javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

NOt sure if I need to copy jboss jar files into the tomcat lib or ext directory?

Thanks very much
Sam


Apology for the multiple posting, I didn't know my question is posted to the second page.

Sam
Victor Zorin
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 4:29 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1183

Join Date: April 14, 2008

Recent Posts

Not sure if I need to copy jboss jar files into the tomcat lib or ext directory?

You can do it either way, it depends on how do you structure your projects and deployment configurations. You can also place them into portlet war. Have to consider the weight of files, project dependencies and ease of updates.
If you run liferay on jboss/tomcat, everything should be in place by default.

If duplicate post is made, a delete option is available to authors.
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 6:30 PM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

I got the following errors when I hit the submit button on my portlet application:

 1
 2Jul 14, 2009 10:57:47 AM org.apache.jk.server.JkMain start
 3INFO: Jk running ID=0 time=0/46  config=null
 4Jul 14, 2009 10:57:47 AM org.apache.catalina.startup.Catalina start
 5INFO: Server startup in 97284 ms
 6log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
 7log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
 8log4j:ERROR [org.apache.catalina.loader.StandardClassLoader@16b13c7] whereas object of type
 9log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader
10  delegate: false
11  repositories:
12    /WEB-INF/classes/
13----------> Parent Classloader:
14WebappClassLoader
15  delegate: false
16  repositories:
17    /WEB-INF/classes/
18----------> Parent Classloader:
19org.apache.catalina.loader.StandardClassLoader@16b13c7
20
21].
22log4j:ERROR Could not instantiate appender named "CONSOLE".
23javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
24        at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1463)
25        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:809)
26        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
27        at javax.naming.InitialContext.lookup(InitialContext.java:392)


the liferay is a liferay-tomcat bundle (5.2.3) and not the jboss-tomcat bundle.
I just simply copied jboss client libraries (jar files) over to the tomcat/lib/ folders then restarted tomcat.

Thanks
Sam

Here is the code:

1. ServiceLocator.java
 1
 2 import javax.naming.Context;
 3 import javax.naming.InitialContext;
 4// import org.igfay.jfig.JFig;
 5 import java.util.*;
 6 import org.apache.commons.logging.LogFactory;
 7 import org.apache.commons.logging.Log;
 8
 9public class ServiceLocator {
10    private Map<String, java.lang.Object> cache;
11    private static ServiceLocator ourInstance = new ServiceLocator();
12    private static final Log logger = LogFactory
13        .getLog(ServiceLocator.class);
14
15    public static ServiceLocator getInstance() {
16        return ourInstance;
17    }
18
19    private ServiceLocator() {
20        this.cache = Collections.synchronizedMap(
21                new HashMap<String, java.lang.Object>());
22    }
23
24    public java.lang.Object getService(String serviceName) {
25        String serviceHost = "192.168.1.242";
26        if (this.cache.containsKey(serviceName)) {
27            return this.cache.get(serviceName);
28        }
29            try {
30                java.lang.Object service = this.getContext(
31                        serviceHost).lookup(
32                                serviceName + "Bean/remote");
33                cache.put(serviceName, service);
34                return service;
35            } catch (Exception e) {
36                e.printStackTrace();
37                logger.error("Unable to bind to service "
38                                   + serviceName + ". Hostname: " + serviceHost, e);
39                return null;
40            } catch (Throwable e) {
41                e.printStackTrace();
42                logger.error("Unable to bind to service "
43                                   + serviceName + ". Hostname: " + serviceHost, e);
44                return null;
45            }
46
47    }
48
49    public java.lang.Object getService(String serviceName, String serviceHost) {
50        String key = serviceHost + "." + serviceName;
51        if (this.cache.containsKey(key)) {
52            return this.cache.get(key);
53        } else {
54            try {
55                java.lang.Object service = this.getContext(
56                        serviceHost).lookup(
57                                serviceName + "Bean/remote");
58                cache.put(key, service);
59                return service;
60            } catch (Exception e) {
61                logger.error("Unable to bind to service "
62                                   + serviceName + ". Hostname: " + serviceHost);
63                return null;
64            }
65        }
66    }
67
68    private Context getContext(String serviceHost) throws javax.naming.NamingException
69    {
70        Properties properties = new Properties();
71        properties.put(Context.INITIAL_CONTEXT_FACTORY,
72                       "org.jnp.interfaces.NamingContextFactory");
73        properties.put(Context.URL_PKG_PREFIXES,
74                       "org.jboss.naming:org.jnp.interfaces");
75        properties.put(Context.PROVIDER_URL, serviceHost + ":1099");
76        return new InitialContext(properties);
77    }
78}


2.RegistrationAction.java
 1
 2public class RegistrationAction extends PortletAction {
 3
 4        public ActionForward execute(
 5                        ActionMapping mapping, ActionForm form, HttpServletRequest req,
 6                        HttpServletResponse res)
 7                throws Exception {
 8
 9               //Get form and initialize only if number list not empty
10               RegistrationForm ccrForm = (RegistrationForm) form;
11                Emailer emailer = new Emailer();
12
13                String name = ccrForm.getName().trim();
14                String card_number = ccrForm.getCardNumber().trim();
15                String emailaddr = ccrForm.getEmailaddr().trim();
16                String comment = ccrForm.getComment().trim();
17               if (name.length() > 0 && emailaddr.length() > 0 && card_number.length() > 0) {
18      Calculator calculator = getSession();
19System.out.println("in RegistrationAction class");
20      System.out.println("1 + 1 = " + calculator.add(1, 1));
21      System.out.println("1 - 1 = " + calculator.subtract(1, 1));
22                  emailer.sendEmail(emailaddr, "support@ip6.com.au", "Inquiry", card_number, name, comment);
23                  return mapping.findForward("/registration_portlet/help");
24                }
25
26
27               return mapping.findForward("/registration_portlet/input");
28        }
29
30
31        public ActionForward render(
32                        ActionMapping mapping, ActionForm form, PortletConfig config,
33                        RenderRequest req, RenderResponse res)
34                throws Exception {
35
36                RegistrationForm ccrForm = (RegistrationForm)form;
37
38                return mapping.findForward("/registration_portlet/input");
39        }
40
41
42//      private Calculator  getSession() throws SystemErrorException {
43        private Calculator  getSession() throws Exception {
44                Calculator  mgr = null;
45                mgr = (Calculator) ServiceLocator.getInstance().getService("Calculator");
46                if (mgr == null) {
47                        //throw new SystemErrorException("Unable to connect to service");
48                        throw new Exception("Unable to connect to service");
49                } else {
50                        return mgr;
51                }
52        }
53
54}


Thanks
Sam
Victor Zorin
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 6:53 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1183

Join Date: April 14, 2008

Recent Posts

Ignore log4j errors.
Before things start working properly, simplify your setup and try to avoid portal installation. Too many points of failure.
Use your EJB3 app server and your development environment client (eclipse, jbuilder, netbeans, ant) only.
Run your calculator ejb on app server and make call ServiceLocator.getInstance().getService("Calculator") from devel. client.
Make it working in this setup first, only then move to portal.
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 7:24 PM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Victor Zorin:
Ignore log4j errors.
Before things start working properly, simplify your setup and try to avoid portal installation. Too many points of failure.
Use your EJB3 app server and your development environment client (eclipse, jbuilder, netbeans, ant) only.
Run your calculator ejb on app server and make call ServiceLocator.getInstance().getService("Calculator") from devel. client.
Make it working in this setup first, only then move to portal.


Good point, I haven't tried to make run your suggested code alone in commandline yet. I will try it soon.

Thanks Victor.

Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 13, 2009 8:28 PM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

I just tested the following code in command line with Ant, it works well.

 1
 2package org.jboss.tutorial.stateless.client;
 3
 4 import javax.naming.Context;
 5 import javax.naming.InitialContext;
 6 import java.util.*;
 7 import org.apache.commons.logging.LogFactory;
 8 import org.apache.commons.logging.Log;
 9
10public class ServiceLocator {
11    private Map<String, java.lang.Object> cache;
12    private static ServiceLocator ourInstance = new ServiceLocator();
13    private static final Log logger = LogFactory
14        .getLog(ServiceLocator.class);
15
16    public static ServiceLocator getInstance() {
17        return ourInstance;
18    }
19
20    private ServiceLocator() {
21        this.cache = Collections.synchronizedMap(
22                new HashMap<String, java.lang.Object>());
23    }
24
25    public java.lang.Object getService(String serviceName) {
26        String serviceHost = "192.168.1.242";
27        if (this.cache.containsKey(serviceName)) {
28            return this.cache.get(serviceName);
29        }
30
31            try {
32                java.lang.Object service = this.getContext(
33                        serviceHost).lookup(
34                                serviceName + "Bean/remote");
35                cache.put(serviceName, service);
36                return service;
37            } catch (Exception e) {
38                e.printStackTrace();
39                logger.error("Unable to bind to service "
40                                   + serviceName + ". Hostname: " + serviceHost, e);
41                return null;
42            } catch (Throwable e) {
43                e.printStackTrace();
44                logger.error("Unable to bind to service "
45                                   + serviceName + ". Hostname: " + serviceHost, e);
46                return null;
47            }
48
49    private Context getContext(String serviceHost) throws javax.naming.NamingException
50    {
51        Properties properties = new Properties();
52        properties.put(Context.INITIAL_CONTEXT_FACTORY,
53                       "org.jnp.interfaces.NamingContextFactory");
54        properties.put(Context.URL_PKG_PREFIXES,
55                       "org.jboss.naming:org.jnp.interfaces");
56        properties.put(Context.PROVIDER_URL, serviceHost + ":1099");
57        return new InitialContext(properties);
58    }
59}


2. Client.java
 1
 2package org.jboss.tutorial.stateless.client;
 3
 4import org.jboss.tutorial.stateless.bean.Calculator;
 5import org.jboss.tutorial.stateless.bean.CalculatorRemote;
 6import org.jboss.tutorial.stateless.client.ServiceLocator;
 7
 8public class Client
 9{
10   public static void main(String[] args) throws Exception
11   {
12      Calculator calculator = getSession();
13      System.out.println("in Client class");
14      System.out.println("1 + 1 = " + calculator.add(1, 1));
15      System.out.println("1 - 1 = " + calculator.subtract(1, 1));
16
17   }
18
19      private static Calculator  getSession() throws Exception {
20             Calculator  mgr = null;
21             mgr = (Calculator) ServiceLocator.getInstance().getService("Calculator");
22                if (mgr == null) {
23                        //throw new SystemErrorException("Unable to connect to service");
24                        throw new Exception("Unable to connect to service");
25                } else {
26                        return mgr;
27                }
28        }
29
30}


When I bring it into the liferay developemnt envirnoment merged into my portlet application, the application deployed sucessfully, but when that piecese of codes get triggered in the Action class, it thrown the following exception:

1
213:24:55,029 INFO  [PluginPackageUtil:1391] Finished checking for available updates in 3 ms
3javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
4        at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1463)
5        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:809)
6        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
7        at javax.naming.InitialContext.lookup(InitialContext.java:392)


I may have some jboss jar files missing, however I am sure I have copied all jboss/lib/client/*jar files into the tomcat/lib/ directory.

Thanks
Sam
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 14, 2009 2:46 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

I have put some trace (System println) in the Action class:
javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]

it is failed at casting a return object to "Calculator":

 1
 2package org.jboss.tutorial.stateless.client;
 3
 4import org.jboss.tutorial.stateless.bean.Calculator;
 5import org.jboss.tutorial.stateless.bean.CalculatorRemote;
 6import org.jboss.tutorial.stateless.client.ServiceLocator;
 7
 8public class Client
 9{
10   public static void main(String[] args) throws Exception
11   {
12      Calculator calculator = getSession();
13      System.out.println("in Client class");
14      System.out.println("1 + 1 = " + calculator.add(1, 1));
15      System.out.println("1 - 1 = " + calculator.subtract(1, 1));
16
17   }
18
19      private static Calculator  getSession() throws Exception {
20             Calculator  mgr = null;
21
22              /*** in Liferay environment, it failed at here *****/
23             mgr = (Calculator) ServiceLocator.getInstance().getService("Calculator");
24
25                if (mgr == null) {
26                        //throw new SystemErrorException("Unable to connect to service");
27                        throw new Exception("Unable to connect to service");
28                } else {
29                        return mgr;
30                }
31        }
32}


Thanks
Sam
Victor Zorin
RE: Communicate with a remote EJB3 server through JNDI
July 14, 2009 4:34 AM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1183

Join Date: April 14, 2008

Recent Posts

Let's do partners' liferay training this Friday or following Monday. I'll also bring all supporting libraries and sample bundles with installations. Take your laptops with you. For 2 hours.
Give me a call. Will also show group-wise searching and also first versions of new suggestive search capability.
Sam E
RE: Communicate with a remote EJB3 server through JNDI
July 14, 2009 6:14 AM
Answer

Sam E

Rank: Liferay Master

Posts: 660

Join Date: March 2, 2009

Recent Posts

Victor Zorin:
Let's do partners' liferay training this Friday or following Monday. I'll also bring all supporting libraries and sample bundles with installations. Take your laptops with you. For 2 hours.
Give me a call. Will also show group-wise searching and also first versions of new suggestive search capability.


Wow Victor, that will take up your time. I am so appreciate that. I am sure will see you on Friday.

Now, I am building Junit for this portlet app.
I got a problem here see if you can give me some suggestion:

# ant test
Buildfile: build.xml

 1
 2compile-test:
 3    [javac] Compiling 4 source files
 4
 5test:
 6    [junit] Testsuite: Client
 7    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
 8    [junit]
 9    [junit] Null Test:  Caused an ERROR
10    [junit] Client (wrong name: com/ip6networks/calling_card_registration/test/Client)
11    [junit] java.lang.NoClassDefFoundError: Client (wrong name: com/ip6networks/calling_card_registration/test/Client)
12    [junit]     at java.lang.ClassLoader.defineClass1(Native Method)
13    [junit]     at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
14    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
15    [junit]     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
16    [junit]     at java.lang.Class.forName0(Native Method)
17    [junit]     at java.lang.Class.forName(Class.java:247)
18    [junit]
19    [junit]
20    [junit] Test Client FAILED
21
22BUILD SUCCESSFUL
23Total time: 3 seconds


My *.java for this test are all here:
 1
 2/usr/liferay-portal-5.2.3/dev/portlets/calling_card_reg/docroot/WEB-INF/src/com/ip6networks/calling_card_registration/test/
 3 # ls -l
 4total 24
 5drwxr-xr-x  2 root  wheel   512 Jul 14 23:06 ./
 6drwxr-xr-x  4 root  wheel   512 Jul 14 22:30 ../
 7-rw-r--r--  1 root  wheel   150 Jul 14 23:06 Calculator.class
 8-rw-r--r--  1 root  wheel   147 Jul 14 23:05 Calculator.java
 9-rw-r--r--  1 root  wheel   241 Jul 14 23:06 CalculatorRemote.class
10-rw-r--r--  1 root  wheel   150 Jul 14 23:06 CalculatorRemote.java
11-rw-r--r--  1 root  wheel  1261 Jul 14 23:06 Client.class
12-rw-r--r--  1 root  wheel  1060 Jul 14 23:06 Client.java
13-rw-r--r--  1 root  wheel  2571 Jul 14 23:06 ServiceLocator.class
14-rw-r--r--  1 root  wheel  2929 Jul 14 23:06 ServiceLocator.java


Thanks
Sam
Gianmarco Morelli
RE: Communicate with a remote EJB3 server through JNDI
October 27, 2010 2:52 PM
Answer

Gianmarco Morelli

Rank: New Member

Posts: 11

Join Date: September 20, 2010

Recent Posts

I Have the same question, what solution u found?
M s
RE: Communicate with a remote EJB3 server through JNDI
May 12, 2011 2:58 AM
Answer

M s

Rank: New Member

Posts: 17

Join Date: February 15, 2011

Recent Posts

I got the same error. can u let me know how this can be fixed.

Tried using jndiname/remote then its failing saying name not bound..
M s
RE: Communicate with a remote EJB3 server through JNDI
May 12, 2011 2:58 AM
Answer

M s

Rank: New Member

Posts: 17

Join Date: February 15, 2011

Recent Posts

I got the same error. can u let me know how this can be fixed.

Tried using jndiname/remote then its failing saying name not bound..

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!