use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class ClearEmptyMappedName method clearEmptyMappedName.
private void clearEmptyMappedName(final JndiConsumer consumer) {
if (consumer == null) {
return;
}
final List<JndiReference> refs = new ArrayList<JndiReference>();
refs.addAll(consumer.getEjbLocalRef());
refs.addAll(consumer.getEjbRef());
refs.addAll(consumer.getEnvEntry());
refs.addAll(consumer.getMessageDestinationRef());
refs.addAll(consumer.getPersistenceContextRef());
refs.addAll(consumer.getPersistenceUnitRef());
refs.addAll(consumer.getResourceEnvRef());
refs.addAll(consumer.getResourceRef());
refs.addAll(consumer.getServiceRef());
for (final JndiReference ref : refs) {
if (ref.getMappedName() != null && ref.getMappedName().length() == 0) {
ref.setMappedName(null);
}
}
}
use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class AutoConfig method deploy.
private void deploy(final EjbModule ejbModule, final AppResources appResources) 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()) {
final EjbDeployment ejbDeployment = deployments.get(bean.getEjbName());
if (ejbDeployment == null) {
throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
}
final Class<? extends ContainerInfo> containerInfoType = ConfigurationFactory.getContainerInfoType(getType(bean));
if (ejbDeployment.getContainerId() == null && !skipMdb(bean)) {
String containerId = getUsableContainer(containerInfoType, bean, appResources);
if (containerId == null) {
containerId = createContainer(containerInfoType, ejbDeployment, bean);
}
ejbDeployment.setContainerId(containerId);
}
// create the container if it doesn't exist
final List<String> containerIds = configFactory.getContainerIds();
containerIds.addAll(appResources.getContainerIds());
if (!containerIds.contains(ejbDeployment.getContainerId()) && !skipMdb(bean)) {
createContainer(containerInfoType, ejbDeployment, bean);
}
// Resource reference
for (final ResourceRef ref : bean.getResourceRef()) {
processResourceRef(ref, ejbDeployment, appResources, ejbModule);
}
// Resource env reference
for (final JndiReference ref : bean.getResourceEnvRef()) {
processResourceEnvRef(ref, ejbDeployment, appResources, ejbModule.getClassLoader());
}
// Message destination reference
for (final MessageDestinationRef ref : bean.getMessageDestinationRef()) {
processResourceEnvRef(ref, ejbDeployment, appResources, ejbModule.getClassLoader());
}
// mdb message destination id
if (autoCreateResources && bean instanceof MessageDrivenBean) {
final MessageDrivenBean mdb = (MessageDrivenBean) bean;
final ResourceLink resourceLink = ejbDeployment.getResourceLink("openejb/destination");
if (resourceLink != null) {
try {
final String destinationId = getResourceEnvId(bean.getEjbName(), resourceLink.getResId(), mdb.getMessageDestinationType(), appResources);
resourceLink.setResId(destinationId);
} catch (final OpenEJBException e) {
// The MDB doesn't need the auto configured "openejb/destination" env entry
ejbDeployment.removeResourceLink("openejb/destination");
}
}
}
}
}
use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class CheckInjectionTargets method validate.
public void validate(final EjbModule ejbModule) {
for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
final List<JndiReference> entries = new ArrayList<JndiReference>();
entries.addAll(bean.getEjbLocalRef());
entries.addAll(bean.getEjbRef());
entries.addAll(bean.getEnvEntry());
entries.addAll(bean.getMessageDestinationRef());
entries.addAll(bean.getPersistenceContextRef());
entries.addAll(bean.getPersistenceUnitRef());
entries.addAll(bean.getResourceEnvRef());
entries.addAll(bean.getResourceRef());
entries.addAll(bean.getServiceRef());
for (final JndiReference reference : entries) {
// check injection target
for (final InjectionTarget target : reference.getInjectionTarget()) {
boolean classPrefix = false;
String name = target.getInjectionTargetName();
if (name.startsWith(target.getInjectionTargetClass() + "/")) {
classPrefix = true;
name = name.substring(target.getInjectionTargetClass().length() + 1);
}
final String shortNameInvalid = name;
if (name.startsWith("set") && name.length() >= 4 && Character.isUpperCase(name.charAt(3))) {
final StringBuilder correctName = new StringBuilder(name);
correctName.delete(0, 3);
correctName.setCharAt(0, Character.toLowerCase(correctName.charAt(0)));
final String shortNameCorrect = correctName.toString();
if (classPrefix) {
correctName.insert(0, target.getInjectionTargetClass() + "/");
}
warn(bean, "injectionTarget.nameContainsSet", target.getInjectionTargetName(), shortNameInvalid, shortNameCorrect, correctName, reference.getName(), reference.getClass().getSimpleName());
target.setInjectionTargetName(correctName.toString());
}
}
}
}
}
use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class SunConversion method deploy.
public AppModule deploy(final AppModule appModule) {
final SunApplication sunApplication = getSunApplication(appModule);
if (sunApplication != null) {
for (final Web web : sunApplication.getWeb()) {
final String webUri = web.getWebUri();
for (final WebModule webModule : appModule.getWebModules()) {
if (webUri.equals(webModule.getModuleId())) {
webModule.setContextRoot(web.getContextRoot());
break;
}
}
}
for (final ClientModule clientModule : appModule.getClientModules()) {
final ApplicationClient applicationClient = clientModule.getApplicationClient();
if (applicationClient == null) {
continue;
}
// map ejb-refs
final Map<String, org.apache.openejb.jee.EjbRef> refMap = applicationClient.getEjbRefMap();
// map ejb-ref jndi name declaration to deploymentId
for (final EjbRef ref : sunApplication.getEjbRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getEjbRefName();
refName = normalize(refName);
org.apache.openejb.jee.EjbRef ejbRef = refMap.get(refName);
// try to match from lookup name
for (final Map.Entry<String, org.apache.openejb.jee.EjbRef> aRef : refMap.entrySet()) {
if (refName.equals(aRef.getValue().getLookupName())) {
ejbRef = aRef.getValue();
break;
}
}
if (ejbRef == null) {
ejbRef = new org.apache.openejb.jee.EjbRef();
ejbRef.setEjbRefName(refName);
refMap.put(refName, ejbRef);
applicationClient.getEjbRef().add(ejbRef);
}
ejbRef.setMappedName(ref.getJndiName());
}
}
// map resource-env-refs and message-destination-refs
final Map<String, JndiReference> resEnvMap = new TreeMap<String, JndiReference>();
resEnvMap.putAll(applicationClient.getResourceEnvRefMap());
resEnvMap.putAll(applicationClient.getMessageDestinationRefMap());
for (final ResourceRef ref : sunApplication.getResourceRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getResRefName();
refName = normalize(refName);
final JndiReference resEnvRef = resEnvMap.get(refName);
if (resEnvRef != null) {
resEnvRef.setMappedName(ref.getJndiName());
}
}
}
for (final ResourceEnvRef ref : sunApplication.getResourceEnvRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getResourceEnvRefName();
refName = normalize(refName);
final JndiReference resEnvRef = resEnvMap.get(refName);
if (resEnvRef != null) {
resEnvRef.setMappedName(ref.getJndiName());
}
}
}
for (final MessageDestinationRef ref : sunApplication.getMessageDestinationRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getMessageDestinationRefName();
refName = normalize(refName);
final JndiReference resEnvRef = resEnvMap.get(refName);
if (resEnvRef != null) {
resEnvRef.setMappedName(ref.getJndiName());
}
}
}
for (final MessageDestination destination : sunApplication.getMessageDestination()) {
if (destination.getJndiName() != null) {
String name = destination.getMessageDestinationName();
name = normalize(name);
final JndiReference ref = resEnvMap.get(name);
if (ref != null) {
ref.setMappedName(destination.getJndiName());
}
}
}
final Map<String, ServiceRef> serviceRefMap = applicationClient.getServiceRefMap();
for (final org.apache.openejb.jee.sun.ServiceRef ref : sunApplication.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);
}
}
}
}
}
for (final EjbModule ejbModule : appModule.getEjbModules()) {
convertModule(ejbModule, appModule.getCmpMappings());
}
for (final ClientModule clientModule : appModule.getClientModules()) {
convertModule(clientModule);
}
for (final WebModule webModule : appModule.getWebModules()) {
convertModule(webModule);
}
return appModule;
}
use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class SunConversion method convertModule.
public void convertModule(final WebModule webModule) {
if (webModule == null) {
return;
}
final WebApp webApp = webModule.getWebApp();
if (webApp == null) {
return;
}
final SunWebApp sunWebApp = getSunWebApp(webModule);
if (sunWebApp == null) {
return;
}
if (sunWebApp.getContextRoot() != null) {
webModule.setContextRoot(sunWebApp.getContextRoot());
}
// map ejb-refs
final Map<String, JndiReference> refMap = new TreeMap<String, JndiReference>();
refMap.putAll(webApp.getEjbRefMap());
refMap.putAll(webApp.getEjbLocalRefMap());
// map ejb-ref jndi name declaration to deploymentId
for (final EjbRef ref : sunWebApp.getEjbRef()) {
if (ref.getJndiName() != null) {
final String refName = ref.getEjbRefName();
JndiReference ejbRef = refMap.get(refName);
if (ejbRef == null) {
ejbRef = new org.apache.openejb.jee.EjbRef();
ejbRef.setName(refName);
refMap.put(refName, ejbRef);
webApp.getEjbRef().add((org.apache.openejb.jee.EjbRef) ejbRef);
}
ejbRef.setMappedName(ref.getJndiName());
}
}
// map resource-env-refs and message-destination-refs
final Map<String, JndiReference> resEnvMap = new TreeMap<String, JndiReference>();
resEnvMap.putAll(webApp.getResourceRefMap());
resEnvMap.putAll(webApp.getResourceEnvRefMap());
resEnvMap.putAll(webApp.getMessageDestinationRefMap());
for (final ResourceRef ref : sunWebApp.getResourceRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getResRefName();
refName = normalize(refName);
final JndiReference resEnvRef = resEnvMap.get(refName);
if (resEnvRef != null) {
resEnvRef.setMappedName(ref.getJndiName());
}
}
}
for (final ResourceEnvRef ref : sunWebApp.getResourceEnvRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getResourceEnvRefName();
refName = normalize(refName);
final JndiReference resEnvRef = resEnvMap.get(refName);
if (resEnvRef != null) {
resEnvRef.setMappedName(ref.getJndiName());
}
}
}
for (final MessageDestinationRef ref : sunWebApp.getMessageDestinationRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getMessageDestinationRefName();
refName = normalize(refName);
final JndiReference resEnvRef = resEnvMap.get(refName);
if (resEnvRef != null) {
resEnvRef.setMappedName(ref.getJndiName());
}
}
}
final Map<String, ServiceRef> serviceRefMap = webApp.getServiceRefMap();
for (final org.apache.openejb.jee.sun.ServiceRef ref : sunWebApp.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);
}
}
}
// map wsdl locations
if (webModule.getWebservices() != null) {
final Map<String, WebserviceDescription> descriptions = webModule.getWebservices().getWebserviceDescriptionMap();
for (final org.apache.openejb.jee.sun.WebserviceDescription sunDescription : sunWebApp.getWebserviceDescription()) {
final WebserviceDescription description = descriptions.get(sunDescription.getWebserviceDescriptionName());
if (description == null) {
continue;
}
final String serviceId = extractSerivceId(sunDescription.getWsdlPublishLocation(), description.getWsdlFile());
if (serviceId != null) {
description.setId(serviceId);
}
}
}
}
Aggregations