Search in sources :

Example 6 with ResourceLink

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

the class ApplyOpenejbJar method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final Map<String, EjbDeployment> ejbDeployments = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
        for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            // Get the OpenEJB deployment from openejb-jar.xml
            final EjbDeployment ejbDeployment = ejbDeployments.get(enterpriseBean.getEjbName());
            enterpriseBean.setId(ejbDeployment.getDeploymentId());
            for (final ResourceRef ref : enterpriseBean.getResourceRef()) {
                final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
                if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(resourceLink.getResId());
                }
            }
            for (final ResourceEnvRef ref : enterpriseBean.getResourceEnvRef()) {
                final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
                if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(resourceLink.getResId());
                }
            }
            for (final MessageDestinationRef ref : enterpriseBean.getMessageDestinationRef()) {
                final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
                if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(resourceLink.getResId());
                }
            }
            for (final EjbRef ref : enterpriseBean.getEjbRef()) {
                final EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
                if (ejbLink != null && ejbLink.getDeployentId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(ejbLink.getDeployentId());
                }
            }
            for (final EjbLocalRef ref : enterpriseBean.getEjbLocalRef()) {
                final EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
                if (ejbLink != null && ejbLink.getDeployentId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(ejbLink.getDeployentId());
                }
            }
        }
    }
    return appModule;
}
Also used : EjbLocalRef(org.apache.openejb.jee.EjbLocalRef) MessageDestinationRef(org.apache.openejb.jee.MessageDestinationRef) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) EjbRef(org.apache.openejb.jee.EjbRef) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ResourceRef(org.apache.openejb.jee.ResourceRef) ResourceEnvRef(org.apache.openejb.jee.ResourceEnvRef) EjbLink(org.apache.openejb.jee.oejb3.EjbLink)

Example 7 with ResourceLink

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

the class AutoConfig method processActivationConfig.

/**
     * Set destination, destinationType, clientId and subscriptionName in the MDB activation config.
     */
private void processActivationConfig(final EjbModule ejbModule) throws OpenEJBException {
    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
        openejbJar = ejbModule.getOpenejbJar();
    } else {
        openejbJar = new OpenejbJar();
        ejbModule.setOpenejbJar(openejbJar);
    }
    final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        if (bean instanceof MessageDrivenBean) {
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            if (mdb.getActivationConfig() == null) {
                mdb.setActivationConfig(new ActivationConfig());
            }
            if (!isJms(mdb)) {
                continue;
            }
            final EjbDeployment ejbDeployment = deployments.get(bean.getEjbName());
            if (ejbDeployment == null) {
                throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
            }
            final Properties properties = mdb.getActivationConfig().toProperties();
            String destination = properties.getProperty("destinationName", properties.getProperty("destinationLookup"));
            if (destination != null) {
                if (destination.startsWith("openejb:Resource/")) {
                    destination = destination.substring("openejb:Resource/".length());
                }
                if (destination.startsWith("java:openejb/Resource/")) {
                    destination = destination.substring("java:openejb/Resource/".length());
                }
                mdb.getActivationConfig().addProperty("destination", destination);
                // Remove destinationName as it is not in the standard ActivationSpec 
                final List<ActivationConfigProperty> list = mdb.getActivationConfig().getActivationConfigProperty();
                final Iterator<ActivationConfigProperty> iterator = list.iterator();
                while (iterator.hasNext()) {
                    final ActivationConfigProperty configProperty = iterator.next();
                    final String activationConfigPropertyName = configProperty.getActivationConfigPropertyName();
                    if (activationConfigPropertyName.equals("destinationName") || activationConfigPropertyName.equals("destinationLookup")) {
                        iterator.remove();
                        // we suppose we have only one of both we should be the case
                        break;
                    }
                }
            } else {
                destination = properties.getProperty("destination");
            }
            if (destination == null) {
                // EE 7/EJB 3.2
                destination = properties.getProperty("destinationLookup");
            }
            //                String destination = properties.getProperty("destination", properties.getProperty("destinationName"));
            if (destination == null) {
                destination = ejbDeployment.getDeploymentId();
                mdb.getActivationConfig().addProperty("destination", destination);
            }
            // destination identifier
            ResourceLink link = ejbDeployment.getResourceLink("openejb/destination");
            if (link == null && mdb.getMessageDestinationLink() == null) {
                link = new ResourceLink();
                link.setResId(destination);
                link.setResRefName("openejb/destination");
                ejbDeployment.addResourceLink(link);
            }
            // destination type
            String destinationType = properties.getProperty("destinationType");
            if (destinationType == null && mdb.getMessageDestinationType() != null) {
                destinationType = mdb.getMessageDestinationType();
                mdb.getActivationConfig().addProperty("destinationType", destinationType);
            }
            if (mdb.getMessageDestinationType() == null) {
                mdb.setMessageDestinationType(destinationType);
            }
            // topics need a clientId and subscriptionName
            if ("javax.jms.Topic".equals(destinationType)) {
                if (Boolean.parseBoolean(SystemInstance.get().getProperty("openejb.activemq.deploymentId-as-clientId", ejbModule.getProperties().getProperty("openejb.activemq.deploymentId-as-clientId", "true"))) && !properties.containsKey("clientId")) {
                    mdb.getActivationConfig().addProperty("clientId", ejbDeployment.getDeploymentId());
                }
                if (!properties.containsKey("subscriptionName")) {
                    mdb.getActivationConfig().addProperty("subscriptionName", ejbDeployment.getDeploymentId() + "_subscription");
                }
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) ActivationConfig(org.apache.openejb.jee.ActivationConfig) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment)

