use of org.apache.openejb.jee.Interceptor$JAXB.readInterceptor in project tomee by apache.
the class StatelessInterceptorTest method buildTestApp.
public static EjbModule buildTestApp() throws Exception {
final EjbJar ejbJar = new EjbJar();
ejbJar.setId(StatelessInterceptorTest.class.getName());
final AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
ejbJar.addEnterpriseBean(new StatelessBean(Target2Bean.class));
final EnterpriseBean bean = ejbJar.addEnterpriseBean(new StatelessBean(TargetBean.class));
Interceptor interceptor;
interceptor = ejbJar.addInterceptor(new Interceptor(DefaultInterceptor.class));
ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
{
interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", List.class)));
}
{
interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", int.class)));
}
{
interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", boolean.class)));
}
final EnterpriseBean bean3 = ejbJar.addEnterpriseBean(new StatelessBean(Target3Bean.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean3));
binding.setExcludeDefaultInterceptors(true);
binding.setExcludeClassInterceptors(true);
return new EjbModule(ejbJar);
}
use of org.apache.openejb.jee.Interceptor$JAXB.readInterceptor in project tomee by apache.
the class TimeoutAroundTest method _testTimeoutAround.
public void _testTimeoutAround() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
// Configure AroundTimeout by deployment plan
final Interceptor interceptorA = new Interceptor(SimpleInterceptorA.class);
interceptorA.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(SimpleInterceptorA.class.getName(), "interceptorTimeoutAround"));
ejbJar.addInterceptor(interceptorA);
// Configure AroundTimeout by annotation
final Interceptor interceptorB = new Interceptor(SimpleInterceptorB.class);
ejbJar.addInterceptor(interceptorB);
// Override AroundTimeout annotation by deployment plan
final Interceptor interceptorC = new Interceptor(SimpleInterceptorC.class);
interceptorC.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(SimpleInterceptorC.class.getName(), "interceptorTimeoutAround"));
ejbJar.addInterceptor(interceptorC);
// Configure aroundTimeout by deployment plan
final StatelessBean subBeanA = new StatelessBean(SubBeanA.class);
subBeanA.addAroundTimeout("beanTimeoutAround");
ejbJar.addEnterpriseBean(subBeanA);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorA));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorB));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorC));
// Configure aroundTimeout by annotation
final StatelessBean subBeanB = new StatelessBean(SubBeanB.class);
ejbJar.addEnterpriseBean(subBeanB);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorA));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorB));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorC));
// Override aroundTimeout annotation by deployment plan
final StatelessBean subBeanC = new StatelessBean(SubBeanC.class);
subBeanC.addAroundTimeout("beanTimeoutAround");
ejbJar.addEnterpriseBean(subBeanC);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorA));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorB));
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorC));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assembler.createApplication(ejbJarInfo);
final InitialContext context = new InitialContext();
final List<Call> expectedResult = Arrays.asList(Call.INTERCEPTOR_BEFORE_AROUNDTIMEOUT, Call.INTERCEPTOR_BEFORE_AROUNDTIMEOUT, Call.INTERCEPTOR_BEFORE_AROUNDTIMEOUT, Call.BEAN_BEFORE_AROUNDTIMEOUT, Call.BEAN_TIMEOUT, Call.BEAN_AFTER_AROUNDTIMEOUT, Call.INTERCEPTOR_AFTER_AROUNDTIMEOUT, Call.INTERCEPTOR_AFTER_AROUNDTIMEOUT, Call.INTERCEPTOR_AFTER_AROUNDTIMEOUT);
{
final BeanInterface beanA = (BeanInterface) context.lookup("SubBeanALocal");
beanA.simpleMethod();
Thread.sleep(5000L);
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanB = (BeanInterface) context.lookup("SubBeanBLocal");
beanB.simpleMethod();
Thread.sleep(5000L);
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanC = (BeanInterface) context.lookup("SubBeanCLocal");
beanC.simpleMethod();
Thread.sleep(5000L);
assertEquals(expectedResult, result);
result.clear();
}
}
use of org.apache.openejb.jee.Interceptor$JAXB.readInterceptor in project tomee by apache.
the class CheckInvalidAroundTimeoutTest method testInvalidAroundTimeoutParameter.
@Keys({ @Key(value = "aroundInvoke.invalidArguments", count = 2), @Key(value = "aroundInvoke.badReturnType", count = 2) })
public EjbJar testInvalidAroundTimeoutParameter() throws Exception {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean("TestInvalidAroundTimeoutParameterBean", TestInvalidAroundTimeoutParameterBean.class));
ejbJar.addInterceptor(new Interceptor(TestInvalidAroundTimeoutParameterInterceptor.class));
return ejbJar;
}
use of org.apache.openejb.jee.Interceptor$JAXB.readInterceptor in project tomee by apache.
the class SecondStatelessInterceptedTest method module.
@Module
public EjbJar module() {
final EjbJar ejbJar = new EjbJar();
final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SecondStatelessInterceptedBean.class));
final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
assembly.addInterceptorBinding(new InterceptorBinding(bean)).setExcludeDefaultInterceptors(true);
return ejbJar;
}
use of org.apache.openejb.jee.Interceptor$JAXB.readInterceptor in project tomee by apache.
the class SystemApps method getSystemModule.
public static EjbModule getSystemModule() {
final EjbModule module = new EjbModule(new EjbJar("openejb"), new OpenejbJar());
final OpenejbJar openejbJar = module.getOpenejbJar();
final EjbJar ejbJar = module.getEjbJar();
//
//
// DONT MODIFY IT WITHOUT VALIDATING org.apache.openejb.config.SystemAppInfo.preComputedInfo()
//
//
ejbJar.addEnterpriseBean(singleton(DeployerEjb.class));
ejbJar.addEnterpriseBean(singleton(ConfigurationInfoEjb.class));
ejbJar.addEnterpriseBean(singleton(MEJBBean.class));
ejbJar.addInterceptor(new Interceptor(InternalSecurityInterceptor.class));
ejbJar.getAssemblyDescriptor().addInterceptorBinding(new InterceptorBinding("*", InternalSecurityInterceptor.class.getName()));
module.getMbeans().add(JMXDeployer.class.getName());
final SingletonBean bean = ejbJar.addEnterpriseBean(new SingletonBean("openejb/WebappDeployer", "org.apache.tomee.catalina.deployer.WebappDeployer"));
final EjbDeployment deployment = openejbJar.addEjbDeployment(bean);
deployment.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.annotationName}");
final SingletonBean exceptionManager = ejbJar.addEnterpriseBean(new SingletonBean("openejb/ExceptionManagerFacade", "org.apache.tomee.catalina.facade.ExceptionManagerFacadeBean"));
final EjbDeployment exceptionMgr = openejbJar.addEjbDeployment(exceptionManager);
exceptionMgr.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.annotationName}");
openejbJar.getProperties().put("openejb.deploymentId.format", "{ejbName}");
openejbJar.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.openejbLegacyName}");
return module;
}
Aggregations