1 22 package org.jboss.test.exception; 23 24 import java.rmi.RemoteException ; 25 import java.security.InvalidKeyException ; 26 import javax.ejb.CreateException ; 27 import javax.ejb.EJBException ; 28 import javax.ejb.SessionBean ; 29 import javax.ejb.SessionContext ; 30 import javax.naming.InitialContext ; 31 import javax.naming.NameNotFoundException ; 32 import javax.naming.NamingException ; 33 34 39 public class ExceptionTesterBean implements SessionBean 40 { 41 private SessionContext ctx; 42 43 public void ejbCreate() throws CreateException 44 { 45 try 46 { 47 InitialContext ic = new InitialContext (); 48 Boolean failInEjbCreate = (Boolean ) ic.lookup("java:comp/env/failInEjbCreate"); 49 if( failInEjbCreate.booleanValue() ) 50 throw new CreateException ("Failed in ejbCreate as requested"); 51 } 52 catch(NameNotFoundException ignore) 53 { 54 } 56 catch(NamingException e) 57 { 58 throw new CreateException ("Failed to access ENC, "+e.getMessage()); 59 } 60 } 61 62 public void applicationExceptionInTx() throws ApplicationException 63 { 64 throw new ApplicationException("Application exception from within " + 65 " an inherited transaction"); 66 } 67 68 public void applicationErrorInTx() 69 { 70 throw new ApplicationError("Application error from within " + 71 " an inherited transaction"); 72 } 73 74 public void ejbExceptionInTx() 75 { 76 throw new EJBException ("EJB exception from within " + 77 " an inherited transaction"); 78 } 79 80 public void runtimeExceptionInTx() 81 { 82 throw new RuntimeException ("Runtime exception from within " + 83 " an inherited transaction"); 84 } 85 86 public void remoteExceptionInTx() throws RemoteException 87 { 88 throw new RemoteException ("Remote exception from within " + 89 " an inherited transaction"); 90 } 91 92 public void applicationExceptionNewTx() throws ApplicationException 93 { 94 throw new ApplicationException("Application exception from within " + 95 " a new container transaction"); 96 } 97 98 public void applicationErrorNewTx() 99 { 100 throw new ApplicationError("Application error from within " + 101 " an inherited transaction"); 102 } 103 104 public void ejbExceptionNewTx() 105 { 106 throw new EJBException ("EJB exception from within " + 107 " a new container transaction"); 108 } 109 110 public void runtimeExceptionNewTx() 111 { 112 throw new RuntimeException ("Runtime exception from within " + 113 " a new container transaction"); 114 } 115 116 public void remoteExceptionNewTx() throws RemoteException 117 { 118 throw new RemoteException ("Remote exception from within " + 119 " a new container transaction"); 120 } 121 122 public void applicationExceptionNoTx() throws ApplicationException 123 { 124 throw new ApplicationException("Application exception without " + 125 " a transaction"); 126 } 127 128 public void applicationErrorNoTx() 129 { 130 throw new ApplicationError("Application error from within " + 131 " an inherited transaction"); 132 } 133 134 public void ejbExceptionNoTx() 135 { 136 throw new EJBException ("EJB exception without " + 137 " a transaction"); 138 } 139 140 public void runtimeExceptionNoTx() 141 { 142 throw new RuntimeException ("Runtime exception without " + 143 " a transaction"); 144 } 145 146 public void remoteExceptionNoTx() throws RemoteException 147 { 148 throw new RemoteException ("Remote exception without " + 149 " a transaction"); 150 } 151 152 public void securityExceptionByAppNoTx() 153 throws InvalidKeyException 154 { 155 throw new InvalidKeyException ("securityExceptionByAppNoTx"); 157 } 158 159 public void securityExceptionNoTx() 160 { 161 } 163 164 public void setSessionContext(SessionContext ctx) 165 { 166 this.ctx = ctx; 167 } 168 169 public void ejbActivate() 170 { 171 } 172 173 public void ejbPassivate() 174 { 175 } 176 177 public void ejbRemove() 178 { 179 } 180 } 181 | Popular Tags |