Search in sources :

Example 6 with EjbJarInfo

use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.

the class JaxRpcInvocationTest method testWebServiceInvocations.

public void testWebServiceInvocations() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class, "PseudoSecurityService", null, "PseudoSecurityService", null));
    assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
    final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
    assembler.createApplication(ejbJar);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("EchoBean");
    assertNotNull(beanContext);
    assertEquals("ServiceEndpointInterface", EchoServiceEndpoint.class, beanContext.getServiceEndpointInterface());
    // OK, Now let's fake a web serivce invocation coming from any random
    // web service provider.  The web serivce provider needs supply
    // the MessageContext and an interceptor to do the marshalling as
    // the arguments of the standard container.invoke signature.
    // So let's create a fake message context.
    final MessageContext messageContext = new FakeMessageContext();
    // Now let's create a fake interceptor as would be supplied by the
    // web service provider.  Instead of writing "fake" marshalling
    // code that would pull the arguments from the soap message, we'll
    // just give it the argument values directly.
    final Object wsProviderInterceptor = new FakeWsProviderInterceptor("Hello world");
    // Ok, now we have the two arguments expected on a JAX-RPC Web Service
    // invocation as per the OpenEJB-specific agreement between OpenEJB
    // and the Web Service Provider
    final Object[] args = new Object[] { messageContext, wsProviderInterceptor };
    // Let's grab the container as the Web Service Provider would do and
    // perform an invocation
    final RpcContainer container = (RpcContainer) beanContext.getContainer();
    final Method echoMethod = EchoServiceEndpoint.class.getMethod("echo", String.class);
    final String value = (String) container.invoke("EchoBean", InterfaceType.SERVICE_ENDPOINT, echoMethod.getDeclaringClass(), echoMethod, args, null);
    assertCalls(Call.values());
    calls.clear();
    assertEquals("Hello world", value);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Method(java.lang.reflect.Method) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) BeanContext(org.apache.openejb.BeanContext) RpcContainer(org.apache.openejb.RpcContainer) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) MessageContext(javax.xml.rpc.handler.MessageContext) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 7 with EjbJarInfo

use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.

the class JaxWsInvocationTest method testWsInvocations.

public void testWsInvocations() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class, "PseudoSecurityService", null, "PseudoSecurityService", null));
    assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
    final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
    assembler.createApplication(ejbJar);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("EchoBean");
    assertNotNull(beanContext);
    assertEquals("ServiceEndpointInterface", EchoServiceEndpoint.class, beanContext.getServiceEndpointInterface());
    // OK, Now let's fake a web serivce invocation coming from any random
    // web service provider.  The web serivce provider needs supply
    // the MessageContext and an interceptor to do the marshalling as
    // the arguments of the standard container.invoke signature.
    // So let's create a fake message context.
    final MessageContext messageContext = new FakeMessageContext();
    // Now let's create a fake interceptor as would be supplied by the
    // web service provider.  Instead of writing "fake" marshalling
    // code that would pull the arguments from the soap message, we'll
    // just give it the argument values directly.
    final Object wsProviderInterceptor = new FakeWsProviderInterceptor("Hello world");
    // Ok, now we have the two arguments expected on a JAX-RPC Web Service
    // invocation as per the OpenEJB-specific agreement between OpenEJB
    // and the Web Service Provider
    final Object[] args = new Object[] { messageContext, wsProviderInterceptor };
    // Let's grab the container as the Web Service Provider would do and
    // perform an invocation
    final RpcContainer container = (RpcContainer) beanContext.getContainer();
    final Method echoMethod = EchoServiceEndpoint.class.getMethod("echo", String.class);
    final String value = (String) container.invoke("EchoBean", InterfaceType.SERVICE_ENDPOINT, echoMethod.getDeclaringClass(), echoMethod, args, null);
    assertCalls(Call.values());
    calls.clear();
    assertEquals("Hello world", value);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Method(java.lang.reflect.Method) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) BeanContext(org.apache.openejb.BeanContext) RpcContainer(org.apache.openejb.RpcContainer) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) MessageContext(javax.xml.ws.handler.MessageContext) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 8 with EjbJarInfo

