Search in sources :

Example 26 with EnterpriseBean

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

the class CheckAssemblyBindings method validate.

public void validate(final EjbModule ejbModule) {
    checkUnusedInterceptors(ejbModule);
    final Map<String, EnterpriseBean> ejbsByName = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
    final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
    if (assembly == null) {
        return;
    }
    for (final InterceptorBinding binding : assembly.getInterceptorBinding()) {
        final List<String> interceptorClasses = binding.getInterceptorClass();
        if (binding.getInterceptorOrder() != null) {
            interceptorClasses.addAll(binding.getInterceptorOrder().getInterceptorClass());
        }
        if (binding.getEjbName() != null && !binding.getEjbName().equals("*") && !ejbsByName.containsKey(binding.getEjbName())) {
            fail("InterceptorBinding", "interceptorBinding.noSuchEjbName", binding.getEjbName(), join(",", interceptorClasses));
        }
        if (binding.getMethod() != null) {
            if (binding.getEjbName() == null) {
                fail("InterceptorBinding", "interceptorBinding.ejbNameRequiredWithMethod", binding.getMethod().getMethodName(), join(",", interceptorClasses));
            }
        }
    }
    for (final MethodPermission permission : assembly.getMethodPermission()) {
        for (final Method method : permission.getMethod()) {
            if (method.getEjbName() == null) {
                fail("MethodPermission", "methodPermission.ejbNameRequired", method.getMethodName(), join(",", permission.getRoleName()));
            } else if (method.getEjbName().equals("*")) {
            //NOPMD
            // no-op. Just continue the loop.
            } else if (!ejbsByName.containsKey(method.getEjbName())) {
                fail("MethodPermission", "methodPermission.noSuchEjbName", method.getEjbName(), method.getMethodName(), join(",", permission.getRoleName()));
            }
        }
    }
    for (final ContainerTransaction transaction : assembly.getContainerTransaction()) {
        for (final Method method : transaction.getMethod()) {
            if (method.getEjbName() == null) {
                fail("ContainerTransaction", "containerTransaction.ejbNameRequired", method.getMethodName(), transaction.getTransAttribute());
            } else if (method.getEjbName().equals("*")) {
            //NOPMD
            // no-op. Just continue the loop.
            } else if (!ejbsByName.containsKey(method.getEjbName())) {
                fail("ContainerTransaction", "containerTransaction.noSuchEjbName", method.getEjbName(), method.getMethodName(), transaction.getTransAttribute());
            }
        }
    }
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) Method(org.apache.openejb.jee.Method) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) MethodPermission(org.apache.openejb.jee.MethodPermission)

Example 27 with EnterpriseBean

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

the class TomEEConfigurableJohnzonTest method service.

@Module
public static EjbModule service() throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    final EnterpriseBean bean = new SingletonBean(Endpoint.class).localBean();
    module.getEjbJar().addEnterpriseBean(bean);
    final Resources resources = new Resources();
    final Service sorter = new Service("testSorter", null);
    sorter.setClassName(Sorter.class.getName());
    resources.getService().add(sorter);
    final Service converter = new Service("customerConverter", null);
    converter.setClassName(MyConverter.class.getName());
    resources.getService().add(converter);
    final Service johnzon = new Service("johnzon", null);
    johnzon.setClassName(TomEEConfigurableJohnzon.class.getName());
    johnzon.getProperties().put("datePattern", "yyyy");
    // johnzon.getProperties().put("converter", "$customerConverter"); // or the collection syntax
    johnzon.getProperties().put("converters", "collection:$customerConverter,$customerConverter");
    johnzon.getProperties().put("attributeOrder", "$testSorter");
    resources.getService().add(johnzon);
    module.initResources(resources);
    final PojoDeployment e = new PojoDeployment();
    e.setClassName("jaxrs-application");
    e.getProperties().setProperty("cxf.jaxrs.providers", "johnzon");
    module.getOpenejbJar().getPojoDeployment().add(e);
    return module;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) Resources(org.apache.openejb.config.sys.Resources) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 28 with EnterpriseBean

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

the class LoggingJAXRSCommons method getEjbModule.

