1 22 package org.jboss.ejb3.test.initial; 23 24 import javax.annotation.Resource; 25 import javax.annotation.PostConstruct; 26 import javax.interceptor.AroundInvoke; 27 import javax.ejb.EJBContext ; 28 import javax.interceptor.Interceptors; 29 import javax.interceptor.InvocationContext; 30 import javax.ejb.PostActivate ; 31 import javax.annotation.PreDestroy; 32 import javax.ejb.PrePassivate ; 33 import javax.ejb.Stateless ; 34 35 39 @Stateless 40 @Interceptors ({FirstInterceptor.class, SecondInterceptor.class}) 41 public class InterceptedSLTestBean implements InterceptedSLTest 42 { 43 @Resource 44 EJBContext ejbCtx; 45 46 public int testMethod(int i) 47 { 48 System.out.println("InterceptedSLTestBean testMethod"); 49 return i; 50 } 51 52 public int throwsThrowable(int i)throws Throwable 53 { 54 System.out.println("InterceptedSLTestBean throwsThrowable"); 55 throw new Throwable (); 56 } 57 58 @AroundInvoke 59 public Object myInterceptor(InvocationContext ctx) throws Exception 60 { 61 System.out.println("Intercepting in InterceptedSLTestBean.myInterceptor()"); 62 int val = (Integer )ctx.getContextData().get("DATA"); 63 64 int ret = (Integer )ctx.proceed(); 65 ejbCtx.setRollbackOnly(); 66 val = (Integer )ctx.getContextData().get("DATA"); 67 ret += val; 68 if (ctx.getTarget() != this) throw new RuntimeException ("ctx.getBean() != this: " + ctx.getTarget() + " != " + this); 69 return ret; 70 } 71 72 @PostConstruct 73 public void postConstruct() 74 { 75 TestStatusBean.postConstruct = true; 76 } 77 78 @PreDestroy 79 public void preDestroy() 80 { 81 TestStatusBean.preDestroy = true; 82 } 83 84 @PrePassivate 85 public void prePassivate() 86 { 87 throw new RuntimeException ("SLSBs don't have PrePassivate methods"); 88 } 89 90 @PostActivate 91 public void postActivate() 92 { 93 throw new RuntimeException ("SLSBs don't have PostActivate methods"); 94 } 95 96 } 97 | Popular Tags |