1 22 package org.jboss.test.hello.ejb; 23 24 import java.io.Serializable ; 25 import javax.ejb.EJBException ; 26 import javax.ejb.DuplicateKeyException ; 27 import javax.ejb.FinderException ; 28 import javax.naming.InitialContext ; 29 30 import org.jboss.test.util.ejb.SessionSupport; 31 import org.jboss.test.hello.interfaces.Hello; 32 import org.jboss.test.hello.interfaces.HelloData; 33 import org.jboss.test.hello.interfaces.HelloException; 34 import org.jboss.test.hello.interfaces.LocalHelloLogHome; 35 import org.jboss.test.hello.interfaces.LocalHelloLog; 36 import org.jboss.test.hello.interfaces.NotSerializable; 37 38 43 public class HelloBean 44 extends SessionSupport 45 { 46 public String hello(String name) 47 { 48 return "Hello "+name+"!"; 49 } 50 51 public String loggedHello(String name) 52 { 53 long begin = System.currentTimeMillis(); 54 LocalHelloLog bean = null; 55 LocalHelloLogHome home = null; 56 try 57 { 58 InitialContext ctx = new InitialContext (); 59 home = (LocalHelloLogHome) ctx.lookup("java:comp/env/ejb/LocalHelloLogHome"); 60 bean = home.create(name); 61 log.info("Created LocalHelloLog with key="+name); 62 if( bean != null ) 63 bean.setStartTime(begin); 64 } 65 catch(DuplicateKeyException e) 66 { 67 try 68 { 69 bean = home.findByPrimaryKey(name); 70 log.info("Found LocalHelloLog with key="+name); 71 if( bean != null ) 72 bean.setStartTime(begin); 73 } 74 catch(FinderException fe) 75 { 76 log.debug("LocalHelloLog find failed", fe); 77 } 78 } 79 catch(Exception e) 80 { 81 log.debug("LocalHelloLog create failed", e); 82 } 83 String reply = "Hello "+name+"!"; 84 long end = System.currentTimeMillis(); 85 if( bean != null ) 86 bean.setEndTime(end); 87 88 return reply; 89 } 90 91 public String helloException(String name) 92 throws HelloException 93 { 94 throw new HelloException("Catch me"); 95 } 96 97 public Hello helloHello(Hello hello) 98 { 99 return hello; 100 } 101 102 public String howdy(HelloData name) 103 { 104 return "Howdy "+name.getName()+"!"; 105 } 106 107 public String sleepingHello(String name, long sleepTimeMS) 108 { 109 if( sleepTimeMS <= 0 ) 110 sleepTimeMS = 1; 111 try 112 { 113 Thread.sleep(sleepTimeMS); 114 } 115 catch(InterruptedException ignore) 116 { 117 } 118 return "Hello "+name+"!"; 119 } 120 121 public Object getCNFEObject() 122 { 123 return new ServerData(); 124 } 125 public void throwException() 126 { 127 throw new EJBException ("Something went wrong"); 128 } 129 130 public void setNotSerializable(NotSerializable ignored) 131 { 132 throw new RuntimeException ("Should not get here"); 133 } 134 public NotSerializable getNotSerializable() 135 { 136 return new NotSerializable(); 137 } 138 139 static class ServerData implements Serializable 140 { 141 } 142 } 143 | Popular Tags |