Example 8 with ResourceLink

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

the class AutoConfig method processResourceEnvRef.

private void processResourceEnvRef(final JndiReference ref, final EjbDeployment ejbDeployment, final AppResources appResources, final ClassLoader classLoader) throws OpenEJBException {
    // skip destinations with lookup name
    if (ref.getLookupName() != null) {
        return;
    }
    // skip destinations with a global jndi name
    final String mappedName = ref.getMappedName() == null ? "" : ref.getMappedName();
    if (mappedName.startsWith("jndi:")) {
        return;
    }
    final String refName = ref.getName();
    final String refType = getType(ref, classLoader);
    // skip references such as SessionContext which are automatically handled by the server
    if (isIgnoredReferenceType(refType, classLoader)) {
        return;
    }
    ResourceLink link = ejbDeployment.getResourceLink(refName);
    if (link == null) {
        String id = mappedName.length() == 0 ? refName : mappedName;
        id = getResourceEnvId(ejbDeployment.getDeploymentId(), id, refType, appResources);
        if (id == null) {
            // could be a session context ref
            return;
        }
        logger.info("Auto-linking resource-env-ref '" + refName + "' in bean " + ejbDeployment.getDeploymentId() + " to Resource(id=" + id + ")");
        link = new ResourceLink();
        link.setResId(id);
        link.setResRefName(refName);
        ejbDeployment.addResourceLink(link);
    } else {
        final String id = getResourceEnvId(ejbDeployment.getDeploymentId(), link.getResId(), refType, appResources);
        link.setResId(id);
        link.setResRefName(refName);
    }
}
Also used : ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink)

Example 9 with ResourceLink

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

the class SunConversion method mergeEjbConfig.

