Thursday, June 16, 2011

Establishing A Baseline

Before we try to do anything fancy, let's get a simple EJB up and running. For this experiment we'll use Java local/remote interfaces, leaving just the bean implementation in Scala.

Remote Interface:

package com.scalaejb;

import javax.ejb.Remote;

@Remote
public interface ScalaEjbRemote {
}


Local Interface:
package com.scalaejb;

import javax.ejb.Local;

@Local
public interface ScalaEjbLocal {
public void sayHi( String name );
}
Bean Implementation:

package com.scalaejb

import javax.ejb.Stateless

@Stateless
class ScalaEjbImpl extends ScalaEjbRemote with ScalaEjbLocal {
def sayHi( name:String ) { println("Hi, "+name ) }
}


And finally a client, which is in my case a ServletContextListener, because I want to inject an EJB reference and call a method on the bean upon startup of the web application.

package com.scalaejb.servlet;

import javax.servlet.*;
import javax.ejb.*;

import com.scalaejb.ScalaEjbLocal;


public class StartupShutdown implements javax.servlet.ServletContextListener {

@EJB private ScalaEjbLocal localEJB;

public void contextInitialized( ServletContextEvent sce ) {
System.out.println("HERE!!! "+localEJB);
localEJB.sayHi("Fred");
}
public void contextDestroyed( ServletContextEvent sce ) { }
}
So... what happens when this is packaged, deployed, and ran? It works. My injection println and my call to sayHi happens and the appropriate output is present in the log file.

This will be my baseline going forward with further experiments.

No comments:

Post a Comment