use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.

the class StatefulTransactionAttributesTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    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 StatefulBean(Color.class));
    ejbJar.addEnterpriseBean(new StatefulBean(Red.class));
    ejbJar.addEnterpriseBean(new StatefulBean(Crimson.class));
    ejbJar.addEnterpriseBean(new StatefulBean(Scarlet.class));
    final List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
    declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "*", "Crimson", "*"));
    declared.add(new ContainerTransaction(TransAttribute.REQUIRES_NEW, "*", "Crimson", "create"));
    final ContainerTransaction o = new ContainerTransaction(TransAttribute.SUPPORTS, "*", "Crimson", "create");
    o.getMethod().get(0).setMethodIntf(MethodIntf.HOME);
    declared.add(o);
    declared.add(new ContainerTransaction(TransAttribute.REQUIRES_NEW, "*", "Crimson", "remove"));
    declared.add(new ContainerTransaction(TransAttribute.REQUIRES_NEW, 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")));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    final InitialContext context = new InitialContext();
    {
        final ColorLocal color = (ColorLocal) context.lookup("ColorLocal");
        assertEquals("Never", color.color());
        assertEquals("RequiresNew", color.color((Object) null));
        assertEquals("Supports", color.color((String) null));
        assertEquals("Supports", color.color((Boolean) null));
        assertEquals("Supports", color.color((Integer) null));
    }
    {
        final ColorRemote color = (ColorRemote) context.lookup("ColorRemote");
        assertEquals("Never", color.color());
        assertEquals("RequiresNew", color.color((Object) null));
        assertEquals("Supports", color.color((String) null));
        assertEquals("Supports", color.color((Boolean) null));
        assertEquals("Supports", color.color((Integer) null));
    }
    {
        final ColorEjbLocalHome home = (ColorEjbLocalHome) context.lookup("ColorLocalHome");
        final ColorEjbLocalObject color = home.create("Supports");
        assertEquals("Never", color.color());
        assertEquals("RequiresNew", color.color((Object) null));
        assertEquals("Supports", color.color((String) null));
        assertEquals("Supports", color.color((Boolean) null));
        assertEquals("Supports", color.color((Integer) null));
        expected.set("Supports");
        color.remove();
    }
    {
        final ColorEjbHome home = (ColorEjbHome) context.lookup("ColorRemoteHome");
        final ColorEjbObject color = home.create("Supports");
        assertEquals("Never", color.color());
        assertEquals("RequiresNew", color.color((Object) null));
        assertEquals("Supports", color.color((String) null));
        assertEquals("Supports", color.color((Boolean) null));
        assertEquals("Supports", color.color((Integer) null));
        expected.set("Supports");
        color.remove();
    }
    {
        final RedLocal red = (RedLocal) context.lookup("RedLocal");
        assertEquals("Never", red.color());
        assertEquals("Required", red.color((Object) null));
        assertEquals("Supports", red.color((String) null));
        assertEquals("Supports", red.color((Boolean) null));
        assertEquals("Supports", red.color((Integer) null));
        assertEquals("RequiresNew", red.red());
        assertEquals("Required", red.red((Object) null));
        assertEquals("Required", red.red((String) null));
    }
    {
        final RedRemote red = (RedRemote) context.lookup("RedRemote");
        assertEquals("Never", red.color());
        assertEquals("Required", red.color((Object) null));
        assertEquals("Supports", red.color((String) null));
        assertEquals("Supports", red.color((Boolean) null));
        assertEquals("Supports", red.color((Integer) null));
        assertEquals("RequiresNew", red.red());
        assertEquals("Required", red.red((Object) null));
        assertEquals("Required", red.red((String) null));
    }
    {
        final RedEjbLocalHome home = (RedEjbLocalHome) context.lookup("RedLocalHome");
        final RedEjbLocalObject red = home.create("Supports");
        assertEquals("Never", red.color());
        assertEquals("Required", red.color((Object) null));
        assertEquals("Supports", red.color((String) null));
        assertEquals("Supports", red.color((Boolean) null));
        assertEquals("Supports", red.color((Integer) null));
        assertEquals("RequiresNew", red.red());
        assertEquals("Required", red.red((Object) null));
        assertEquals("Required", red.red((String) null));
        expected.set("Supports");
        red.remove();
    }
    {
        final RedEjbHome home = (RedEjbHome) context.lookup("RedRemoteHome");
        final RedEjbObject red = home.create("Supports");
        assertEquals("Never", red.color());
        assertEquals("Required", red.color((Object) null));
        assertEquals("Supports", red.color((String) null));
        assertEquals("Supports", red.color((Boolean) null));
        assertEquals("Supports", red.color((Integer) null));
        assertEquals("RequiresNew", red.red());
        assertEquals("Required", red.red((Object) null));
        assertEquals("Required", red.red((String) null));
        expected.set("Supports");
        red.remove();
    }
    {
        final CrimsonLocal crimson = (CrimsonLocal) context.lookup("CrimsonLocal");
        assertEquals("Required", crimson.color());
        assertEquals("Required", crimson.color((Object) null));
        assertEquals("Required", crimson.color((String) null));
        assertEquals("Required", crimson.color((Boolean) null));
        assertEquals("Required", crimson.color((Integer) null));
        assertEquals("RequiresNew", crimson.red());
        assertEquals("Required", crimson.red((Object) null));
        assertEquals("Required", crimson.red((String) null));
        assertEquals("RequiresNew", crimson.crimson());
        assertEquals("Required", crimson.crimson((String) null));
    }
    {
        final CrimsonRemote crimson = (CrimsonRemote) context.lookup("CrimsonRemote");
        assertEquals("Required", crimson.color());
        assertEquals("Required", crimson.color((Object) null));
        assertEquals("Required", crimson.color((String) null));
        assertEquals("Required", crimson.color((Boolean) null));
        assertEquals("Required", crimson.color((Integer) null));
        assertEquals("RequiresNew", crimson.red());
        assertEquals("Required", crimson.red((Object) null));
        assertEquals("Required", crimson.red((String) null));
        assertEquals("RequiresNew", crimson.crimson());
        assertEquals("Required", crimson.crimson((String) null));
    }
    {
        final CrimsonEjbLocalHome home = (CrimsonEjbLocalHome) context.lookup("CrimsonLocalHome");
        final CrimsonEjbLocalObject crimson = home.create("RequiresNew");
        assertEquals("Required", crimson.color());
        assertEquals("Required", crimson.color((Object) null));
        assertEquals("Required", crimson.color((String) null));
        assertEquals("Required", crimson.color((Boolean) null));
        assertEquals("Required", crimson.color((Integer) null));
        assertEquals("RequiresNew", crimson.red());
        assertEquals("Required", crimson.red((Object) null));
        assertEquals("Required", crimson.red((String) null));
        assertEquals("RequiresNew", crimson.crimson());
        assertEquals("Required", crimson.crimson((String) null));
        expected.set("RequiresNew");
        crimson.remove();
    }
    {
        final CrimsonEjbHome home = (CrimsonEjbHome) context.lookup("CrimsonRemoteHome");
        final CrimsonEjbObject crimson = home.create("Supports");
        assertEquals("Required", crimson.color());
        assertEquals("Required", crimson.color((Object) null));
        assertEquals("Required", crimson.color((String) null));
        assertEquals("Required", crimson.color((Boolean) null));
        assertEquals("Required", crimson.color((Integer) null));
        assertEquals("RequiresNew", crimson.red());
        assertEquals("Required", crimson.red((Object) null));
        assertEquals("Required", crimson.red((String) null));
        assertEquals("RequiresNew", crimson.crimson());
        assertEquals("Required", crimson.crimson((String) null));
        expected.set("RequiresNew");
        crimson.remove();
    }
    {
        final ScarletLocal scarlet = (ScarletLocal) context.lookup("ScarletLocal");
        assertEquals("Never", scarlet.color());
        assertEquals("Required", scarlet.color((Object) null));
        assertEquals("RequiresNew", scarlet.color((String) null));
        assertEquals("RequiresNew", scarlet.color((Boolean) null));
        assertEquals("RequiresNew", scarlet.color((Integer) null));
        assertEquals("RequiresNew", scarlet.red());
        assertEquals("Never", scarlet.red((Object) null));
        assertEquals("Never", scarlet.red((String) null));
        assertEquals("Required", scarlet.scarlet());
        assertEquals("NotSupported", scarlet.scarlet((String) null));
    }
    {
        final ScarletRemote scarlet = (ScarletRemote) context.lookup("ScarletRemote");
        assertEquals("Never", scarlet.color());
        assertEquals("Required", scarlet.color((Object) null));
        assertEquals("RequiresNew", scarlet.color((String) null));
        assertEquals("RequiresNew", scarlet.color((Boolean) null));
        assertEquals("RequiresNew", scarlet.color((Integer) null));
        assertEquals("RequiresNew", scarlet.red());
        assertEquals("Never", scarlet.red((Object) null));
        assertEquals("Never", scarlet.red((String) null));
        assertEquals("Required", scarlet.scarlet());
        assertEquals("NotSupported", scarlet.scarlet((String) null));
    }
    {
        final ScarletEjbLocalHome home = (ScarletEjbLocalHome) context.lookup("ScarletLocalHome");
        final ScarletEjbLocalObject scarlet = home.create("RequiresNew");
        assertEquals("Never", scarlet.color());
        assertEquals("Required", scarlet.color((Object) null));
        assertEquals("RequiresNew", scarlet.color((String) null));
        assertEquals("RequiresNew", scarlet.color((Boolean) null));
        assertEquals("RequiresNew", scarlet.color((Integer) null));
        assertEquals("RequiresNew", scarlet.red());
        assertEquals("Never", scarlet.red((Object) null));
        assertEquals("Never", scarlet.red((String) null));
        assertEquals("Required", scarlet.scarlet());
        assertEquals("NotSupported", scarlet.scarlet((String) null));
    }
    {
        final ScarletEjbHome home = (ScarletEjbHome) context.lookup("ScarletRemoteHome");
        final ScarletEjbObject scarlet = home.create("RequiresNew");
        assertEquals("Never", scarlet.color());
        assertEquals("Required", scarlet.color((Object) null));
        assertEquals("RequiresNew", scarlet.color((String) null));
        assertEquals("RequiresNew", scarlet.color((Boolean) null));
        assertEquals("RequiresNew", scarlet.color((Integer) null));
        assertEquals("RequiresNew", scarlet.red());
        assertEquals("Never", scarlet.red((Object) null));
        assertEquals("Never", scarlet.red((String) null));
        assertEquals("Required", scarlet.scarlet());
        assertEquals("NotSupported", scarlet.scarlet((String) null));
    }
}
Also used : LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) StatefulBean(org.apache.openejb.jee.StatefulBean) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 9 with EjbJarInfo

