ga

Tuesday, April 22, 2008

EJB 3. Wooohooo???

I was trying to decide if I should learn EJB 3 and more of JEE 5 or if I should jump into Spring. Looking at the available jobs on indeed points to Spring, but I went with EJB anyway because I think it may eventually pick up steam.

So, I did a simple app and my first complaint is that unless I missed something Sun's documentation/tutorial isn't that good. It seems the samples are geared to a single server install where the EJB and the clients are bundled into the same EAR file. My first foray I wanted to have them separate so I could easily test on remote servers. Thankfully, there is google and I found why my client could never find the EJB. Apparently, you have to do something like this:

Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://127.0.0.1:3700/");
InitialContext ic = new InitialContext(env);
bf2EJB = (BF2Remote) ic.lookup("BF2");

I guess I should mention I was using Glassfish. I suppose the code is simple enough, but I think the client has to do to much. IMHO, the only thing the client should have to do is specify a protocol (iiop, rmi, etc.) and the address:port (new InitialContext("iiop://127.0.0.1:3700). When the server gets a connection it should resolve to a default factory to talk to unless another is specified. Again, I wanted to try this on geronimo, but I just don't have time to be bothered with the extra hoops you have to jump through with it.

Do all JEE 5 servers require the initial context factory to be set?

Is it bad to have a server receive a lookup call and that server looks for it locally and returns it if it is found (in my case you have to specify the server address)?

0 comments: