Search in sources :

Example 1 with Interceptor

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

the class EjbJarInfoBuilder method initInterceptors.

private void initInterceptors(final EjbModule jar, final EjbJarInfo ejbJar) throws OpenEJBException {
    if (jar.getEjbJar().getInterceptors().length == 0) {
        return;
    }
    if (jar.getEjbJar().getAssemblyDescriptor() == null) {
        return;
    }
    if (jar.getEjbJar().getAssemblyDescriptor().getInterceptorBinding() == null) {
        return;
    }
    for (final Interceptor s : jar.getEjbJar().getInterceptors()) {
        final InterceptorInfo info = new InterceptorInfo();
        info.clazz = s.getInterceptorClass();
        copyCallbacks(s.getAroundInvoke(), info.aroundInvoke);
        copyCallbacks(s.getPostConstruct(), info.postConstruct);
        copyCallbacks(s.getPreDestroy(), info.preDestroy);
        copyCallbacks(s.getPostActivate(), info.postActivate);
        copyCallbacks(s.getPrePassivate(), info.prePassivate);
        copyCallbacks(s.getAfterBegin(), info.afterBegin);
        copyCallbacks(s.getBeforeCompletion(), info.beforeCompletion);
        copyCallbacks(s.getAfterCompletion(), info.afterCompletion);
        copyCallbacks(s.getAroundTimeout(), info.aroundTimeout);
        ejbJar.interceptors.add(info);
    }
    for (final InterceptorBinding binding : jar.getEjbJar().getAssemblyDescriptor().getInterceptorBinding()) {
        final InterceptorBindingInfo info = new InterceptorBindingInfo();
        info.ejbName = binding.getEjbName();
        info.excludeClassInterceptors = binding.getExcludeClassInterceptors();
        info.excludeDefaultInterceptors = binding.getExcludeDefaultInterceptors();
        info.interceptors.addAll(binding.getInterceptorClass());
        if (binding.getInterceptorOrder() != null) {
            info.interceptorOrder.addAll(binding.getInterceptorOrder().getInterceptorClass());
        }
        info.method = toInfo(binding.getMethod());
        info.className = binding.getClassName();
        ejbJar.interceptorBindings.add(info);
    }
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) InterceptorBindingInfo(org.apache.openejb.assembler.classic.InterceptorBindingInfo) InterceptorInfo(org.apache.openejb.assembler.classic.InterceptorInfo) Interceptor(org.apache.openejb.jee.Interceptor)

Example 2 with Interceptor

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

