Search in sources :

Example 26 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class RootBeanDeploymentArchiveTest method testConstructor.

@Test
public void testConstructor() throws Exception {
    String archiveName = "an";
    String webInfLib1 = "WEB-INF/lib/lib1.jar";
    String webInfLib2 = "WEB-INF/lib/lib2.jar";
    String subArchive11Name = "sa1";
    String subArchive12Name = "sa2";
    URI webInfLib1URI = URI.create(webInfLib1);
    URI webInfLib2URI = URI.create(webInfLib2);
    ArrayList<String> lib1ClassNames = new ArrayList<>();
    lib1ClassNames.add(Lib1Class1.class.getName() + ".class");
    lib1ClassNames.add(Lib1Class2.class.getName() + ".class");
    ArrayList<String> lib2ClassNames = new ArrayList<>();
    lib2ClassNames.add(Lib2Class1.class.getName() + ".class");
    lib2ClassNames.add(Lib2Class2.class.getName() + ".class");
    WeldUtils.BDAType bdaType = WeldUtils.BDAType.WAR;
    ArrayList<String> webInfLibEntries = new ArrayList<>();
    webInfLibEntries.add(webInfLib1);
    webInfLibEntries.add(webInfLib2);
    EasyMockSupport mockSupport = new EasyMockSupport();
    BeansXml beansXML = mockSupport.createMock(BeansXml.class);
    WeldBootstrap wb = mockSupport.createMock(WeldBootstrap.class);
    ReadableArchive readableArchive = mockSupport.createMock(ReadableArchive.class);
    ReadableArchive subArchive1 = mockSupport.createMock(ReadableArchive.class);
    ReadableArchive subArchive2 = mockSupport.createMock(ReadableArchive.class);
    Collection<EjbDescriptor> ejbs = Collections.emptyList();
    DeploymentContext deploymentContext = mockSupport.createMock(DeploymentContext.class);
    expect(deploymentContext.getClassLoader()).andReturn(null).anyTimes();
    expect(readableArchive.getName()).andReturn(archiveName).anyTimes();
    expect(readableArchive.exists(WeldUtils.WEB_INF_BEANS_XML)).andReturn(true).anyTimes();
    expect(readableArchive.exists(WeldUtils.WEB_INF_CLASSES_META_INF_BEANS_XML)).andReturn(false).anyTimes();
    // in BeanDeploymentArchiveImpl.populate
    expect(deploymentContext.getTransientAppMetadata()).andReturn(null).anyTimes();
    expect(deploymentContext.getModuleMetaData(Application.class)).andReturn(null).anyTimes();
    expect(deploymentContext.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class)).andReturn(wb).anyTimes();
    expect(wb.parse(anyObject(URL.class))).andReturn(beansXML).anyTimes();
    expect(readableArchive.getURI()).andReturn(URI.create("an.war")).anyTimes();
    expect(subArchive1.getURI()).andReturn(webInfLib1URI).anyTimes();
    expect(subArchive2.getURI()).andReturn(webInfLib2URI).anyTimes();
    expect(beansXML.getBeanDiscoveryMode()).andReturn(BeanDiscoveryMode.ALL).anyTimes();
    expect(readableArchive.entries()).andReturn(Collections.<String>emptyEnumeration());
    readableArchive.close();
    expect(readableArchive.exists(WeldUtils.WEB_INF_LIB)).andReturn(true).anyTimes();
    expect(readableArchive.entries(WeldUtils.WEB_INF_LIB)).andReturn(Collections.enumeration(webInfLibEntries));
    expect(readableArchive.getSubArchive(webInfLib1)).andReturn(subArchive1);
    expect(subArchive1.exists(WeldUtils.META_INF_BEANS_XML)).andReturn(true);
    expect(readableArchive.getSubArchive(webInfLib2)).andReturn(subArchive2);
    expect(subArchive2.exists(WeldUtils.META_INF_BEANS_XML)).andReturn(true);
    // build new BeanDeploymentArchiveImpl for lib1 and lib2
    setupMocksForWebInfLibBda(subArchive1, subArchive11Name, lib1ClassNames);
    setupMocksForWebInfLibBda(subArchive2, subArchive12Name, lib2ClassNames);
    readableArchive.close();
    mockSupport.replayAll();
    RootBeanDeploymentArchive rootBeanDeploymentArchive = new RootBeanDeploymentArchive(readableArchive, ejbs, deploymentContext);
    assertEquals("root_" + archiveName, rootBeanDeploymentArchive.getId());
    assertEquals(WeldUtils.BDAType.UNKNOWN, rootBeanDeploymentArchive.getBDAType());
    assertEquals(0, rootBeanDeploymentArchive.getBeanClasses().size());
    assertEquals(0, rootBeanDeploymentArchive.getBeanClassObjects().size());
    assertNull(rootBeanDeploymentArchive.getBeansXml());
    BeanDeploymentArchiveImpl moduleBda = (BeanDeploymentArchiveImpl) rootBeanDeploymentArchive.getModuleBda();
    assertNotNull(moduleBda);
    assertEquals(WeldUtils.BDAType.WAR, moduleBda.getBDAType());
    assertEquals(3, rootBeanDeploymentArchive.getBeanDeploymentArchives().size());
    assertTrue(rootBeanDeploymentArchive.getBeanDeploymentArchives().contains(moduleBda));
    assertEquals(3, moduleBda.getBeanDeploymentArchives().size());
    assertTrue(moduleBda.getBeanDeploymentArchives().contains(rootBeanDeploymentArchive));
    assertEquals(0, rootBeanDeploymentArchive.getModuleBeanClasses().size());
    assertEquals(0, rootBeanDeploymentArchive.getModuleBeanClassObjects().size());
    assertSame(rootBeanDeploymentArchive.getModuleClassLoaderForBDA(), moduleBda.getModuleClassLoaderForBDA());
    mockSupport.verifyAll();
    mockSupport.resetAll();
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) WeldUtils(org.glassfish.weld.connector.WeldUtils) URI(java.net.URI) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) Test(org.junit.Test)

