use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class CmpFields method runIndividualCmpFieldTest.
/**
* run an individual verifier test of a declated cmp field of the class
*
* @param entity the descriptor for the entity bean containing the cmp-field
* @param f the descriptor for the declared cmp field
* @param c the class owning the cmp field
* @parma r the result object to use to put the test results in
*
* @return true if the test passed
*/
protected boolean runIndividualCmpFieldTest(Descriptor entity, Descriptor persistentField, Class c, Result result) {
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
String cmpFieldName = persistentField.getName();
String getMethodName = "get" + Character.toUpperCase(cmpFieldName.charAt(0)) + cmpFieldName.substring(1);
Method getMethod = getMethod(c, getMethodName, null);
Class fieldType;
if (getMethod != null) {
boolean run = false;
// get the return type for the setMethod
fieldType = getMethod.getReturnType();
EjbBundleDescriptorImpl bundle = ((EjbDescriptor) entity).getEjbBundleDescriptor();
if (!RmiIIOPUtils.isValidRmiIDLPrimitiveType(fieldType) && !EjbUtils.isValidSerializableType(fieldType)) {
// it must be a reference to a bean's home or local interface
if (!isValidInterface(fieldType, bundle.getEjbs(), MethodDescriptor.EJB_REMOTE, result)) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error : Invalid type assigned for container managed field [ {0} ] in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), entity.getName() }));
return false;
}
if (!isValidInterface(fieldType, bundle.getEjbs(), MethodDescriptor.EJB_LOCAL, result)) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error : Invalid type assigned for container managed field [ {0} ] in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), entity.getName() }));
return false;
}
}
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned for container managed field [ {0} ] in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), entity.getName() }));
run = true;
return run;
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.isAccessorDeclared.failed2", "Error : Cannot find accessor [ {0} ] method for [ {1} ] field ", new Object[] { getMethodName, persistentField.getName() }));
}
return false;
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class MessageDrivenHandler method setMessageListenerInterface.
private HandlerProcessingResult setMessageListenerInterface(MessageDriven mdAn, EjbMessageBeanDescriptor msgEjbDesc, Class ejbClass, AnnotationInfo ainfo) throws AnnotationProcessorException {
String intfName = null;
if (mdAn.messageListenerInterface() != Object.class) {
intfName = mdAn.messageListenerInterface().getName();
} else {
for (Class next : ejbClass.getInterfaces()) {
if (!excludedFromImplementsClause(next)) {
if (intfName == null) {
intfName = next.getName();
} else {
EjbBundleDescriptorImpl currentBundle = (EjbBundleDescriptorImpl) ((EjbBundleContext) ainfo.getProcessingContext().getHandler()).getDescriptor();
log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.ambiguousimplementsclausemdb", "Implements clause for 3.x message driven bean class {0} in {1} declares more than one potential message-listener interface. In this case, the @MessageDriven.messageListenerInterface() attribute must be used to specify the message listener interface.", new Object[] { ejbClass, currentBundle.getModuleDescriptor().getArchiveUri() }));
return getDefaultFailedResult();
}
}
}
}
// so intfName after this set, will never be null
if (intfName == null) {
intfName = msgEjbDesc.getMessageListenerType();
}
msgEjbDesc.setMessageListenerType(intfName);
return getDefaultProcessedResult();
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class EjbDeployer method generateArtifacts.
/**
* Use this method to generate any ejb-related artifacts for the module
*/
@Override
protected void generateArtifacts(DeploymentContext dc) throws DeploymentException {
OpsParams params = dc.getCommandParameters(OpsParams.class);
if (!(params.origin.isDeploy() && isDas())) {
// Generate artifacts only when being deployed on DAS
return;
}
EjbBundleDescriptorImpl bundle = dc.getModuleMetaData(EjbBundleDescriptorImpl.class);
DeployCommandParameters dcp = dc.getCommandParameters(DeployCommandParameters.class);
boolean generateRmicStubs = dcp.generatermistubs;
dc.addTransientAppMetaData(CMPDeployer.MODULE_CLASSPATH, getModuleClassPath(dc));
if (generateRmicStubs) {
StaticRmiStubGenerator staticStubGenerator = new StaticRmiStubGenerator(habitat);
try {
staticStubGenerator.ejbc(dc);
} catch (Exception e) {
throw new DeploymentException("Static RMI-IIOP Stub Generation exception for " + dc.getSourceDir(), e);
}
}
if (bundle == null || !bundle.containsCMPEntity()) {
// bundle WAS null in a war file where we do not support CMPs
return;
}
initCMPDeployer();
if (cmpDeployer == null) {
throw new DeploymentException("No CMP Deployer is available to deploy this module");
}
cmpDeployer.deploy(dc);
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class SafeProperties method initializeHome.
/**
* Called from the ContainerFactory during initialization.
*/
protected void initializeHome() throws Exception {
if (isWebServiceEndpoint) {
EjbBundleDescriptorImpl bundle = ejbDescriptor.getEjbBundleDescriptor();
WebServicesDescriptor webServices = bundle.getWebServices();
Collection myEndpoints = webServices.getEndpointsImplementedBy(ejbDescriptor);
// An ejb can only be exposed through 1 web service endpoint
Iterator iter = myEndpoints.iterator();
webServiceEndpoint = (com.sun.enterprise.deployment.WebServiceEndpoint) iter.next();
Class serviceEndpointIntfClass = loader.loadClass(webServiceEndpoint.getServiceEndpointInterface());
if (serviceEndpointIntfClass == null || !serviceEndpointIntfClass.isInterface()) {
ServiceInterfaceGenerator generator = new ServiceInterfaceGenerator(loader, ejbClass);
serviceEndpointIntfClass = EJBUtils.generateSEI(generator, generator.getGeneratedClass(), loader, this.ejbClass);
if (serviceEndpointIntfClass == null) {
throw new RuntimeException(localStrings.getLocalString("ejb.error_generating_sei", "Error in generating service endpoint interface class for EJB class {0}", this.ejbClass));
}
}
WebServiceInvocationHandler invocationHandler = new WebServiceInvocationHandler(ejbClass, webServiceEndpoint, serviceEndpointIntfClass, ejbContainerUtilImpl, webServiceInvocationInfoMap);
invocationHandler.setContainer(this);
Object servant = Proxy.newProxyInstance(loader, new Class[] { serviceEndpointIntfClass }, invocationHandler);
// starting in 2.0, there is no more generated Ties
final Class<?> tieClass = getTieClass();
// Create a facade for container services to be used by web services runtime.
EjbEndpointFacade endpointFacade = new EjbEndpointFacadeImpl(this, ejbContainerUtilImpl);
wsejbEndpointRegistry = Globals.getDefaultBaseServiceLocator().getService(WSEjbEndpointRegistry.class);
if (wsejbEndpointRegistry == null) {
throw new DeploymentException(localStrings.getLocalString("ejb.no_webservices_module", "EJB-based Webservice endpoint is detected" + " but there is no webservices module installed to handle it"));
}
wsejbEndpointRegistry.registerEndpoint(webServiceEndpoint, endpointFacade, servant, tieClass);
}
Map<String, Object> intfsForPortableJndi = new HashMap<>();
// Root of portable global JNDI name for this bean
String javaGlobalName = getJavaGlobalJndiNamePrefix();
if (isRemote) {
boolean disableNonPortableJndiName = false;
Boolean disableInDD = ejbDescriptor.getEjbBundleDescriptor().getDisableNonportableJndiNames();
if (disableInDD != null) {
// explicitly set in glassfish-ejb-jar.xml
disableNonPortableJndiName = disableInDD;
} else {
String disableInServer = ejbContainerUtilImpl.getEjbContainer().getPropertyValue(RuntimeTagNames.DISABLE_NONPORTABLE_JNDI_NAMES);
disableNonPortableJndiName = Boolean.parseBoolean(disableInServer);
}
String glassfishSpecificJndiName = null;
if (!disableNonPortableJndiName) {
// This is either the default glassfish-specific (non-portable)
// global JNDI name or the one specified via mappedName(), sun-ejb-jar.xml,
// etc.
glassfishSpecificJndiName = ejbDescriptor.getJndiName();
// clashes.
if ((glassfishSpecificJndiName != null) && (glassfishSpecificJndiName.equals("") || glassfishSpecificJndiName.equals(javaGlobalName))) {
glassfishSpecificJndiName = null;
}
}
if (hasRemoteHomeView) {
this.ejbHomeImpl = instantiateEJBHomeImpl();
this.ejbHome = ejbHomeImpl.getEJBHome();
// Since some containers might create multiple EJBObjects for
// the same ejb, make sure we use the same Proxy class to
// instantiate all the proxy instances.
ejbObjectProxyClass = Proxy.getProxyClass(loader, remoteIntf);
ejbObjectProxyCtor = ejbObjectProxyClass.getConstructor(InvocationHandler.class);
//
// Make sure all Home/Remote interfaces conform to RMI-IIOP
// rules. Checking for conformance here keeps the exposed
// deployment/startup error behavior consistent since when
// rmic is used during codegen it makes equivalent checks and
// treats any validation problems as fatal errors.
//
// These same checks will be made when setTarget is called
// in POARemoteReferenceFactory.preinvoke, but that happens
// only when the actual invocation is made, so it's better to
// know at container initialization time if there is a problem.
//
getProtocolManager().validateTargetObjectInterfaces(this.ejbHome);
// Unlike the Home, each of the concrete containers are
// responsible for creating the EJBObjects, so just create
// a dummy EJBObjectImpl for validation purposes.
EJBObjectImpl dummyEJBObjectImpl = instantiateEJBObjectImpl();
EJBObject dummyEJBObject = (EJBObject) dummyEJBObjectImpl.getEJBObject();
getProtocolManager().validateTargetObjectInterfaces(dummyEJBObject);
// Remotereference factory needs instances of
// Home and Remote to get repository Ids since it doesn't have
// stubs and ties. This must be done before any Home or Remote
// references are created.
remoteHomeRefFactory.setRepositoryIds(homeIntf, remoteIntf);
// get a remote ref for the EJBHome
ejbHomeStub = (EJBHome) remoteHomeRefFactory.createHomeReference(homeInstanceKey);
// Add 2.x Home for later portable JNDI name processing.
intfsForPortableJndi.put(ejbDescriptor.getHomeClassName(), ejbHomeStub);
// this was the original use of the jndi name.
if (glassfishSpecificJndiName != null) {
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(glassfishSpecificJndiName, ejbHomeStub);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
}
if (hasRemoteBusinessView) {
this.ejbRemoteBusinessHomeImpl = instantiateEJBRemoteBusinessHomeImpl();
this.ejbRemoteBusinessHome = ejbRemoteBusinessHomeImpl.getEJBHome();
// RMI-IIOP validation
getProtocolManager().validateTargetObjectInterfaces(this.ejbRemoteBusinessHome);
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
next.proxyClass = Proxy.getProxyClass(loader, next.generatedRemoteIntf);
next.proxyCtor = next.proxyClass.getConstructor(InvocationHandler.class);
// Remotereference factory needs instances of
// Home and Remote to get repository Ids since it
// doesn't have stubs and ties. This must be done before
// any Home or Remote references are created.
next.referenceFactory.setRepositoryIds(remoteBusinessHomeIntf, next.generatedRemoteIntf);
// selected, so just do it the first time through the loop.
if (ejbRemoteBusinessHomeStub == null) {
ejbRemoteBusinessHomeStub = (EJBHome) next.referenceFactory.createHomeReference(homeInstanceKey);
}
}
EJBObjectImpl dummyEJBObjectImpl = instantiateRemoteBusinessObjectImpl();
// Internal jndi name under which remote business home is registered for
// glassfish-specific remote business JNDI names
String remoteBusinessHomeJndiName = null;
if (glassfishSpecificJndiName != null) {
remoteBusinessHomeJndiName = EJBUtils.getRemote30HomeJndiName(glassfishSpecificJndiName);
}
// Convenience location for common case of 3.0 session bean with only
// 1 remote business interface and no adapted remote home. Allows a
// stand-alone client to access 3.0 business interface by using simple
// jndi name. Each remote business interface is also always available
// at <jndi-name>#<business_interface_name>. This is needed for the
// case where the bean has an adapted remote home and/or multiple business
// interfaces.
String simpleRemoteBusinessJndiName = null;
if (glassfishSpecificJndiName != null && !hasRemoteHomeView && remoteBusinessIntfInfo.size() == 1) {
simpleRemoteBusinessJndiName = glassfishSpecificJndiName;
}
// We need a separate name for the internal generated home object to
// support the portable global JNDI names for business interfaces.
// There won't necessarily be a glassfish-specific name specified so
// it's cleaner to just always use a separate ones.
String internalHomeJndiNameForPortableRemoteNames = EJBUtils.getRemote30HomeJndiName(javaGlobalName);
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
java.rmi.Remote dummyEJBObject = dummyEJBObjectImpl.getEJBObject(next.generatedRemoteIntf.getName());
getProtocolManager().validateTargetObjectInterfaces(dummyEJBObject);
if (glassfishSpecificJndiName != null) {
next.jndiName = EJBUtils.getRemoteEjbJndiName(true, next.remoteBusinessIntf.getName(), glassfishSpecificJndiName);
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(), new StringRefAddr("url", remoteBusinessHomeJndiName), "com.sun.ejb.containers.RemoteBusinessObjectFactory", null);
// Glassfish-specific JNDI name for fully-qualified 3.0 Remote business interface.
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(next.jndiName, remoteBusRef);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
if (simpleRemoteBusinessJndiName != null) {
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(), new StringRefAddr("url", remoteBusinessHomeJndiName), "com.sun.ejb.containers.RemoteBusinessObjectFactory", null);
// Glassfish-specific JNDI name for simple 3.0 Remote business interface lookup.
// Applicable when the bean exposes only a single Remote 3.x client view.
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(simpleRemoteBusinessJndiName, remoteBusRef);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(), new StringRefAddr("url", internalHomeJndiNameForPortableRemoteNames), "com.sun.ejb.containers.RemoteBusinessObjectFactory", null);
// Always register portable JNDI name for each remote business view
intfsForPortableJndi.put(next.remoteBusinessIntf.getName(), remoteBusRef);
}
if (remoteBusinessHomeJndiName != null) {
// Glassfish-specific JNDI name for internal generated
// home object used by container
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(remoteBusinessHomeJndiName, ejbRemoteBusinessHomeStub);
jndiInfo.setInternal(true);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
// Always registeer internal name for home in support of portable global
// remote business JNDI names.
JndiInfo jndiInfo = JndiInfo.newPortableRemote(internalHomeJndiNameForPortableRemoteNames, ejbRemoteBusinessHomeStub);
jndiInfo.setInternal(true);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
// lookup logic that depends on ejbDescriptor.getJndiName() will work.
if (glassfishSpecificJndiName == null) {
ejbDescriptor.setJndiName(javaGlobalName);
}
}
}
if (isLocal) {
if (hasLocalHomeView) {
this.ejbLocalHomeImpl = instantiateEJBLocalHomeImpl();
this.ejbLocalHome = ejbLocalHomeImpl.getEJBLocalHome();
// Since some containers might create multiple EJBLocalObjects
// for the same ejb, make sure we use the same Proxy class to
// instantiate all the proxy instances.
Class<?> ejbLocalObjectProxyClass = Proxy.getProxyClass(loader, IndirectlySerializable.class, localIntf);
ejbLocalObjectProxyCtor = ejbLocalObjectProxyClass.getConstructor(InvocationHandler.class);
// Portable JNDI name for EJB 2.x LocalHome. We don't provide a
// glassfish-specific way of accessing Local EJBs.
//
JavaGlobalJndiNamingObjectProxy namingProxy = new JavaGlobalJndiNamingObjectProxy(this, localHomeIntf.getName());
intfsForPortableJndi.put(localHomeIntf.getName(), namingProxy);
}
if (hasLocalBusinessView) {
ejbLocalBusinessHomeImpl = instantiateEJBLocalBusinessHomeImpl();
ejbLocalBusinessHome = (GenericEJBLocalHome) ejbLocalBusinessHomeImpl.getEJBLocalHome();
Class<?>[] proxyInterfaces = new Class[localBusinessIntfs.size() + 1];
proxyInterfaces[0] = IndirectlySerializable.class;
int index = 1;
for (Class<?> next : localBusinessIntfs) {
proxyInterfaces[index] = next;
index++;
}
Class<?> proxyClass = Proxy.getProxyClass(loader, proxyInterfaces);
ejbLocalBusinessObjectProxyCtor = proxyClass.getConstructor(InvocationHandler.class);
for (Class<?> next : localBusinessIntfs) {
// Portable JNDI name for EJB 3.x Local business interface.
// We don't provide a glassfish-specific way of accessing Local EJBs.
JavaGlobalJndiNamingObjectProxy namingProxy = new JavaGlobalJndiNamingObjectProxy(this, next.getName());
intfsForPortableJndi.put(next.getName(), namingProxy);
}
}
if (hasOptionalLocalBusinessView) {
EJBLocalHomeImpl obj = instantiateEJBOptionalLocalBusinessHomeImpl();
ejbOptionalLocalBusinessHomeImpl = obj;
ejbOptionalLocalBusinessHome = (GenericEJBLocalHome) ejbOptionalLocalBusinessHomeImpl.getEJBLocalHome();
Class<?>[] proxyInterfaces = new Class[2];
proxyInterfaces[0] = IndirectlySerializable.class;
String optionalIntfName = EJBUtils.getGeneratedOptionalInterfaceName(ejbClass.getName());
proxyInterfaces[1] = //
ejbGeneratedOptionalLocalBusinessIntfClass = optIntfClassLoader.loadClass(optionalIntfName);
Class<?> proxyClass = Proxy.getProxyClass(loader, proxyInterfaces);
ejbOptionalLocalBusinessObjectProxyCtor = proxyClass.getConstructor(InvocationHandler.class);
// Portable JNDI name for no-interface view.
// We don't provide a glassfish-specific way of accessing the
// no-interface view of a session bean.
//
JavaGlobalJndiNamingObjectProxy namingProxy = new JavaGlobalJndiNamingObjectProxy(this, ejbClass.getName());
intfsForPortableJndi.put(ejbClass.getName(), namingProxy);
}
}
for (Map.Entry<String, Object> entry : intfsForPortableJndi.entrySet()) {
String intf = entry.getKey();
String fullyQualifiedJavaGlobalName = javaGlobalName + "!" + intf;
Object namingProxy = entry.getValue();
boolean local = (namingProxy instanceof JavaGlobalJndiNamingObjectProxy);
if (intfsForPortableJndi.size() == 1) {
JndiInfo jndiInfo = local ? JndiInfo.newPortableLocal(javaGlobalName, namingProxy) : JndiInfo.newPortableRemote(javaGlobalName, namingProxy);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
JndiInfo jndiInfo = local ? JndiInfo.newPortableLocal(fullyQualifiedJavaGlobalName, namingProxy) : JndiInfo.newPortableRemote(fullyQualifiedJavaGlobalName, namingProxy);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
for (Map.Entry<String, JndiInfo> entry : jndiInfoMap.entrySet()) {
JndiInfo jndiInfo = entry.getValue();
try {
jndiInfo.publish(this.namingManager);
if (jndiInfo.internal) {
publishedInternalGlobalJndiNames.add(jndiInfo.name);
} else {
if (jndiInfo.portable) {
publishedPortableGlobalJndiNames.add(jndiInfo.name);
} else {
publishedNonPortableGlobalJndiNames.add(jndiInfo.name);
}
}
} catch (Exception e) {
throw new RuntimeException(localStrings.getLocalString("ejb.error_binding_jndi_name", "Error while binding JNDI name {0} for EJB {1}", jndiInfo.name, this.ejbDescriptor.getName()), e);
}
}
if (!publishedPortableGlobalJndiNames.isEmpty()) {
_logger.log(Level.INFO, PORTABLE_JNDI_NAMES, new Object[] { this.ejbDescriptor.getName(), publishedPortableGlobalJndiNames });
}
if (!publishedNonPortableGlobalJndiNames.isEmpty()) {
_logger.log(Level.INFO, GLASSFISH_SPECIFIC_JNDI_NAMES, new Object[] { this.ejbDescriptor.getName(), publishedNonPortableGlobalJndiNames });
}
if (!publishedInternalGlobalJndiNames.isEmpty()) {
_logger.log(Level.FINE, "Internal container JNDI names for EJB {0}: {1}", new Object[] { this.ejbDescriptor.getName(), publishedInternalGlobalJndiNames });
}
// set EJBMetaData
setEJBMetaData();
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class SafeProperties method getJavaGlobalJndiNamePrefix.
protected String getJavaGlobalJndiNamePrefix() {
String appName = null;
Application app = ejbDescriptor.getApplication();
if (!app.isVirtual()) {
appName = ejbDescriptor.getApplication().getAppName();
}
EjbBundleDescriptorImpl ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
String modName = ejbBundle.getModuleDescriptor().getModuleName();
String ejbName = ejbDescriptor.getName();
StringBuilder javaGlobalPrefix = new StringBuilder("java:global/");
if (appName != null) {
javaGlobalPrefix.append(appName);
javaGlobalPrefix.append("/");
}
javaGlobalPrefix.append(modName);
javaGlobalPrefix.append("/");
javaGlobalPrefix.append(ejbName);
return javaGlobalPrefix.toString();
}
Aggregations