geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: Exception by using EJB3 on Geronimo 2
Date Fri, 04 Apr 2008 07:03:35 GMT
Additionally, you'll want to update your client code as follows:


   public void runTest() throws Exception {
     Properties p = new Properties();
     p.put("java.naming.factory.initial",  
"org.apache.openejb.client.RemoteInitialContextFactory");
     p.put("java.naming.provider.url", "ejbd://localhost:4201");

     InitialContext ctx = new InitialContext(p);
     SimpleBean bean = (SimpleBean) ctx.lookup("ExampleLocal");
     String result = bean.sayHello("Billy Bob");
     System.out.println(result);
   }

Couple notes on the differences.

First, as David J. mentions, the global JNDI names of EJBs are not  
standard (for that you need an official app client), however if you  
like the way it is in the Sun example, you can setup Geronimo to use  
that style [1].  Just set a system property in Geronimo  
"openejb.jndiname.format={deploymentId}"

Second, you can alternately set "java.naming.factory.initial" and  
"java.naming.provider.url" in three different ways:
   1.  as plain java system properties either via System.setProperty  
in java client code
   2.  via vm flags such as "-Djava.naming.provider.url=ejbd:// 
localhost:4201" on your client vm
   3.  creating a jndi.properties file containing the above values and  
including it in your client classpath.

That said, I'll point out we do have some far better examples for  
learning EJB 3.0.  First, the above example requires you to manually  
start the server, manually deploy, manually run the client (which is  
not a junit test), and then to manually undeploy, manually stop.. etc.  
etc.

Download these examples and give them a try:

   http://www.apache.org/dyn/closer.cgi/openejb/3.0-beta-2/openejb-examples-3.0-beta-2.zip

I recommend the simple-stateless to start.  All come with Ant and  
Maven build files (use what you like) and all examples come with  
ordinary JUnit test cases that will do all the start/stop/deploy/ 
undeploy work for you.  You'll be amazed at how much is happening with  
so little work on your part and you'll be amazed at how fast they run.

Give them a try and if you run into any issues, just ping the list and  
we'll help you out.

-David

[1] http://cwiki.apache.org/GMOxDOC21/client-jndi-names.html


On Apr 2, 2008, at 11:51 PM, David Jencks wrote:
> Thanks for resending with comprehensible formatting :-)
>
> I think you left out some information about your environment.  I  
> think there is a jndi.properties file in the client's classpath that  
> is directing the use of a corba name service for jndi lookups, using  
> the sun ee corba implementation in the client.  It's somewhat tricky  
> to get that to work.
>
> Access to ejbs from anything other than a javaee module in the same  
> javaee application is not standardized.  I recommend taking the  
> corba and sun stuff out of your client and including the openejb3  
> client jar in its classpath.  This should set the jndi properties  
> correctly for the openejb transport.
>
> If you look in the server log as your application starts you should  
> see the global jndi names your ejbs are bound under and that you can  
> use with the openejb jndi provider to look up your ejbs.
>
> hope this helps
> david jencks
>
> On Apr 1, 2008, at 8:41 AM, thomas2004 wrote:
>
>>
>> Hi all,
>>
>> I am learning the EJB3. I follow a tutorial under:
>> http://www.webagesolutions.com/knowledgebase/javakb/jkb005/index.html
>>
>> and it runs quite well since I use the SUN Application Server.
>>
>> So I deployed the EJB Jars onto Geronimo 2. Bu tas I try to start  
>> the client
>> I got exception as follow:
>>
>> Caused by: java.net.ConnectException: Connection refused: connect
>> 	at sun.nio.ch.Net.connect(Native Method)
>> 	at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:464)
>> 	at
>> com 
>> .sun 
>> .corba.ee.impl.orbutil.ORBUtility.openSocketChannel(ORBUtility.java: 
>> 105)
>> 	at
>> com 
>> .sun 
>> .enterprise 
>> .iiop.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java: 
>> 332)
>> 	... 16 more
>>
>> Here is my session bean:
>>
>> @Stateless(name = "Example",  mappedName = "ejb/SimpleBeanJNDI")
>> public class SimpleBeanImpl implements SimpleBean {
>> 	public String sayHello(String name) {
>> 		return "Hello, the text you enter is: " + name + "!";
>> 	}
>> }
>>
>>
>> And here is the client and lookup:
>>
>> public class TestClient {
>>
>> 	public void runTest() throws Exception {
>> 		InitialContext ctx = new InitialContext();
>> 		SimpleBean bean = (SimpleBean) ctx.lookup("ejb/SimpleBeanJNDI");
>> 		String result = bean.sayHello("Billy Bob, Wei Chen");
>> 		System.out.println(result);
>> 	}
>>
>> 	public static void main(String[] args) {
>> 		try {
>> 			TestClient cli = new TestClient();
>> 			cli.runTest();
>>
>> 		} catch (Exception e) {
>> 			e.printStackTrace();
>> 		}
>> 	}
>> }
>>
>> Has someone idea?
>>
>> Regards
>>
>> Thomas
>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Exception-by-using-EJB3-on-Geronimo-2-tp16418687s134p16418687.html
>> Sent from the Apache Geronimo - Users mailing list archive at  
>> Nabble.com.
>>
>
>


Mime
View raw message