Search in sources :

Example 16 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 17 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 18 with InterceptorBinding

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

the class CheckAssemblyBindings method checkUnusedInterceptors.

private void checkUnusedInterceptors(final EjbModule ejbModule) {
    final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
    final Interceptor[] interceptorsArray = ejbModule.getEjbJar().getInterceptors();
    final List<Interceptor> interceptors = Arrays.asList(interceptorsArray);
    final Set<String> interceptorClassNames = new HashSet<String>(interceptors.size());
    for (final Interceptor interceptor : interceptors) {
        interceptorClassNames.add(interceptor.getInterceptorClass());
    }
    final Set<String> interceptorClassNamesUsedInBindings = new HashSet<String>();
    for (final InterceptorBinding binding : assembly.getInterceptorBinding()) {
        final List<String> interceptorClass = binding.getInterceptorClass();
        interceptorClassNamesUsedInBindings.addAll(interceptorClass);
    }
    final Set<String> unusedInterceptors = new HashSet<String>();
    for (final String clazz : interceptorClassNames) {
        if (!interceptorClassNamesUsedInBindings.contains(clazz)) {
            unusedInterceptors.add(clazz);
        }
    }
    for (final String clazz : unusedInterceptors) {
        warn("Interceptors", "interceptor.unused", clazz);
    }
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) HashSet(java.util.HashSet)

Example 19 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)

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