Example 27 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class InboundRecoveryHandler method getEjbDescriptors.

private Vector getEjbDescriptors(Application application, ApplicationRegistry appsRegistry) {
    Vector ejbDescriptors = new Vector();
    if (ResourcesUtil.createInstance().isEnabled(application)) {
        ApplicationInfo appInfo = appsRegistry.get(application.getName());
        // non java-ee apps do not have ejbs, and they dont't have Application entry, leading to NPE
        if (appInfo != null && appInfo.isJavaEEApp()) {
            com.sun.enterprise.deployment.Application app = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
            Set<BundleDescriptor> descriptors = app.getBundleDescriptors();
            for (BundleDescriptor descriptor : descriptors) {
                if (descriptor instanceof EjbBundleDescriptor) {
                    EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) descriptor;
                    Set<? extends EjbDescriptor> ejbDescriptorsSet = ejbBundleDescriptor.getEjbs();
                    for (EjbDescriptor ejbDescriptor : ejbDescriptorsSet) {
                        ejbDescriptors.add(ejbDescriptor);
                    }
                }
            }
        } else {
            // application is enabled, but still not found in app-registry
            _logger.log(Level.WARNING, "application.not.started.skipping.recovery", application.getName());
        }
    }
    return ejbDescriptors;
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Vector(java.util.Vector) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 28 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class InboundRecoveryHandler method recoverInboundTransactions.

