Search in sources :

Example 1 with ActivationConfigProperty$JAXB.readActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty in project tomee by apache.

the class EjbJarInfoBuilder method initMessageBean.

private EnterpriseBeanInfo initMessageBean(final MessageDrivenBean mdb, final Map m) throws OpenEJBException {
    final MessageDrivenBeanInfo bean = new MessageDrivenBeanInfo();
    bean.timeoutMethod = toInfo(mdb.getTimeoutMethod());
    copyCallbacks(mdb.getAroundTimeout(), bean.aroundTimeout);
    copyCallbacks(mdb.getAroundInvoke(), bean.aroundInvoke);
    copyCallbacks(mdb.getPostConstruct(), bean.postConstruct);
    copyCallbacks(mdb.getPreDestroy(), bean.preDestroy);
    copySchedules(mdb.getTimer(), bean.methodScheduleInfos);
    final EjbDeployment d = (EjbDeployment) m.get(mdb.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + mdb.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = mdb.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = mdb.getDescription();
    bean.displayName = mdb.getDisplayName();
    bean.ejbClass = mdb.getEjbClass();
    bean.ejbName = mdb.getEjbName();
    final TransactionType txType = mdb.getTransactionType();
    bean.transactionType = txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
    bean.properties.putAll(d.getProperties());
    if (mdb.getMessagingType() != null) {
        bean.mdbInterface = mdb.getMessagingType();
    } else {
        bean.mdbInterface = "javax.jms.MessageListener";
    }
    final ResourceLink resourceLink = d.getResourceLink("openejb/destination");
    if (resourceLink != null) {
        bean.destinationId = resourceLink.getResId();
    }
    if (mdb.getMessageDestinationType() != null) {
        bean.activationProperties.put("destinationType", mdb.getMessageDestinationType());
    }
    final ActivationConfig activationConfig = mdb.getActivationConfig();
    if (activationConfig != null) {
        for (final ActivationConfigProperty property : activationConfig.getActivationConfigProperty()) {
            final String name = property.getActivationConfigPropertyName();
            final String value = property.getActivationConfigPropertyValue();
            bean.activationProperties.put(name, value);
        }
    }
    return bean;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) TransactionType(org.apache.openejb.jee.TransactionType) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Icon(org.apache.openejb.jee.Icon) ActivationConfig(org.apache.openejb.jee.ActivationConfig)

Example 2 with ActivationConfigProperty$JAXB.readActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty in project tomee by apache.

the class MdbConfigTest method createJaxbMdb.

private MessageDrivenBean createJaxbMdb(final String ejbName, final String mdbClass, final String messageListenerInterface) {
    final MessageDrivenBean bean = new MessageDrivenBean(ejbName);
    bean.setEjbClass(mdbClass);
    bean.setMessagingType(messageListenerInterface);
    final ActivationConfig activationConfig = new ActivationConfig();
    activationConfig.getActivationConfigProperty().add(new ActivationConfigProperty("destination", ejbName));
    activationConfig.getActivationConfigProperty().add(new ActivationConfigProperty("destinationType", "javax.jms.Queue"));
    bean.setActivationConfig(activationConfig);
    return bean;
}
Also used : ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ActivationConfig(org.apache.openejb.jee.ActivationConfig)

Example 3 with ActivationConfigProperty$JAXB.readActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty in project tomee by apache.

the class ActivationConfig$JAXB method _read.

public static final ActivationConfig _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final ActivationConfig activationConfig = new ActivationConfig();
    context.beforeUnmarshal(activationConfig, LifecycleCallback.NONE);
    ArrayList<Text> descriptions = null;
    List<ActivationConfigProperty> activationConfigProperty = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("activation-configType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, ActivationConfig.class);
        }
    }
    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
        if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
            // ATTRIBUTE: id
            final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
            context.addXmlId(reader, id, activationConfig);
            activationConfig.id = id;
        } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
            context.unexpectedAttribute(attribute, new QName("", "id"));
        }
    }
    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
        if (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: descriptions
            final Text descriptionsItem = readText(elementReader, context);
            if (descriptions == null) {
                descriptions = new ArrayList<Text>();
            }
            descriptions.add(descriptionsItem);
        } else if (("activation-config-property" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: activationConfigProperty
            final ActivationConfigProperty activationConfigPropertyItem = readActivationConfigProperty(elementReader, context);
            if (activationConfigProperty == null) {
                activationConfigProperty = activationConfig.activationConfigProperty;
                if (activationConfigProperty != null) {
                    activationConfigProperty.clear();
                } else {
                    activationConfigProperty = new ArrayList<ActivationConfigProperty>();
                }
            }
            activationConfigProperty.add(activationConfigPropertyItem);
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "activation-config-property"));
        }
    }
    if (descriptions != null) {
        try {
            activationConfig.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
        } catch (final Exception e) {
            context.setterError(reader, ActivationConfig.class, "setDescriptions", Text[].class, e);
        }
    }
    if (activationConfigProperty != null) {
        activationConfig.activationConfigProperty = activationConfigProperty;
    }
    context.afterUnmarshal(activationConfig, LifecycleCallback.NONE);
    return activationConfig;
}
Also used : ActivationConfigProperty$JAXB.readActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty) ActivationConfigProperty$JAXB.writeActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 4 with ActivationConfigProperty$JAXB.readActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty in project tomee by apache.

