use of org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean in project tomee by apache.
the class ResourceAdapterControlTest method app.
@Module
@Classes(value = Mdb.class)
public EjbModule app() {
return new EjbModule(new EjbJar("test") {
{
addEnterpriseBean(new MessageDrivenBean("ejb/Mdb", Mdb.class) {
{
setActivationConfig(new ActivationConfig());
getActivationConfig().addProperty("MdbActiveOnStartup", "false");
getActivationConfig().addProperty("MdbJMXControl", "default:type=test");
}
});
}
});
}
use of org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean in project tomee by apache.
the class AutoConfig method getUsableContainer.
private String getUsableContainer(final Class<? extends ContainerInfo> containerInfoType, final Object bean, final AppResources appResources) {
if (MessageDrivenBean.class.isInstance(bean)) {
final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
final String messagingType = messageDrivenBean.getMessagingType();
final List<String> containerIds = appResources.containerIdsByType.get(messagingType);
if (containerIds != null && !containerIds.isEmpty()) {
return containerIds.get(0);
}
}
String containerInfo = matchContainer(containerInfoType, bean, appResources.getContainerInfos());
if (containerInfo == null) {
// avoid to build configFactory.getContainerInfos() if not needed
containerInfo = matchContainer(containerInfoType, bean, configFactory.getContainerInfos());
}
if (containerInfo != null) {
return containerInfo;
}
return null;
}
use of org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean 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.MessageDrivenBean$JAXB.writeMessageDrivenBean 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");
}
}
}
}
}
use of org.apache.openejb.jee.MessageDrivenBean$JAXB.writeMessageDrivenBean in project tomee by apache.
the class AutoConfig method getUsableContainer.
private String getUsableContainer(final Class<? extends ContainerInfo> containerInfoType, final EnterpriseBean bean, final AppResources appResources) {
if (logger.isDebugEnabled()) {
logger.debug("Searching for usable container for bean: {0}. Available application containers: {1}, available system containers {2}", bean.getEjbName(), getContainerIds(appResources.getContainerInfos()), getContainerIds(configFactory.getContainerInfos()));
}
if (MessageDrivenBean.class.isInstance(bean)) {
final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
final String messagingType = messageDrivenBean.getMessagingType();
final List<String> containerIds = appResources.containerIdsByType.get(messagingType);
if (logger.isDebugEnabled()) {
logger.debug("Searching for usable container for bean: {0} by messaging type: {1}. Potential application containers: {2}", bean.getEjbName(), messagingType, containerIds == null ? "" : Join.join(",", containerIds));
}
if (containerIds != null && !containerIds.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("Returning first application container matching by type: {0} - {1}", messagingType, containerIds.get(0));
}
return containerIds.get(0);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Attempting to find a matching container for bean: {0} from application containers {1}", bean.getEjbName(), getContainerIds(appResources.getContainerInfos()));
}
String containerInfo = matchContainer(containerInfoType, bean, appResources.getContainerInfos());
if (containerInfo == null) {
if (logger.isDebugEnabled()) {
logger.debug("Matching application container not found. Attempting to find a matching container for bean: {0} from system containers {1}", bean.getEjbName(), getContainerIds(appResources.getContainerInfos()));
}
containerInfo = matchContainer(containerInfoType, bean, configFactory.getContainerInfos());
}
if (containerInfo != null) {
if (logger.isDebugEnabled()) {
logger.debug("Using container {0} for bean {1}", containerInfo, bean.getEjbName());
}
return containerInfo;
}
if (logger.isDebugEnabled()) {
logger.debug("No suitable existing container found for bean {0}", bean.getEjbName());
}
return null;
}
Aggregations