use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.

the class ScheduleTest method testSchedule.

public void testSchedule() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    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();
    //Configure schedule by deployment plan
    final StatelessBean subBeanA = new StatelessBean(SubBeanA.class);
    final Timer subBeanATimer = new Timer();
    subBeanATimer.setTimeoutMethod(new NamedMethod("subBeanA", "javax.ejb.Timer"));
    final TimerSchedule timerScheduleA = new TimerSchedule();
    timerScheduleA.setSecond("2");
    timerScheduleA.setMinute("*");
    timerScheduleA.setHour("*");
    subBeanATimer.setSchedule(timerScheduleA);
    subBeanATimer.setInfo("SubBeanAInfo");
    subBeanA.getTimer().add(subBeanATimer);
    ejbJar.addEnterpriseBean(subBeanA);
    //Configure schedule by annotation
    final StatelessBean subBeanB = new StatelessBean(SubBeanB.class);
    ejbJar.addEnterpriseBean(subBeanB);
    //Override aroundTimeout annotation by deployment plan
    final StatelessBean subBeanC = new StatelessBean(SubBeanC.class);
    final Timer subBeanCTimer = new Timer();
    subBeanCTimer.setTimeoutMethod(new NamedMethod("subBeanC", "javax.ejb.Timer"));
    final TimerSchedule timerScheduleC = new TimerSchedule();
    timerScheduleC.setSecond("2");
    timerScheduleC.setMinute("*");
    timerScheduleC.setHour("*");
    subBeanCTimer.setSchedule(timerScheduleC);
    subBeanCTimer.setInfo("SubBeanCInfo");
    subBeanC.getTimer().add(subBeanCTimer);
    ejbJar.addEnterpriseBean(subBeanC);
    final StatefulBean subBeanM = new StatefulBean(SubBeanM.class);
    ejbJar.addEnterpriseBean(subBeanM);
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    countDownLatch.await(1L, TimeUnit.MINUTES);
    //A better way for validation ?
    int beforeAroundInvocationCount = 0;
    int afterAroundInvocationCount = 0;
    int timeoutInvocationCount = 0;
    final int size;
    synchronized (result) {
        size = result.size();
        for (final Call call : result) {
            switch(call) {
                case BEAN_BEFORE_AROUNDTIMEOUT:
                    beforeAroundInvocationCount++;
                    break;
                case BEAN_AFTER_AROUNDTIMEOUT:
                    afterAroundInvocationCount++;
                    break;
                case TIMEOUT:
                    timeoutInvocationCount++;
                    break;
            }
        }
    }
    assertEquals(3, beforeAroundInvocationCount);
    assertEquals(3, afterAroundInvocationCount);
    assertEquals(3, timeoutInvocationCount);
    assertEquals(9, size);
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) NamedMethod(org.apache.openejb.jee.NamedMethod) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TimerSchedule(org.apache.openejb.jee.TimerSchedule) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Timer(org.apache.openejb.jee.Timer) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 10 with EjbJarInfo

