| 1 package sellwin.server; 2 3 4 import java.util.*; 5 import java.rmi.*; 6 7 import javax.ejb.*; 8 import javax.naming.*; 9 import javax.rmi.PortableRemoteObject ; 10 11 15 21 public class EJBUtils { 22 public final static String JNDI_NAME="SellwinSessionHome"; 23 public final static String WEBLOGIC_URL="t3://localhost:7001"; 24 28 public static Context getInitialContext() throws NamingException { 29 30 try { 31 Properties h = new Properties(); 33 h.put(Context.INITIAL_CONTEXT_FACTORY, 34 "weblogic.jndi.WLInitialContextFactory"); 35 h.put(Context.PROVIDER_URL, WEBLOGIC_URL); 36 return new InitialContext(h); 37 } catch (NamingException ne) { 38 System.out.println("We were unable to get a connection to the WebLogic server at "+WEBLOGIC_URL); 39 System.out.println("Please make sure that the server is running."); 40 throw ne; 41 } 42 } 43 44 47 public static Object narrow(Object ref, Class c) { 48 return PortableRemoteObject.narrow(ref, c); 49 } 50 51 public static SellwinSession ejbConnect() 52 throws NamingException, CreateException, RemoteException { 53 54 String JNDI_NAME = "SellwinSessionHome"; 55 56 Context ctx = getInitialContext(); 57 58 Object home = ctx.lookup(JNDI_NAME); 59 SellwinSessionHome sellwinHome = (SellwinSessionHome)narrow(home, SellwinSessionHome.class); 60 System.out.println("found sellwin session home in jndi"); 61 62 SellwinSession sellwin = (SellwinSession)narrow(sellwinHome.create(), SellwinSession.class); 63 System.out.println("created SellwinSession remote reference"); 64 return sellwin; 65 66 } 67 68 } 69 | Popular Tags |