private void mergeEjbConfig(final EjbModule ejbModule, final SunEjbJar sunEjbJar) {
    final EjbJar ejbJar = ejbModule.getEjbJar();
    final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
    if (openejbJar == null) {
        return;
    }
    if (sunEjbJar == null) {
        return;
    }
    if (sunEjbJar.getEnterpriseBeans() == null) {
        return;
    }
    final Map<String, Map<String, WebserviceEndpoint>> endpointMap = new HashMap<String, Map<String, WebserviceEndpoint>>();
    for (final Ejb ejb : sunEjbJar.getEnterpriseBeans().getEjb()) {
        final EjbDeployment deployment = openejbJar.getDeploymentsByEjbName().get(ejb.getEjbName());
        if (deployment == null) {
            // warn no matching deployment
            continue;
        }
        // ejb jndi name is the deploymentId
        if (ejb.getJndiName() != null) {
            deployment.setDeploymentId(ejb.getJndiName());
        }
        // map ejb-ref jndi name declaration to deploymentId
        final Map<String, EjbLink> linksMap = deployment.getEjbLinksMap();
        for (final EjbRef ref : ejb.getEjbRef()) {
            if (ref.getJndiName() != null) {
                String refName = ref.getEjbRefName();
                refName = normalize(refName);
                EjbLink link = linksMap.get(refName);
                if (link == null) {
                    link = new EjbLink();
                    link.setEjbRefName(refName);
                    linksMap.put(refName, link);
                    deployment.getEjbLink().add(link);
                }
                link.setDeployentId(ref.getJndiName());
            }
        }
        final Map<String, ResourceLink> resourceLinksMap = deployment.getResourceLinksMap();
        for (final ResourceRef ref : ejb.getResourceRef()) {
            if (ref.getJndiName() != null) {
                String refName = ref.getResRefName();
                refName = normalize(refName);
                ResourceLink link = resourceLinksMap.get(refName);
                if (link == null) {
                    link = new ResourceLink();
                    link.setResRefName(refName);
                    resourceLinksMap.put(refName, link);
                    deployment.getResourceLink().add(link);
                }
                link.setResId(ref.getJndiName());
            }
        }
        for (final ResourceEnvRef ref : ejb.getResourceEnvRef()) {
            if (ref.getJndiName() != null) {
                String refName = ref.getResourceEnvRefName();
                refName = normalize(refName);
                ResourceLink link = resourceLinksMap.get(refName);
                if (link == null) {
                    link = new ResourceLink();
                    link.setResRefName(refName);
                    resourceLinksMap.put(refName, link);
                    deployment.getResourceLink().add(link);
                }
                link.setResId(ref.getJndiName());
            }
        }
        for (final MessageDestinationRef ref : ejb.getMessageDestinationRef()) {
            if (ref.getJndiName() != null) {
                String refName = ref.getMessageDestinationRefName();
                refName = normalize(refName);
                ResourceLink link = resourceLinksMap.get(refName);
                if (link == null) {
                    link = new ResourceLink();
                    link.setResRefName(refName);
                    resourceLinksMap.put(refName, link);
                    deployment.getResourceLink().add(link);
                }
                link.setResId(ref.getJndiName());
            }
        }
        final EnterpriseBean bean = ejbJar.getEnterpriseBeansByEjbName().get(ejb.getEjbName());
        if (bean != null) {
            final Map<String, ServiceRef> serviceRefMap = bean.getServiceRefMap();
            for (final org.apache.openejb.jee.sun.ServiceRef ref : ejb.getServiceRef()) {
                String refName = ref.getServiceRefName();
                refName = normalize(refName);
                final ServiceRef serviceRef = serviceRefMap.get(refName);
                if (serviceRef != null) {
                    final Map<String, PortComponentRef> ports = new TreeMap<String, PortComponentRef>();
                    for (final PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
                        ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
                    }
                    for (final PortInfo portInfo : ref.getPortInfo()) {
                        final PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
                        if (portComponentRef != null) {
                            final WsdlPort wsdlPort = portInfo.getWsdlPort();
                            if (wsdlPort != null) {
                                final QName qname = new QName(wsdlPort.getNamespaceURI(), wsdlPort.getLocalpart());
                                portComponentRef.setQName(qname);
                            }
                            for (final StubProperty stubProperty : portInfo.getStubProperty()) {
                                final String name = stubProperty.getName();
                                final String value = stubProperty.getValue();
                                portComponentRef.getProperties().setProperty(name, value);
                            }
                        }
                    }
                    final String wsdlOverride = ref.getWsdlOverride();
                    if (wsdlOverride != null && wsdlOverride.length() > 0) {
                        final String serviceId = extractServiceId(wsdlOverride);
                        serviceRef.setMappedName(serviceId);
                    }
                }
            }
        }
        if (ejb.getMdbResourceAdapter() != null) {
            // resource adapter id is the MDB container ID
            final String resourceAdapterId = ejb.getMdbResourceAdapter().getResourceAdapterMid();
            deployment.setContainerId(resourceAdapterId);
        }
        endpointMap.put(ejb.getEjbName(), ejb.getWebserviceEndpointMap());
    }
    // map wsdl locations
    if (ejbModule.getWebservices() != null) {
        final Map<String, org.apache.openejb.jee.sun.WebserviceDescription> sunDescriptions = sunEjbJar.getEnterpriseBeans().getWebserviceDescriptionMap();
        for (final WebserviceDescription description : ejbModule.getWebservices().getWebserviceDescription()) {
            final org.apache.openejb.jee.sun.WebserviceDescription sunDescription = sunDescriptions.get(description.getWebserviceDescriptionName());
            // get the serviceId if specified
            String serviceId = null;
            if (sunDescription != null) {
                serviceId = extractSerivceId(sunDescription.getWsdlPublishLocation(), description.getWsdlFile());
            }
            if (serviceId != null) {
                description.setId(serviceId);
            }
            for (final PortComponent port : description.getPortComponent()) {
                // set the ejb bind location
                final ServiceImplBean bean = port.getServiceImplBean();
                if (bean != null && bean.getEjbLink() != null) {
                    final Map<String, WebserviceEndpoint> endpoints = endpointMap.get(bean.getEjbLink());
                    if (endpoints != null) {
                        final WebserviceEndpoint endpoint = endpoints.get(port.getPortComponentName());
                        if (endpoint != null && endpoint.getEndpointAddressUri() != null) {
                            port.setLocation(endpoint.getEndpointAddressUri());
                        }
                    }
                }
            }
        }
    }
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) PortComponent(org.apache.openejb.jee.PortComponent) HashMap(java.util.HashMap) WsdlPort(org.apache.openejb.jee.sun.WsdlPort) PortInfo(org.apache.openejb.jee.sun.PortInfo) MessageDestinationRef(org.apache.openejb.jee.sun.MessageDestinationRef) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) EjbRef(org.apache.openejb.jee.sun.EjbRef) ResourceEnvRef(org.apache.openejb.jee.sun.ResourceEnvRef) EjbJar(org.apache.openejb.jee.EjbJar) SunEjbJar(org.apache.openejb.jee.sun.SunEjbJar) ServiceImplBean(org.apache.openejb.jee.ServiceImplBean) QName(javax.xml.namespace.QName) StubProperty(org.apache.openejb.jee.sun.StubProperty) WebserviceEndpoint(org.apache.openejb.jee.sun.WebserviceEndpoint) TreeMap(java.util.TreeMap) EjbLink(org.apache.openejb.jee.oejb3.EjbLink) PortComponentRef(org.apache.openejb.jee.PortComponentRef) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ResourceRef(org.apache.openejb.jee.sun.ResourceRef) Ejb(org.apache.openejb.jee.sun.Ejb) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ServiceRef(org.apache.openejb.jee.ServiceRef)

Aggregations

ResourceLink (org.apache.openejb.jee.oejb3.ResourceLink)9 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)6 OpenEJBException (org.apache.openejb.OpenEJBException)5 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)5 MessageDestinationRef (org.apache.openejb.jee.MessageDestinationRef)4 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)4 Properties (java.util.Properties)3 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)3 ResourceRef (org.apache.openejb.jee.ResourceRef)3 SuperProperties (org.apache.openejb.util.SuperProperties)3 HashMap (java.util.HashMap)2 ActivationConfig (org.apache.openejb.jee.ActivationConfig)2 ActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty)2 ResourceEnvRef (org.apache.openejb.jee.ResourceEnvRef)2 EjbLink (org.apache.openejb.jee.oejb3.EjbLink)2 URI (java.net.URI)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Queue (javax.jms.Queue)1 QName (javax.xml.namespace.QName)1