use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.

the class AppInfoBuilder method build.

public AppInfo build(final AppModule appModule) throws OpenEJBException {
    // send an event so that it becomes pretty easy at this step to dynamically change the module description
    // before going into the info tree. Pretty easy to hack on portability issues.
    SystemInstance.get().fireEvent(new BeforeAppInfoBuilderEvent(appModule));
    final AppInfo appInfo = new AppInfo();
    appInfo.appId = appModule.getModuleId();
    appInfo.path = appModule.getJarLocation();
    appInfo.standaloneModule = appModule.isStandaloneModule() || appModule.isWebapp();
    appInfo.delegateFirst = appModule.isDelegateFirst();
    appInfo.watchedResources.addAll(appModule.getWatchedResources());
    appInfo.mbeans.addAll(appModule.getAdditionalLibMbeans());
    appInfo.jaxRsProviders.addAll(appModule.getJaxRsProviders());
    appInfo.properties.putAll(appModule.getProperties());
    if (appInfo.appId == null) {
        throw new IllegalArgumentException("AppInfo.appId cannot be null");
    }
    if (appInfo.path == null) {
        appInfo.path = appInfo.appId;
    }
    this.buildPojoConfiguration(appModule, appInfo);
    this.buildAppResources(appModule, appInfo);
    this.buildAppServices(appModule, appInfo);
    //
    //  J2EE Connectors
    //
    this.buildConnectorModules(appModule, appInfo);
    //
    //  Persistence Units
    //
    this.buildPersistenceModules(appModule, appInfo);
    final List<String> containerIds = this.configFactory.getContainerIds();
    for (final ConnectorInfo connectorInfo : appInfo.connectors) {
        for (final MdbContainerInfo containerInfo : connectorInfo.inbound) {
            containerIds.add(containerInfo.id);
        }
    }
    containerIds.addAll(appInfo.containerIds);
    //
    //  EJB Jars
    //
    final Map<EjbModule, EjbJarInfo> ejbJarInfos = new HashMap<EjbModule, EjbJarInfo>();
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        try {
            final EjbJarInfo ejbJarInfo = this.ejbJarInfoBuilder.buildInfo(ejbModule);
            ejbJarInfo.mbeans = ejbModule.getMbeans();
            final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
            for (final EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
                final EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
                if (d.getContainerId() != null && !containerIds.contains(d.getContainerId())) {
                    for (final String cId : appInfo.containerIds) {
                        if (cId.endsWith("/" + d.getContainerId())) {
                            d.setContainerId(cId);
                            break;
                        }
                    }
                }
                /*
                     * JRG - there's probably a better way of handling this, but this code handles the case when:
                     * 
                     * A connector with two or more inbound adapter is registered, causing two containers named with the format:
                     *     <moduleId>-<message listener interface>
                     * 
                     * This code adjusts the container id for the associated MDBs by sticking the message listener interface on the end.
                     * 
                     */
                if (bean instanceof MessageDrivenBeanInfo && !containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
                    final MessageDrivenBeanInfo mdb = (MessageDrivenBeanInfo) bean;
                    final String newContainerId = d.getContainerId() + "-" + mdb.mdbInterface;
                    if (containerIds.contains(newContainerId)) {
                        d.setContainerId(newContainerId);
                    }
                }
                if (!containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
                    final String msg = new Messages("org.apache.openejb.util.resources").format("config.noContainerFound", d.getContainerId(), d.getEjbName());
                    logger.fatal(msg);
                    throw new OpenEJBException(msg);
                }
                bean.containerId = d.getContainerId();
            }
            for (final PojoDeployment pojoDeployment : ejbModule.getOpenejbJar().getPojoDeployment()) {
                final IdPropertiesInfo info = new IdPropertiesInfo();
                info.id = pojoDeployment.getClassName();
                info.properties.putAll(pojoDeployment.getProperties());
                ejbJarInfo.pojoConfigurations.add(info);
            }
            ejbJarInfo.validationInfo = ValidatorBuilder.getInfo(ejbModule.getValidationConfig());
            ejbJarInfo.portInfos.addAll(this.configureWebservices(ejbModule.getWebservices()));
            ejbJarInfo.uniqueId = ejbModule.getUniqueId();
            ejbJarInfo.webapp = ejbModule.isWebapp();
            this.configureWebserviceSecurity(ejbJarInfo, ejbModule);
            ejbJarInfos.put(ejbModule, ejbJarInfo);
            appInfo.ejbJars.add(ejbJarInfo);
        } catch (final OpenEJBException e) {
            ConfigUtils.logger.warning("conf.0004", ejbModule.getJarLocation(), e.getMessage());
            throw e;
        }
    }
    // Create the JNDI info builder
    final JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo);
    if (appModule.getApplication() != null) {
        //TODO figure out how to prevent adding stuff to the module and comp contexts from the application
        //or maybe validate the xml so this won't happen.
        jndiEncInfoBuilder.build(appModule.getApplication(), appInfo.appId, null, appModule.getModuleUri(), new JndiEncInfo(), new JndiEncInfo());
    }
    final List<EnterpriseBeanInfo> beans = new ArrayList<EnterpriseBeanInfo>();
    // Build the JNDI tree for each ejb
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJarInfo ejbJar = ejbJarInfos.get(ejbModule);
        final Map<String, EnterpriseBean> beanData = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
        for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
            beans.add(beanInfo);
            // Get the ejb-jar.xml object
            final EnterpriseBean enterpriseBean = beanData.get(beanInfo.ejbName);
            // Build the JNDI info tree for the EJB
            jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, ejbJar.moduleName, ejbModule.getModuleUri(), ejbJar.moduleJndiEnc, beanInfo.jndiEnc);
            jndiEncInfoBuilder.buildDependsOnRefs(enterpriseBean, beanInfo, ejbJar.moduleName);
        }
    }
    // Check for circular references in Singleton @DependsOn
    try {
        References.sort(beans, new References.Visitor<EnterpriseBeanInfo>() {

            @Override
            public String getName(final EnterpriseBeanInfo bean) {
                return bean.ejbDeploymentId;
            }

            @Override
            public Set<String> getReferences(final EnterpriseBeanInfo bean) {
                return new LinkedHashSet<String>(bean.dependsOn);
            }
        });
    } catch (final CircularReferencesException e) {
    // List<List> circuits = e.getCircuits();
    // TODO Seems we lost circular reference detection, or we do it elsewhere and don't need it here
    }
    //
    //  Application Clients
    //
    this.buildClientModules(appModule, appInfo, jndiEncInfoBuilder);
    //
    //  Webapps
    //
    this.buildWebModules(appModule, jndiEncInfoBuilder, appInfo);
    //
    //  Final AppInfo creation
    //
    final List<URL> additionalLibraries = appModule.getAdditionalLibraries();
    for (final URL url : additionalLibraries) {
        final File file = toFile(url);
        try {
            appInfo.libs.add(file.getCanonicalPath());
        } catch (final IOException e) {
            throw new OpenEJBException("Invalid application lib path " + file.getAbsolutePath());
        }
    }
    if (appModule.getCmpMappings() != null) {
        try {
            appInfo.cmpMappingsXml = JpaJaxbUtil.marshal(EntityMappings.class, appModule.getCmpMappings());
        } catch (final JAXBException e) {
            throw new OpenEJBException("Unable to marshal cmp entity mappings", e);
        }
    }
    final ReportValidationResults reportValidationResults = new ReportValidationResults();
    reportValidationResults.deploy(appModule);
    logger.info("config.appLoaded", appInfo.path);
    appInfo.webAppAlone = appModule.isWebapp();
    return appInfo;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) BeforeAppInfoBuilderEvent(org.apache.openejb.config.event.BeforeAppInfoBuilderEvent) URL(java.net.URL) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) Messages(org.apache.openejb.util.Messages) ConnectorInfo(org.apache.openejb.assembler.classic.ConnectorInfo) JndiEncInfo(org.apache.openejb.assembler.classic.JndiEncInfo) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) References(org.apache.openejb.util.References) CircularReferencesException(org.apache.openejb.util.CircularReferencesException) EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) URLs.toFile(org.apache.openejb.util.URLs.toFile) File(java.io.File)

Aggregations

EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)52 Assembler (org.apache.openejb.assembler.classic.Assembler)34 EjbJar (org.apache.openejb.jee.EjbJar)26 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)21 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)21 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)17 AppInfo (org.apache.openejb.assembler.classic.AppInfo)16 HashMap (java.util.HashMap)14 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)14 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)13 BeanContext (org.apache.openejb.BeanContext)11 File (java.io.File)10 Properties (java.util.Properties)10 InitialContext (javax.naming.InitialContext)10 StatelessBean (org.apache.openejb.jee.StatelessBean)10 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)9 ArrayList (java.util.ArrayList)8 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)8 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)8 Test (org.junit.Test)8