private void recoverInboundTransactions(List<XAResource> xaresList) {
    List<Application> applications = deployedApplications.getApplications();
    try {
        _logger.log(Level.INFO, "Recovery of Inbound Transactions started.");
        if (applications.size() == 0) {
            _logger.log(Level.FINE, "No applications deployed.");
            return;
        }
        // List of CMT enabled MDB descriptors on the application server instance.
        List<EjbDescriptor> xaEnabledMDBList = new ArrayList<EjbDescriptor>();
        // Done so as to initialize connectors-runtime before loading inbound active RA. need a better way ?
        ConnectorRuntime cr = connectorRuntimeProvider.get();
        for (Application application : applications) {
            Vector ejbDescVec = getEjbDescriptors(application, appsRegistry);
            for (int j = 0; j < ejbDescVec.size(); j++) {
                EjbDescriptor desc = (EjbDescriptor) ejbDescVec.elementAt(j);
                // add it to the list of xaEnabledMDBList.
                if (desc instanceof EjbMessageBeanDescriptor && desc.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
                    xaEnabledMDBList.add(desc);
                    _logger.log(Level.FINE, "Found a CMT MDB: " + desc.getEjbClassName());
                }
            }
        }
        if (xaEnabledMDBList.size() == 0) {
            _logger.log(Level.FINE, "Found no CMT MDBs in all applications");
            return;
        }
        ConnectorRegistry creg = ConnectorRegistry.getInstance();
        // for each RA (key in the map) get the list (value) of MDB Descriptors
        Map<String, List<EjbDescriptor>> mappings = createRAEjbMapping(xaEnabledMDBList);
        // For each RA
        for (Map.Entry entry : mappings.entrySet()) {
            String raMid = (String) entry.getKey();
            List<EjbDescriptor> respectiveDesc = mappings.get(raMid);
            try {
                createActiveResourceAdapter(raMid);
            } catch (Exception ex) {
                _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", raMid);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, ex.toString(), ex);
                }
            }
            ActiveInboundResourceAdapter activeInboundRA = (ActiveInboundResourceAdapter) creg.getActiveResourceAdapter(raMid);
            // assert activeInboundRA instanceof ActiveInboundResourceAdapter;
            boolean isSystemJmsRA = false;
            if (ConnectorsUtil.isJMSRA(activeInboundRA.getModuleName())) {
                isSystemJmsRA = true;
            }
            javax.resource.spi.ResourceAdapter resourceAdapter = activeInboundRA.getResourceAdapter();
            // activationSpecList represents the ActivationSpec[] that would be
            // sent to the getXAResources() method.
            ArrayList<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
            try {
                for (int i = 0; i < respectiveDesc.size(); i++) {
                    try {
                        // Get a MessageBeanDescriptor from respectiveDesc ArrayList
                        EjbMessageBeanDescriptor descriptor = (EjbMessageBeanDescriptor) respectiveDesc.get(i);
                        // to be updated J2EE 1.4 style props.
                        if (isSystemJmsRA) {
                            // XXX: Find out the pool descriptor corres to MDB and update
                            // MDBRuntimeInfo with that.
                            activeInboundRA.updateMDBRuntimeInfo(descriptor, null);
                        }
                        // Get the ActivationConfig Properties from the MDB Descriptor
                        Set activationConfigProps = RARUtils.getMergedActivationConfigProperties(descriptor);
                        // get message listener type
                        String msgListenerType = descriptor.getMessageListenerType();
                        // start resource adapter and get ActivationSpec class for
                        // the given message listener type from the ConnectorRuntime
                        ActivationSpec aspec = (ActivationSpec) (Class.forName(cr.getActivationSpecClass(raMid, msgListenerType), false, resourceAdapter.getClass().getClassLoader()).newInstance());
                        aspec.setResourceAdapter(resourceAdapter);
                        // Populate ActivationSpec class with ActivationConfig properties
                        SetMethodAction sma = new SetMethodAction(aspec, activationConfigProps);
                        sma.run();
                        activationSpecList.add(aspec);
                    } catch (Exception e) {
                        _logger.log(Level.WARNING, "error.creating.activationspec", e.getMessage());
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, e.toString(), e);
                        }
                    }
                }
                // Get XA resources from RA.
                ActivationSpec[] activationSpecArray = activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]);
                XAResource[] xar = resourceAdapter.getXAResources(activationSpecArray);
                // Add the resources to the xaresList which is used by the RecoveryManager
                if (xar != null) {
                    for (int p = 0; p < xar.length; p++) {
                        xaresList.add(xar[p]);
                    }
                }
            // Catch UnsupportedOperationException if a RA does not support XA
            // which is fine.
            } catch (UnsupportedOperationException uoex) {
                _logger.log(Level.FINE, uoex.getMessage());
            // otherwise catch the unexpected exception
            } catch (Exception e) {
                _logger.log(Level.SEVERE, "exception.during.inbound.resource.acqusition", e);
            }
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, "exception.during.inbound.recovery", e);
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) Vector(java.util.Vector) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) XAResource(javax.transaction.xa.XAResource) EjbMessageBeanDescriptor(com.sun.enterprise.deployment.EjbMessageBeanDescriptor) ActivationSpec(javax.resource.spi.ActivationSpec) Application(com.sun.enterprise.config.serverbeans.Application) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 29 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class ConcurrencyManagementHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    ConcurrencyManagement cmAn = (ConcurrencyManagement) ainfo.getAnnotation();
    ConcurrencyManagementType cmType = cmAn.value();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = ejbContext.getDescriptor();
        if (ejbDesc instanceof EjbSessionDescriptor) {
            EjbSessionDescriptor.ConcurrencyManagementType descCMType;
            switch(cmType) {
                case CONTAINER:
                    descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Container;
                    break;
                case BEAN:
                    descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Bean;
                    break;
                default:
                    throw new AnnotationProcessorException("Unsupported concurrency management " + "type = " + cmType);
            }
            EjbSessionDescriptor sDesc = (EjbSessionDescriptor) ejbDesc;
            // Set value on descriptor unless it has been set by .xml
            sDesc.setConcurrencyManagementTypeIfNotSet(descCMType);
        }
    }
    return getDefaultProcessedResult();
}
Also used : ConcurrencyManagement(javax.ejb.ConcurrencyManagement) ConcurrencyManagementType(javax.ejb.ConcurrencyManagementType) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 30 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class IIOPSSLUtilImpl method createSSLTaggedComponent.

