use of org.apache.openejb.jee.oejb3.EjbLink 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;
}
use of org.apache.openejb.jee.oejb3.EjbLink in project tomee by apache.
the class OpenEjb2Conversion method convertEjbRefs.
public final void convertEjbRefs(final EjbJar ejbJar, final OpenejbJar openejbJar, final OpenejbJarType openejbJarType) {
openejbJar.getProperties().putAll(openejbJarType.getProperties());
final Map<String, EnterpriseBean> ejbs = ejbJar.getEnterpriseBeansByEjbName();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
for (final org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans()) {
final EnterpriseBean ejb = ejbs.get(enterpriseBean.getEjbName());
if (ejb == null) {
// todo warn no such ejb in the ejb-jar.xml
continue;
}
final Map<String, EjbRef> ejbRefs = ejb.getEjbRefMap();
final EjbDeployment deployment = deployments.get(enterpriseBean.getEjbName());
if (deployment == null) {
// todo warn no such ejb in the ejb-jar.xml
continue;
}
// Add WS Security
if (enterpriseBean instanceof SessionBeanType) {
final SessionBeanType sessionBean = (SessionBeanType) enterpriseBean;
final WebServiceSecurityType webServiceSecurityType = sessionBean.getWebServiceSecurity();
if (webServiceSecurityType != null) {
if (webServiceSecurityType.getRealmName() != null) {
deployment.addProperty("webservice.security.realm", webServiceSecurityType.getRealmName());
}
if (webServiceSecurityType.getSecurityRealmName() != null) {
deployment.addProperty("webservice.security.securityRealm", webServiceSecurityType.getSecurityRealmName());
}
if (webServiceSecurityType.getTransportGuarantee() != null) {
deployment.addProperty("webservice.security.transportGarantee", webServiceSecurityType.getTransportGuarantee().value());
} else {
deployment.addProperty("webservice.security.transportGarantee", "NONE");
}
if (webServiceSecurityType.getAuthMethod() != null) {
deployment.addProperty("webservice.security.authMethod", webServiceSecurityType.getAuthMethod().value());
} else {
deployment.addProperty("webservice.security.authMethod", "NONE");
}
deployment.getProperties().putAll(webServiceSecurityType.getProperties());
}
if (sessionBean.getWebServiceAddress() != null) {
deployment.getProperties().put("openejb.webservice.deployment.address", sessionBean.getWebServiceAddress());
}
}
deployment.getProperties().putAll(enterpriseBean.getProperties());
for (final String name : enterpriseBean.getLocalJndiName()) {
deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "LocalHome"));
}
for (final String name : enterpriseBean.getJndiName()) {
deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "RemoteHome"));
}
for (final Jndi jndi : enterpriseBean.getJndi()) {
deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(jndi.getName(), jndi.getInterface()));
}
final Set<String> ejbLinks = new TreeSet<>();
for (final EjbLink ejbLink : deployment.getEjbLink()) {
ejbLinks.add(ejbLink.getEjbRefName());
}
for (final EjbRefType refType : enterpriseBean.getEjbRef()) {
final String refName = refType.getRefName();
if (ejbLinks.contains(refName)) {
// don't overwrite refs that have been already set
continue;
}
final String nsCorbaloc = refType.getNsCorbaloc();
if (nsCorbaloc != null) {
final EjbRef ref = ejbRefs.get(refName);
if (ref != null) {
ref.setMappedName("jndi:" + nsCorbaloc);
}
} else if (refType.getEjbLink() != null) {
final EjbRef ref = ejbRefs.get(refName);
if (ref != null) {
ref.setEjbLink(refType.getEjbLink());
}
} else {
final PatternType pattern = refType.getPattern();
addEjbLink(deployment, refName, pattern);
}
}
for (final EjbLocalRefType refType : enterpriseBean.getEjbLocalRef()) {
final String refName = refType.getRefName();
if (ejbLinks.contains(refName)) {
// don't overwrite refs that have been already set
continue;
}
if (refType.getEjbLink() != null) {
final EjbRef ref = ejbRefs.get(refName);
if (ref != null) {
ref.setEjbLink(refType.getEjbLink());
}
} else {
final PatternType pattern = refType.getPattern();
addEjbLink(deployment, refName, pattern);
}
}
}
}
use of org.apache.openejb.jee.oejb3.EjbLink in project tomee by apache.
the class OpenEjb2Conversion method addEjbLink.
private void addEjbLink(final EjbDeployment deployment, final String refName, final PatternType pattern) {
String module = pattern.getModule();
if (module == null) {
module = pattern.getArtifactId();
}
final String ejbName = pattern.getName();
final String deploymentId = module + "/" + ejbName;
final EjbLink ejbLink = new EjbLink(refName, deploymentId);
deployment.getEjbLink().add(ejbLink);
}
use of org.apache.openejb.jee.oejb3.EjbLink 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<>();
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<>();
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());
}
}
}
}
}
}
}
Aggregations