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;
}
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;
}
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;
}
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;
}
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");
}
}
}
}
}
Aggregations