Search in sources :

Example 16 with Interceptor$JAXB.writeInterceptor

use of org.apache.openejb.jee.Interceptor$JAXB.writeInterceptor 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);
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) NamedMethod(org.apache.openejb.jee.NamedMethod) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) ArrayList(java.util.ArrayList) List(java.util.List) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 17 with Interceptor$JAXB.writeInterceptor

use of org.apache.openejb.jee.Interceptor$JAXB.writeInterceptor 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();
    }
}
Also used : LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) Interceptor(org.apache.openejb.jee.Interceptor) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 18 with Interceptor$JAXB.writeInterceptor

use of org.apache.openejb.jee.Interceptor$JAXB.writeInterceptor 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;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 19 with Interceptor$JAXB.writeInterceptor

use of org.apache.openejb.jee.Interceptor$JAXB.writeInterceptor 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;
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar) Module(org.apache.openejb.testing.Module)

Example 20 with Interceptor$JAXB.writeInterceptor

use of org.apache.openejb.jee.Interceptor$JAXB.writeInterceptor 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;
}
Also used : MEJBBean(org.apache.openejb.mgmt.MEJBBean) InternalSecurityInterceptor(org.apache.openejb.security.internal.InternalSecurityInterceptor) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) DeployerEjb(org.apache.openejb.assembler.DeployerEjb) JMXDeployer(org.apache.openejb.assembler.monitoring.JMXDeployer) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ConfigurationInfoEjb(org.apache.openejb.assembler.classic.cmd.ConfigurationInfoEjb) Interceptor(org.apache.openejb.jee.Interceptor) InternalSecurityInterceptor(org.apache.openejb.security.internal.InternalSecurityInterceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

Interceptor (org.apache.openejb.jee.Interceptor)20 EjbJar (org.apache.openejb.jee.EjbJar)16 InterceptorBinding (org.apache.openejb.jee.InterceptorBinding)15 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)11 StatelessBean (org.apache.openejb.jee.StatelessBean)10 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)6 NamedMethod (org.apache.openejb.jee.NamedMethod)5 ArrayList (java.util.ArrayList)3 Module (org.apache.openejb.testing.Module)3 InitialContext (javax.naming.InitialContext)2 Assembler (org.apache.openejb.assembler.classic.Assembler)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)2 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)2 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)2 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)2 EjbModule (org.apache.openejb.config.EjbModule)2 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)2 ContainerTransaction (org.apache.openejb.jee.ContainerTransaction)2 Interceptor$JAXB.readInterceptor (org.apache.openejb.jee.Interceptor$JAXB.readInterceptor)2