@Override
public TaggedComponent createSSLTaggedComponent(IORInfo iorInfo, Object sInfos) {
    List<com.sun.corba.ee.spi.folb.SocketInfo> socketInfos = (List<com.sun.corba.ee.spi.folb.SocketInfo>) sInfos;
    orbHelper = Lookups.getGlassFishORBHelper();
    TaggedComponent result = null;
    org.omg.CORBA.ORB orb = orbHelper.getORB();
    int sslMutualAuthPort = -1;
    try {
        if (iorInfo instanceof com.sun.corba.ee.spi.legacy.interceptor.IORInfoExt) {
            sslMutualAuthPort = ((com.sun.corba.ee.spi.legacy.interceptor.IORInfoExt) iorInfo).getServerPort("SSL_MUTUALAUTH");
        }
    } catch (com.sun.corba.ee.spi.legacy.interceptor.UnknownType ute) {
        _logger.log(Level.FINE, ".isnert: UnknownType exception", ute);
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, ".insert: sslMutualAuthPort: " + sslMutualAuthPort);
    }
    CSIV2TaggedComponentInfo ctc = new CSIV2TaggedComponentInfo(orb, sslMutualAuthPort);
    EjbDescriptor desc = ctc.getEjbDescriptor(iorInfo);
    if (desc != null) {
        result = ctc.createSecurityTaggedComponent(socketInfos, desc);
    }
    return result;
}
Also used : EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) TaggedComponent(org.omg.IOP.TaggedComponent) List(java.util.List)

Aggregations

EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)48 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)16 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)11 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)10 Application (com.sun.enterprise.deployment.Application)6 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)6 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)5 ManagedBeanDescriptor (com.sun.enterprise.deployment.ManagedBeanDescriptor)4 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)4 ArrayList (java.util.ArrayList)4 Descriptor (org.glassfish.deployment.common.Descriptor)4 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)4 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)3 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)3 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)3 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)3 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)3 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)3 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)3 Method (java.lang.reflect.Method)3