the class ActivationConfigPropertyOverride method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    final Properties system = new Properties();
    system.putAll(SystemInstance.get().getProperties());
    system.putAll(appModule.getProperties());
    system.putAll(JavaSecurityManagers.getSystemProperties());
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final Properties module = new Properties();
        module.putAll(openejbJar.getProperties());
        module.putAll(system);
        final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            final String ejbName = bean.getEjbName();
            final EjbDeployment ejbDeployment = deployments.get(ejbName);
            if (!(bean instanceof MessageDrivenBean)) {
                continue;
            }
            final Properties properties = new Properties();
            properties.putAll(module);
            properties.putAll(ejbDeployment.getProperties());
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            // override with placeholding
            if (mdb.getActivationConfig() != null) {
                for (final ActivationConfigProperty property : mdb.getActivationConfig().getActivationConfigProperty()) {
                    final String originalValue = property.getActivationConfigPropertyValue();
                    final String value = PropertyPlaceHolderHelper.simpleValue(originalValue);
                    if (value != null && !originalValue.equals(value)) {
                        property.setActivationConfigPropertyValue(value);
                    }
                }
            }
            // now try to use special keys
            final Properties overrides = new Properties();
            final MdbContainerDetails mdbContainer = getMdbContainer(appModule, ejbDeployment.getContainerId(), appModule.getModuleId());
            if (mdbContainer != null) {
                overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.container." + mdbContainer.getContainerId() + ".activation", "EnterpriseBean"));
                overrides.putAll(ConfigurationFactory.getOverrides(mdbContainer.getProperties(), "activation", "EnterpriseBean"));
            }
            overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, mdb.getMessagingType() + ".activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbName + ".activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbDeployment.getDeploymentId() + ".activation", "EnterpriseBean"));
            // If we don't have any overrides, skip to the next
            if (overrides.size() == 0) {
                continue;
            }
            if (mdb.getActivationConfig() == null) {
                mdb.setActivationConfig(new ActivationConfig());
            }
            final List<ActivationConfigProperty> activationConfigList = mdb.getActivationConfig().getActivationConfigProperty();
            for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                final Object property = String.valueOf(entry.getKey());
                final Object value = String.valueOf(entry.getValue());
                ActivationConfigProperty activationConfigProperty = this.findActivationProperty(activationConfigList, property.toString());
                if (activationConfigProperty != null) {
                    logger.info(String.format("Found %s bean with activation-config property %s=%s to override", ejbName, activationConfigProperty.getActivationConfigPropertyName(), activationConfigProperty.getActivationConfigPropertyValue()));
                    logger.info(String.format("Overriding %s bean activation-config property.%s=%s", ejbName, property, value));
                    activationConfigProperty.setActivationConfigPropertyValue(entry.getValue().toString());
                } else {
                    logger.info(String.format("Adding %s bean activation-config property %s=%s", ejbName, property, value));
                    activationConfigProperty = new ActivationConfigProperty();
                    activationConfigProperty.setActivationConfigPropertyName(property.toString());
                    activationConfigProperty.setActivationConfigPropertyValue(value.toString());
                    activationConfigList.add(activationConfigProperty);
                }
            }
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Properties(java.util.Properties) 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) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Map(java.util.Map) EjbJar(org.apache.openejb.jee.EjbJar)

Example 5 with ActivationConfigProperty$JAXB.readActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty 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)

Aggregations

ActivationConfig (org.apache.openejb.jee.ActivationConfig)5 ActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty)5 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)4 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)3 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)3 Properties (java.util.Properties)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 ActivationConfigProperty$JAXB.readActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty)2 ActivationConfigProperty$JAXB.writeActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty)2 Text$JAXB.readText (org.apache.openejb.jee.Text$JAXB.readText)2 Text$JAXB.writeText (org.apache.openejb.jee.Text$JAXB.writeText)2 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)2 ResourceLink (org.apache.openejb.jee.oejb3.ResourceLink)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)1 QName (javax.xml.namespace.QName)1 MessageDrivenBeanInfo (org.apache.openejb.assembler.classic.MessageDrivenBeanInfo)1