001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.exception;
023:
024: import java.rmi.RemoteException;
025: import java.security.GeneralSecurityException;
026: import java.security.InvalidKeyException;
027: import javax.ejb.CreateException;
028: import javax.ejb.EJBException;
029: import javax.ejb.SessionBean;
030: import javax.ejb.SessionContext;
031: import javax.naming.InitialContext;
032: import javax.naming.NameNotFoundException;
033: import javax.naming.NamingException;
034:
035: /** Tests of exception propagation via remote and local interfaces
036: *
037: * @author Scott.Stark@jboss.org
038: * @version $Revision: 57211 $
039: */
040: public class ExceptionTesterBean implements SessionBean {
041: private SessionContext ctx;
042:
043: public void ejbCreate() throws CreateException {
044: try {
045: InitialContext ic = new InitialContext();
046: Boolean failInEjbCreate = (Boolean) ic
047: .lookup("java:comp/env/failInEjbCreate");
048: if (failInEjbCreate.booleanValue())
049: throw new CreateException(
050: "Failed in ejbCreate as requested");
051: } catch (NameNotFoundException ignore) {
052: // Assume failInEjbCreate = false
053: } catch (NamingException e) {
054: throw new CreateException("Failed to access ENC, "
055: + e.getMessage());
056: }
057: }
058:
059: public void applicationExceptionInTx() throws ApplicationException {
060: throw new ApplicationException(
061: "Application exception from within "
062: + " an inherited transaction");
063: }
064:
065: public void applicationErrorInTx() {
066: throw new ApplicationError("Application error from within "
067: + " an inherited transaction");
068: }
069:
070: public void ejbExceptionInTx() {
071: throw new EJBException("EJB exception from within "
072: + " an inherited transaction");
073: }
074:
075: public void runtimeExceptionInTx() {
076: throw new RuntimeException("Runtime exception from within "
077: + " an inherited transaction");
078: }
079:
080: public void remoteExceptionInTx() throws RemoteException {
081: throw new RemoteException("Remote exception from within "
082: + " an inherited transaction");
083: }
084:
085: public void applicationExceptionNewTx() throws ApplicationException {
086: throw new ApplicationException(
087: "Application exception from within "
088: + " a new container transaction");
089: }
090:
091: public void applicationErrorNewTx() {
092: throw new ApplicationError("Application error from within "
093: + " an inherited transaction");
094: }
095:
096: public void ejbExceptionNewTx() {
097: throw new EJBException("EJB exception from within "
098: + " a new container transaction");
099: }
100:
101: public void runtimeExceptionNewTx() {
102: throw new RuntimeException("Runtime exception from within "
103: + " a new container transaction");
104: }
105:
106: public void remoteExceptionNewTx() throws RemoteException {
107: throw new RemoteException("Remote exception from within "
108: + " a new container transaction");
109: }
110:
111: public void applicationExceptionNoTx() throws ApplicationException {
112: throw new ApplicationException("Application exception without "
113: + " a transaction");
114: }
115:
116: public void applicationErrorNoTx() {
117: throw new ApplicationError("Application error from within "
118: + " an inherited transaction");
119: }
120:
121: public void ejbExceptionNoTx() {
122: throw new EJBException("EJB exception without "
123: + " a transaction");
124: }
125:
126: public void runtimeExceptionNoTx() {
127: throw new RuntimeException("Runtime exception without "
128: + " a transaction");
129: }
130:
131: public void remoteExceptionNoTx() throws RemoteException {
132: throw new RemoteException("Remote exception without "
133: + " a transaction");
134: }
135:
136: public void securityExceptionByAppNoTx() throws InvalidKeyException {
137: // This exception should be propagated as is
138: throw new InvalidKeyException("securityExceptionByAppNoTx");
139: }
140:
141: public void securityExceptionNoTx() {
142: // The method permissions should cause the security exception
143: }
144:
145: public void setSessionContext(SessionContext ctx) {
146: this .ctx = ctx;
147: }
148:
149: public void ejbActivate() {
150: }
151:
152: public void ejbPassivate() {
153: }
154:
155: public void ejbRemove() {
156: }
157: }
|