1 25 package org.objectweb.sampleCluster2.web; 26 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.naming.NamingException ; 30 import javax.rmi.PortableRemoteObject ; 31 import javax.servlet.http.HttpServlet ; 32 33 import org.objectweb.sampleCluster2.ejb.MyEjb1; 34 import org.objectweb.sampleCluster2.ejb.MyEjb1Home; 35 import org.objectweb.sampleCluster2.ejb.MyStateful; 36 import org.objectweb.sampleCluster2.ejb.MyStatefulHome; 37 38 import org.objectweb.jonas.common.JProp; 39 import org.objectweb.jonas.common.Log; 40 41 import org.objectweb.util.monolog.api.BasicLevel; 42 import org.objectweb.util.monolog.api.Logger; 43 44 49 public abstract class AbstractServlet extends HttpServlet { 50 51 54 public void init() { 55 56 if (logger == null) { 57 logger = Log.getLogger("org.objectweb.jonas_tests"); 58 } 59 logger.log(BasicLevel.DEBUG, ""); 60 } 61 62 66 public MyStateful createStatefulEJB() { 67 Context ctx = null; 68 MyStatefulHome home = null; 69 MyStateful bean = null; 70 71 try { 72 ctx = new InitialContext (); 73 } catch (NamingException e) { 74 e.printStackTrace(); 75 } 76 77 String bName = "java:comp/env/ejb/MyStatefulHome"; 79 try { 80 home = (MyStatefulHome) PortableRemoteObject.narrow(ctx.lookup(bName), MyStatefulHome.class); 81 bean = home.create(); 82 } catch (Exception e) { 83 e.printStackTrace(); 84 } 85 return bean; 86 } 87 88 92 public MyEjb1 theEJB() { 93 Context ctx = null; 94 MyEjb1Home home = null; 95 MyEjb1 bean = null; 96 97 try { 98 ctx = new InitialContext (); 99 } catch (NamingException e) { 100 e.printStackTrace(); 101 } 102 103 String bName = "java:comp/env/ejb/MyEjb1Home"; 105 try { 106 home = (MyEjb1Home) PortableRemoteObject.narrow(ctx.lookup(bName), MyEjb1Home.class); 107 bean = home.create(); 108 } catch (Exception e) { 109 e.printStackTrace(); 110 } 111 return bean; 112 } 113 114 118 public static String getMyJonasInstanceName() { 119 120 String s = "unknown"; 121 try { 122 JProp jp = JProp.getInstance(); 123 s = jp.getValue("jonas.name"); 124 } catch (Exception e) { 125 e.printStackTrace(); 126 } 127 return s; 128 } 129 130 134 public Logger getLogger() { 135 return logger; 136 } 137 138 141 private static Logger logger = null; 142 } 143 144 | Popular Tags |