the class DebuggableVmHackery method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
        ejbJar.setRelationships(null);
        final List<String> removed = new ArrayList<>();
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            final String ejbName = bean.getEjbName();
            final EjbDeployment ejbDeployment = deployments.get(ejbName);
            pruneRefs(bean, ejbDeployment);
            // }
            if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
                continue;
            }
            ejbJar.removeEnterpriseBean(ejbName);
            openejbJar.removeEjbDeployment(ejbDeployment);
            removed.add(ejbName);
            final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
            if (assemblyDescriptor != null) {
                for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
                    for (final Method method : copy(permission.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            permission.getMethod().remove(method);
                        }
                    }
                    if (permission.getMethod().size() == 0) {
                        assemblyDescriptor.getMethodPermission().remove(permission);
                    }
                }
                for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
                    for (final Method method : copy(transaction.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            transaction.getMethod().remove(method);
                        }
                    }
                    if (transaction.getMethod().size() == 0) {
                        assemblyDescriptor.getContainerTransaction().remove(transaction);
                    }
                }
                for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
                    if (binding.getEjbName().equals(ejbName)) {
                        assemblyDescriptor.getInterceptorBinding().remove(binding);
                    }
                }
            }
        }
        // Drop any ejb ref to with an ejb-link to a removed ejb
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            bean.getEjbLocalRefMap().keySet().removeAll(removed);
            bean.getEjbRefMap().keySet().removeAll(removed);
        }
        for (final Interceptor interceptor : ejbJar.getInterceptors()) {
            pruneRefs(interceptor, new EjbDeployment());
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ArrayList(java.util.ArrayList) Method(org.apache.openejb.jee.Method) MethodPermission(org.apache.openejb.jee.MethodPermission) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EntityBean(org.apache.openejb.jee.EntityBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 3 with Interceptor

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

the class RemoveWebServices method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            final String ejbName = bean.getEjbName();
            final EjbDeployment ejbDeployment = deployments.get(ejbName);
            // Clear any <service-ref> references from ejbs
            bean.getServiceRef().clear();
            if (!(bean instanceof SessionBean)) {
                continue;
            }
            final SessionBean sessionBean = (SessionBean) bean;
            if (sessionBean.getServiceEndpoint() == null) {
                continue;
            }
            sessionBean.setServiceEndpoint(null);
            // if not, then we should just delete it
            if (sessionBean.getHome() != null) {
                continue;
            }
            if (sessionBean.getLocalHome() != null) {
                continue;
            }
            if (sessionBean.getBusinessLocal().size() > 0) {
                continue;
            }
            if (sessionBean.getBusinessRemote().size() > 0) {
                continue;
            }
            // Ok, delete away...
            ejbJar.removeEnterpriseBean(ejbName);
            openejbJar.removeEjbDeployment(ejbDeployment);
            // As well, let's get rid of any transaction or security attributes
            // associated with the bean we just deleted.
            final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
            if (assemblyDescriptor != null) {
                for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
                    for (final Method method : copy(permission.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            permission.getMethod().remove(method);
                        }
                    }
                    if (permission.getMethod().size() == 0) {
                        assemblyDescriptor.getMethodPermission().remove(permission);
                    }
                }
                for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
                    for (final Method method : copy(transaction.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            transaction.getMethod().remove(method);
                        }
                    }
                    if (transaction.getMethod().size() == 0) {
                        assemblyDescriptor.getContainerTransaction().remove(transaction);
                    }
                }
                for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
                    if (binding.getEjbName().equals(ejbName)) {
                        assemblyDescriptor.getInterceptorBinding().remove(binding);
                    }
                }
            }
        }
        // Clear any <service-ref> references from interceptors
        for (final Interceptor interceptor : ejbJar.getInterceptors()) {
            interceptor.getServiceRef().clear();
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Method(org.apache.openejb.jee.Method) SessionBean(org.apache.openejb.jee.SessionBean) MethodPermission(org.apache.openejb.jee.MethodPermission) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 4 with Interceptor

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

the class CheckClasses method validate.

public void validate(final EjbModule ejbModule) {
    final ClassLoader loader = ejbModule.getClassLoader();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        try {
            final Class<?> beanClass = check_hasEjbClass(loader, bean);
            // All the subsequent checks require the bean class
            if (beanClass == null) {
                continue;
            }
            if (!(bean instanceof RemoteBean)) {
                continue;
            }
            if (bean instanceof SessionBean && ((SessionBean) bean).getProxy() != null) {
                continue;
            }
            final RemoteBean b = (RemoteBean) bean;
            check_isEjbClass(b);
            check_hasDependentClasses(b, b.getEjbClass(), "ejb-class");
            check_hasInterface(b);
            if (b.getRemote() != null) {
                checkInterface(loader, b, beanClass, "remote", b.getRemote());
            }
            if (b.getHome() != null) {
                checkInterface(loader, b, beanClass, "home", b.getHome());
            }
            if (b.getLocal() != null) {
                checkInterface(loader, b, beanClass, "local", b.getLocal());
            }
            if (b.getLocalHome() != null) {
                checkInterface(loader, b, beanClass, "local-home", b.getLocalHome());
            }
            if (b instanceof SessionBean) {
                final SessionBean sessionBean = (SessionBean) b;
                for (final String interfce : sessionBean.getBusinessLocal()) {
                    checkInterface(loader, b, beanClass, "business-local", interfce);
                }
                for (final String interfce : sessionBean.getBusinessRemote()) {
                    checkInterface(loader, b, beanClass, "business-remote", interfce);
                }
            }
        } catch (final RuntimeException e) {
            throw new OpenEJBRuntimeException(bean.getEjbName(), e);
        }
    }
    for (final Interceptor interceptor : ejbModule.getEjbJar().getInterceptors()) {
        check_hasInterceptorClass(loader, interceptor);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) RemoteBean(org.apache.openejb.jee.RemoteBean) SessionBean(org.apache.openejb.jee.SessionBean) Interceptor(org.apache.openejb.jee.Interceptor)

Example 5 with Interceptor

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

the class CheckInvalidInterceptorTest method test1.

@Keys({ @Key(value = "interceptor.unused", count = 2, type = KeyType.WARNING), @Key("aroundInvoke.invalidArguments") })
public EjbJar test1() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(BarBean.class));
    final Interceptor unused = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(UnusedInterceptor.class));
    final Interceptor unused1 = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(UnusedInterceptor1.class));
    final Interceptor used = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(UsedInterceptor.class));
    final List<InterceptorBinding> interceptorBindings = ejbJar.getAssemblyDescriptor().getInterceptorBinding();
    final InterceptorBinding binding = new InterceptorBinding("BarBean", used);
    interceptorBindings.add(binding);
    return ejbJar;
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) Interceptor(org.apache.openejb.jee.Interceptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

Interceptor (org.apache.openejb.jee.Interceptor)21 EjbJar (org.apache.openejb.jee.EjbJar)17 InterceptorBinding (org.apache.openejb.jee.InterceptorBinding)16 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)12 StatelessBean (org.apache.openejb.jee.StatelessBean)10 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)6 NamedMethod (org.apache.openejb.jee.NamedMethod)5 Module (org.apache.openejb.testing.Module)5 ArrayList (java.util.ArrayList)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