Search in sources :

Example 11 with InterceptorBinding

use of org.apache.openejb.jee.InterceptorBinding 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)

Example 12 with InterceptorBinding

use of org.apache.openejb.jee.InterceptorBinding in project tomee by apache.

the class TransactionAttributesTest method test.

public void test() throws Exception {
    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();
    ejbJar.addEnterpriseBean(new StatelessBean(Color.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Red.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Crimson.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Scarlet.class));
    final List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
    declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "*", "*", "*"));
    declared.add(new ContainerTransaction(TransAttribute.SUPPORTS, "*", "Crimson", "*"));
    declared.add(new ContainerTransaction(TransAttribute.SUPPORTS, Color.class.getName(), "Scarlet", "*"));
    declared.add(new ContainerTransaction(TransAttribute.NEVER, Red.class.getName(), "Scarlet", "red"));
    declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "Scarlet", Scarlet.class.getMethod("scarlet")));
    ejbJar.getAssemblyDescriptor().addInterceptorBinding(new InterceptorBinding("*", AttributeInterceptor.class.getName()));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    loadAttributes(ejbJarInfo, "Color");
    assertAttribute("Never", Color.class.getMethod("color"));
    assertAttribute("RequiresNew", Color.class.getMethod("color", Object.class));
    assertAttribute("Mandatory", Color.class.getMethod("color", String.class));
    assertAttribute("Mandatory", Color.class.getMethod("color", Boolean.class));
    assertAttribute("Mandatory", Color.class.getMethod("color", Integer.class));
    loadAttributes(ejbJarInfo, "Red");
    assertAttribute("Never", Red.class.getMethod("color"));
    assertAttribute("Required", Red.class.getMethod("color", Object.class));
    assertAttribute("Mandatory", Red.class.getMethod("color", String.class));
    assertAttribute("Mandatory", Red.class.getMethod("color", Boolean.class));
    assertAttribute("Mandatory", Red.class.getMethod("color", Integer.class));
    assertAttribute("RequiresNew", Red.class.getMethod("red"));
    assertAttribute("Required", Red.class.getMethod("red", Object.class));
    assertAttribute("Required", Red.class.getMethod("red", String.class));
    loadAttributes(ejbJarInfo, "Crimson");
    assertAttribute("Supports", Crimson.class.getMethod("color"));
    assertAttribute("Supports", Crimson.class.getMethod("color", Object.class));
    assertAttribute("Supports", Crimson.class.getMethod("color", String.class));
    assertAttribute("Supports", Crimson.class.getMethod("color", Boolean.class));
    assertAttribute("Supports", Crimson.class.getMethod("color", Integer.class));
    assertAttribute("RequiresNew", Crimson.class.getMethod("red"));
    assertAttribute("Supports", Crimson.class.getMethod("red", Object.class));
    assertAttribute("Supports", Crimson.class.getMethod("red", String.class));
    assertAttribute("RequiresNew", Crimson.class.getMethod("crimson"));
    assertAttribute("Supports", Crimson.class.getMethod("crimson", String.class));
    loadAttributes(ejbJarInfo, "Scarlet");
    assertAttribute("Never", Scarlet.class.getMethod("color"));
    assertAttribute("Required", Scarlet.class.getMethod("color", Object.class));
    assertAttribute("Supports", Scarlet.class.getMethod("color", String.class));
    assertAttribute("Supports", Scarlet.class.getMethod("color", Boolean.class));
    assertAttribute("Supports", Scarlet.class.getMethod("color", Integer.class));
    assertAttribute("RequiresNew", Scarlet.class.getMethod("red"));
    assertAttribute("Never", Scarlet.class.getMethod("red", Object.class));
    assertAttribute("Never", Scarlet.class.getMethod("red", String.class));
    assertAttribute("Required", Scarlet.class.getMethod("scarlet"));
    assertAttribute("NotSupported", Scarlet.class.getMethod("scarlet", String.class));
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar)

Example 13 with InterceptorBinding

use of org.apache.openejb.jee.InterceptorBinding 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 14 with InterceptorBinding

use of org.apache.openejb.jee.InterceptorBinding 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 15 with InterceptorBinding

use of org.apache.openejb.jee.InterceptorBinding in project tomee by apache.

the class StatefulInterceptorTest method buildTestApp.

public EjbModule buildTestApp() {
    final EjbJar ejbJar = new EjbJar();
    final AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
    final EnterpriseBean bean = ejbJar.addEnterpriseBean(new StatefulBean(TargetBean.class));
    Interceptor interceptor;
    interceptor = ejbJar.addInterceptor(new Interceptor(ClassInterceptor.class));
    ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
    interceptor = ejbJar.addInterceptor(new Interceptor(DefaultInterceptor.class));
    ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
    interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptor.class));
    final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
    binding.setMethod(new NamedMethod("echo"));
    return new EjbModule(this.getClass().getClassLoader(), this.getClass().getSimpleName(), "test", ejbJar, null);
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) NamedMethod(org.apache.openejb.jee.NamedMethod) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

InterceptorBinding (org.apache.openejb.jee.InterceptorBinding)17 Interceptor (org.apache.openejb.jee.Interceptor)15 EjbJar (org.apache.openejb.jee.EjbJar)14 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)12 StatelessBean (org.apache.openejb.jee.StatelessBean)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)5 NamedMethod (org.apache.openejb.jee.NamedMethod)5 ContainerTransaction (org.apache.openejb.jee.ContainerTransaction)4 ArrayList (java.util.ArrayList)3 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)3 Method (org.apache.openejb.jee.Method)3 MethodPermission (org.apache.openejb.jee.MethodPermission)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 EjbModule (org.apache.openejb.config.EjbModule)2