Search in sources :

Example 11 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class OutputGeneratedDescriptors method writeOpenejbJar.

private void writeOpenejbJar(final EjbModule ejbModule) {
    try {
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final File tempFile = tempFile("openejb-jar-", ejbModule.getModuleId() + ".xml");
        final OutputStream out = IO.write(tempFile);
        try {
            JaxbOpenejbJar3.marshal(OpenejbJar.class, openejbJar, out);
            logger.info("Dumping Generated openejb-jar.xml to: " + tempFile.getAbsolutePath());
        } catch (final JAXBException e) {
        // no-op
        } finally {
            IO.close(out);
        }
    } catch (final Exception e) {
    // no-op
    }
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) File(java.io.File) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 12 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar 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 13 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class BusinessInterfacesTest method setUp.

@Override
protected void setUp() throws Exception {
    final Assembler assembler = new Assembler();
    config = new ConfigurationFactory();
    ejbModule = new EjbModule(new EjbJar());
    ejbModule.setOpenejbJar(new OpenejbJar());
    ejbJar = ejbModule.getEjbJar();
    strict(false);
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 14 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideOpenejbJar.

@Test
public void testEjbNameOverrideOpenejbJar() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final OpenejbJar openejbJar = new OpenejbJar();
        final Properties properties = openejbJar.getProperties();
        properties.setProperty("mdb.activation.maxSessions", "20");
        properties.setProperty("mdb.activation.maxMessagesPerSessions", "100");
        properties.setProperty("mdb.activation.destinationType", "javax.jms.Queue");
        properties.setProperty("mdb.activation.destination", "OVERRIDDEN.QUEUE");
        final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("20", orange.activationProperties.get("maxSessions"));
        assertEquals("100", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("20", yellow.activationProperties.get("maxSessions"));
        assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
    }
    // Verify the openejb-jar level overrides do not affect other apps
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("7", orange.activationProperties.get("maxSessions"));
        assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("5", yellow.activationProperties.get("maxSessions"));
        assertEquals("10", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Topic", yellow.activationProperties.get("destinationType"));
        assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination"));
    }
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test) ActivationContainerOverwriteBothConfigurationTest(org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)

Example 15 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class AppInfoBuilderTest method testShouldCreateContainer.

public void testShouldCreateContainer() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    final OpenejbJar openejbJar = new OpenejbJar();
    final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
    final AppModule appModule = new AppModule(ejbModule);
    appModule.getContainers().add(new Container("my-container", "MESSAGE", null));
    final AppInfo appInfo = new AppInfoBuilder(new ConfigurationFactory()).build(appModule);
    assertEquals(1, appInfo.containers.size());
    final ContainerInfo containerInfo = appInfo.containers.get(0);
    assertEquals(appInfo.appId + "/my-container", containerInfo.id);
    assertEquals(1, containerInfo.types.size());
    assertEquals("MESSAGE", containerInfo.types.get(0));
    assertEquals(MdbContainerFactory.class.getName(), containerInfo.className);
    assertEquals("Default JMS Resource Adapter", containerInfo.properties.get("ResourceAdapter"));
    assertEquals(MessageListener.class.getName(), containerInfo.properties.get("MessageListenerInterface"));
    assertEquals(TomEEMessageActivationSpec.class.getName(), containerInfo.properties.get("ActivationSpecClass"));
    assertEquals("10", containerInfo.properties.get("InstanceLimit"));
    assertEquals("true", containerInfo.properties.get("FailOnUnknownActivationSpec"));
}
Also used : TomEEMessageActivationSpec(org.apache.openejb.resource.activemq.TomEEMessageActivationSpec) MdbContainer(org.apache.openejb.core.mdb.MdbContainer) Container(org.apache.openejb.config.sys.Container) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) MdbContainerFactory(org.apache.openejb.core.mdb.MdbContainerFactory) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) MessageListener(javax.jms.MessageListener) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)65 EjbJar (org.apache.openejb.jee.EjbJar)52 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)37 EjbModule (org.apache.openejb.config.EjbModule)30 Properties (java.util.Properties)20 StatelessBean (org.apache.openejb.jee.StatelessBean)19 Assembler (org.apache.openejb.assembler.classic.Assembler)18 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)16 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)12 ContainerSystem (org.apache.openejb.spi.ContainerSystem)12 SingletonBean (org.apache.openejb.jee.SingletonBean)11 Module (org.apache.openejb.testing.Module)11 AppModule (org.apache.openejb.config.AppModule)8 PojoDeployment (org.apache.openejb.jee.oejb3.PojoDeployment)8 InitialContext (javax.naming.InitialContext)7 OpenEJBException (org.apache.openejb.OpenEJBException)7 Resources (org.apache.openejb.config.sys.Resources)7 Service (org.apache.openejb.config.sys.Service)7 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)7 File (java.io.File)6