use of org.apache.openejb.jee.oejb3.EjbDeployment 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.oejb3.EjbDeployment in project tomee by apache.
the class MappedNameBuilder method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
if (openejbJar == null) {
return appModule;
}
final Map<String, EjbDeployment> ejbDeployments = openejbJar.getDeploymentsByEjbName();
for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
final EjbDeployment ejbDeployment = ejbDeployments.get(enterpriseBean.getEjbName());
if (ejbDeployment == null) {
continue;
}
final String mappedName = enterpriseBean.getMappedName();
if (mappedName != null && mappedName.length() > 0) {
ejbDeployment.getJndi().add(new Jndi(mappedName, "Remote"));
}
}
}
return appModule;
}
use of org.apache.openejb.jee.oejb3.EjbDeployment 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());
}
}
}
}
}
}
}
use of org.apache.openejb.jee.oejb3.EjbDeployment in project tomee by apache.
the class SystemApps method getSystemModule.
public static EjbModule getSystemModule() {
final EjbModule module = new EjbModule(new EjbJar("openejb"), new OpenejbJar());
final OpenejbJar openejbJar = module.getOpenejbJar();
final EjbJar ejbJar = module.getEjbJar();
//
//
// DONT MODIFY IT WITHOUT VALIDATING org.apache.openejb.config.SystemAppInfo.preComputedInfo()
//
//
ejbJar.addEnterpriseBean(singleton(DeployerEjb.class));
ejbJar.addEnterpriseBean(singleton(ConfigurationInfoEjb.class));
ejbJar.addEnterpriseBean(singleton(MEJBBean.class));
ejbJar.addInterceptor(new Interceptor(InternalSecurityInterceptor.class));
ejbJar.getAssemblyDescriptor().addInterceptorBinding(new InterceptorBinding("*", InternalSecurityInterceptor.class.getName()));
module.getMbeans().add(JMXDeployer.class.getName());
final SingletonBean bean = ejbJar.addEnterpriseBean(new SingletonBean("openejb/WebappDeployer", "org.apache.tomee.catalina.deployer.WebappDeployer"));
final EjbDeployment deployment = openejbJar.addEjbDeployment(bean);
deployment.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.annotationName}");
final SingletonBean exceptionManager = ejbJar.addEnterpriseBean(new SingletonBean("openejb/ExceptionManagerFacade", "org.apache.tomee.catalina.facade.ExceptionManagerFacadeBean"));
final EjbDeployment exceptionMgr = openejbJar.addEjbDeployment(exceptionManager);
exceptionMgr.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.annotationName}");
openejbJar.getProperties().put("openejb.deploymentId.format", "{ejbName}");
openejbJar.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.openejbLegacyName}");
return module;
}
use of org.apache.openejb.jee.oejb3.EjbDeployment 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;
}
Aggregations