protected EjbModule getEjbModule(String pojoDeploymentClassName, String ejbModuleId) throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    if (ejbModuleId != null) {
        module.setModuleId(ejbModuleId);
    }
    final EnterpriseBean bean = new SingletonBean(LogginTestBean.class).localBean();
    module.getEjbJar().addEnterpriseBean(bean);
    final Resources resources = new Resources();
    final Service feature = new Service("xml", null);
    feature.setClassName(JAXBElementProvider.class.getName());
    feature.getProperties().put("eventHandler", "$handler");
    resources.getService().add(feature);
    module.initResources(resources);
    if (pojoDeploymentClassName != null) {
        final PojoDeployment e = new PojoDeployment();
        e.setClassName(pojoDeploymentClassName);
        e.getProperties().setProperty("cxf.jaxrs.providers", "xml");
        module.getOpenejbJar().getPojoDeployment().add(e);
    }
    return module;
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) RESTService(org.apache.openejb.server.rest.RESTService) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) Resources(org.apache.openejb.config.sys.Resources) EjbJar(org.apache.openejb.jee.EjbJar)

Example 29 with EnterpriseBean

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

the class AdvancedProviderConfigTest method service.

@Module
public static EjbModule service() throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    final EnterpriseBean bean = new SingletonBean(AdvancedBean.class).localBean();
    module.getEjbJar().addEnterpriseBean(bean);
    final Resources resources = new Resources();
    final Service feature = new Service("xml", null);
    feature.setClassName(JAXBElementProvider.class.getName());
    feature.getProperties().put("eventHandler", "$handler");
    resources.getService().add(feature);
    final Service handler = new Service("handler", null);
    handler.setClassName(MyValidator.class.getName());
    resources.getService().add(handler);
    module.initResources(resources);
    final PojoDeployment e = new PojoDeployment();
    e.setClassName("jaxrs-application");
    e.getProperties().setProperty("cxf.jaxrs.providers", "xml");
    module.getOpenejbJar().getPojoDeployment().add(e);
    return module;
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) Resources(org.apache.openejb.config.sys.Resources) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 30 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project aries by apache.

the class OpenEJBLocator method findEJBs.

public void findEJBs(BundleManifest manifest, IDirectory bundle, EJBRegistry registry) throws ModellerException {
    logger.debug("Scanning " + manifest.getSymbolicName() + "_" + manifest.getManifestVersion() + " for EJBs");
    String ejbJarLocation = (manifest.getRawAttributes().getValue("Web-ContextPath") == null) ? "META-INF/ejb-jar.xml" : "WEB-INF/ejb-jar.xml";
    try {
        //If we have an ejb-jar.xml then parse it 
        IFile file = bundle.getFile(ejbJarLocation);
        EjbJar ejbJar = (file == null) ? new EjbJar() : ReadDescriptors.readEjbJar(file.toURL());
        EjbModule module = new EjbModule(ejbJar);
        //We build our own because we can't trust anyone to get the classpath right otherwise!
        module.setFinder(new IDirectoryFinder(AnnotationDeployer.class.getClassLoader(), getClassPathLocations(manifest, bundle)));
        //Scan our app for annotated EJBs
        AppModule app = new AppModule(module);
        new AnnotationDeployer().deploy(app);
        //Register our session beans
        for (EnterpriseBean eb : ejbJar.getEnterpriseBeans()) {
            if (!!!(eb instanceof SessionBean))
                continue;
            else
                registerSessionBean(registry, (SessionBean) eb);
        }
    } catch (Exception e) {
        throw new ModellerException(e);
    }
}
Also used : AnnotationDeployer(org.apache.openejb.config.AnnotationDeployer) IFile(org.apache.aries.util.filesystem.IFile) AppModule(org.apache.openejb.config.AppModule) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) ModellerException(org.apache.aries.application.modelling.ModellerException) SessionBean(org.apache.openejb.jee.SessionBean) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ModellerException(org.apache.aries.application.modelling.ModellerException) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)46 EjbJar (org.apache.openejb.jee.EjbJar)19 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)16 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)14 SessionBean (org.apache.openejb.jee.SessionBean)12 ArrayList (java.util.ArrayList)9 EjbModule (org.apache.openejb.config.EjbModule)9 HashMap (java.util.HashMap)8 OpenEJBException (org.apache.openejb.OpenEJBException)7 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)7 Map (java.util.Map)6 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)6 Interceptor (org.apache.openejb.jee.Interceptor)6 List (java.util.List)5 Properties (java.util.Properties)5 EntityBean (org.apache.openejb.jee.EntityBean)5 InterceptorBinding (org.apache.openejb.jee.InterceptorBinding)5 ResourceLink (org.apache.openejb.jee.oejb3.ResourceLink)5 Resources (org.apache.openejb.config.sys.Resources)4 JndiConsumer (org.apache.openejb.jee.JndiConsumer)4