-
1. Re: InitialContext reference and definition
peterj Jan 20, 2009 2:03 PM (in response to davestar)I think you are missing the jndi.properties file. It should contain:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=jnp://localhost:1099 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
-
2. Re: InitialContext reference and definition
davestar Jan 20, 2009 3:17 PM (in response to davestar)Thanks Peter!
I no longer get the NoInitialContext exception.
Now when I do a look up with the codeBurdenRateFacade bean = (BurdenRateFacade)context.lookup("BurdenRateFacade");
I get a Classcast exception.java.lang.ClassCastException: org.jnp.interfaces.NamingContext
I did acontext.lookup("BurdenRateFacade").getClass()
and it prints org.jnp.interfaces.NamingContext
I have the following entries in my jndi.propertiesjava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces java.naming.provider.url=jnp://localhost:1099
-
3. Re: InitialContext reference and definition
peterj Jan 20, 2009 3:47 PM (in response to davestar)You need to lookup "BurdenRateFacade/remote". Note the full name in the JNDI tree that you posted earlier.
-
4. Re: InitialContext reference and definition
davestar Jan 20, 2009 4:20 PM (in response to davestar)Thanks Peter! it worked
-
5. Re: InitialContext reference and definition
pepelara Jan 27, 2009 9:28 AM (in response to davestar)Hi,
How do I call a local interface?
This is then Global JNDI Namespace from then JMX Console of
JBoss 4.2.2 GA,+- CalculatorEAR (class: org.jnp.interfaces.NamingContext) | +- CalculatorBean (class: org.jnp.interfaces.NamingContext) | | +- local (proxy: $Proxy62 implements interface jboss.tutorial.Calculator,interface org.jboss.ejb3.JBossProxy)
and then client is,package jboss.tutorial; import java.util.Properties; import javax.ejb.EJB; import javax.naming.InitialContext; import javax.naming.Context; public class CalculatorClient { @EJB private static Calculator calculator; public CalculatorClient() { try { Properties props = new Properties(); props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); props.put("java.naming.factory.url.pkgs", "jnp://localhost:1099"); props.put("java.naming.provider.url", "jnp://localhost:1099"); Context ctx = new InitialContext(props); calculator = (Calculator) ctx.lookup("CalculatorBean/local"); } catch (Exception ex) { System.out.println("Couldn’t create calculator bean. "+ ex.getMessage()); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub CalculatorClient cClient = new CalculatorClient(); System.out.println("1 + 1 = " + calculator.add(1, 1)); System.out.println("1 - 1 = " + calculator.subtract(1, 1)); } }
The output gives me the Exception,Couldn’t create calculator bean. CalculatorBean not bound
Regards,
pepelara -
6. Re: InitialContext reference and definition
jaikiran Jan 27, 2009 9:46 AM (in response to davestar)ctx.lookup("CalculatorBean/local")
Should bectx.lookup("CalculatorEAR/CalculatorBean/local")
-
7. Re: InitialContext reference and definition
pepelara Jan 27, 2009 10:54 AM (in response to davestar)Hi,
It is working ok when I call the remote interface.
I do it as you say. It works fine.
But about the local interface, then console of Eclipse
gives me the following exception,Caught an unexpected exception! javax.ejb.EJBException: Invalid (i.e. remote) invocation of local interface (null container) at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:80) at $Proxy0.add(Unknown Source) at jboss.tutorial.CalculatorClient.doOperations(CalculatorClient.java:29) at jboss.tutorial.CalculatorClient.main(CalculatorClient.java:45)
This is my new client,public class CalculatorClient { @EJB private static Calculator calculator; public CalculatorClient() { try { Properties props = new Properties(); props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); props.put("java.naming.factory.url.pkgs", "jnp://localhost:1099"); props.put("java.naming.provider.url", "jnp://localhost:1099"); Context ctx = new InitialContext(props); calculator = (Calculator) ctx.lookup("CalculatorEAR/CalculatorBean/local"); } catch (Exception ex) { System.out.println("Couldn’t create calculator bean. "+ ex.getMessage()); } } public void doOperations() { try { System.out.println("1 + 1 = " + calculator.add(1, 1)); System.out.println("1 - 1 = " + calculator.subtract(1, 1)); System.exit(0); } catch (Exception ex) { System.err.println("Caught an unexpected exception!"); ex.printStackTrace(); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub CalculatorClient cClient = new CalculatorClient(); cClient.doOperations(); } }
The exception occurs when I call the doOperations() method.
Thanks,
pepelara -
8. Re: InitialContext reference and definition
pepelara Jan 27, 2009 12:40 PM (in response to davestar)Hi,
Take a look at this post,
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4105969#4105969
I think he has got the solution.
But I have no idea about what he is saying.
Load balancing and cluster????
Help!
Regards,
pepelara