use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class EjbDeployer method load.
@Override
public EjbApplication load(EjbContainerStarter containerStarter, DeploymentContext dc) {
super.load(containerStarter, dc);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer Loading app from: {0}", dc.getSourceDir());
}
// Register the EjbSecurityComponentInvocationHandler
RegisteredComponentInvocationHandler handler = habitat.getService(RegisteredComponentInvocationHandler.class, "ejbSecurityCIH");
handler.register();
EjbBundleDescriptorImpl ejbBundle = dc.getModuleMetaData(EjbBundleDescriptorImpl.class);
if (ejbBundle == null) {
throw new RuntimeException("Unable to load EJB module. DeploymentContext does not contain any EJB " + " Check archive to ensure correct packaging for " + dc.getSourceDir());
}
ejbBundle.setClassLoader(dc.getClassLoader());
ejbBundle.setupDataStructuresForRuntime();
if (ejbBundle.containsCMPEntity()) {
CMPService cmpService = cmpServiceProvider.get();
if (cmpService == null) {
throw new RuntimeException("CMP Module is not available");
} else if (!cmpService.isReady()) {
throw new RuntimeException("CMP Module is not initialized");
}
}
EjbApplication ejbApp = new EjbApplication(ejbBundle, dc, dc.getClassLoader(), habitat);
try {
compEnvManager.bindToComponentNamespace(ejbBundle);
// If within .war, also bind dependencies declared by web application. There is
// a single naming environment for the entire .war module. Yhis is necessary
// in order for eagerly initialized ejb components to have visibility to all the
// dependencies b/c the web container does not bind to the component namespace until
// its start phase, which comes after the ejb start phase.
Object rootDesc = ejbBundle.getModuleDescriptor().getDescriptor();
if ((rootDesc != ejbBundle) && (rootDesc instanceof WebBundleDescriptor)) {
WebBundleDescriptor webBundle = (WebBundleDescriptor) rootDesc;
compEnvManager.bindToComponentNamespace(webBundle);
}
} catch (Exception e) {
throw new RuntimeException("Exception registering ejb bundle level resources", e);
}
ejbApp.loadContainers(dc);
return ejbApp;
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class EjbDeployer method event.
@Override
public void event(Event event) {
if (event.is(Deployment.APPLICATION_PREPARED) && isDas()) {
ExtendedDeploymentContext context = (ExtendedDeploymentContext) event.hook();
OpsParams opsparams = context.getCommandParameters(OpsParams.class);
DeployCommandParameters dcp = context.getCommandParameters(DeployCommandParameters.class);
ApplicationInfo appInfo = appRegistry.get(opsparams.name());
Application app = appInfo.getMetaData(Application.class);
if (app == null) {
// Not a Java EE application
return;
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer in APPLICATION_PREPARED for origin: " + opsparams.origin + ", target: " + dcp.target + ", name: " + opsparams.name());
}
boolean createTimers = true;
// target could be null for internal apps such as wstx-services or admin console
boolean isDeploymentGroup = dcp.target == null ? false : domain.getDeploymentGroupNamed(dcp.target) != null;
boolean isDeployment = opsparams.origin.isDeploy() || opsparams.origin.isCreateAppRef();
boolean isDirectTarget = env.getInstanceName().equals(dcp.target);
// Create timers on DAS only if this condition is not met
if (!isDeployment || isDirectTarget) {
// Otherwise, timers will be created by the BaseContainer if it's a single instance deploy
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer ... will only set the timeout application flag if any");
}
// But is-timed-app needs to be set in AppInfo in any case
createTimers = false;
}
if (isDeploymentGroup) {
_logger.log(Level.WARNING, "Deployment targets deployment group {0}, it is assumed that timer " + "service configuration is consistent accross all members of the group", dcp.target);
}
String target = dcp.target;
if (createTimers && dcp.isredeploy != null && dcp.isredeploy && DeploymentUtils.isDomainTarget(target)) {
List<String> targets = (List<String>) context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
for (String ref : targets) {
target = ref;
if (domain.getClusterNamed(target) != null || domain.getDeploymentGroupNamed(target) != null) {
// prefer cluster target
break;
}
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer using target for event as " + target);
}
boolean isTimedApp = false;
for (EjbBundleDescriptorImpl ejbBundle : app.getBundleDescriptors(EjbBundleDescriptorImpl.class)) {
if (checkEjbBundleForTimers(ejbBundle, createTimers, target)) {
isTimedApp = true;
}
}
if (isTimedApp && (opsparams.origin.isDeploy() || opsparams.origin.isLoad())) {
// Mark application as a timeout application, so that the clean() call removes the timers.
appInfo.addTransientAppMetaData(IS_TIMEOUT_APP_PROP, Boolean.TRUE);
}
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class CMPDeployerImpl method deploy.
/**
* Generates the concrete impls for all CMPs in the application.
*
* @throws DeploymentException if this exception was thrown while generating concrete impls
*/
public void deploy(DeploymentContext ctx) throws DeploymentException {
// deployment descriptor object representation for the archive
Application application = null;
// deployment descriptor object representation for each module
EjbBundleDescriptorImpl bundle = null;
// ejb name
String beanName = null;
// GeneratorException message if any
StringBuilder generatorExceptionMsg = null;
try {
CMPGenerator gen = new JDOCodeGenerator();
// stubs dir for the current deployment (generated/ejb)
// NOI18N
File stubsDir = ctx.getScratchDir("ejb");
application = ctx.getModuleMetaData(Application.class);
if (_logger.isLoggable(Logger.FINE)) {
// NOI18N
_logger.fine(// NOI18N
"cmpc.processing_cmp", application.getRegistrationName());
}
List<File> cmpFiles = new ArrayList<File>();
final ClassLoader jcl = application.getClassLoader();
bundle = ctx.getModuleMetaData(EjbBundleDescriptorImpl.class);
// This gives the dir where application is exploded
String archiveUri = ctx.getSource().getURI().getSchemeSpecificPart();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Module Dir name is " + archiveUri);
}
// xml dir for the current deployment (generated/xml)
String generatedXmlsPath = ctx.getScratchDir("xml").getCanonicalPath();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Generated XML Dir name is " + generatedXmlsPath);
}
try {
long start = System.currentTimeMillis();
gen.init(bundle, ctx, archiveUri, generatedXmlsPath);
Iterator ejbs = bundle.getEjbs().iterator();
while (ejbs.hasNext()) {
EjbDescriptor desc = (EjbDescriptor) ejbs.next();
beanName = desc.getName();
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Ejb Class Name: " + desc.getEjbClassName());
}
if (desc instanceof IASEjbCMPEntityDescriptor) {
// generate concrete CMP class implementation
IASEjbCMPEntityDescriptor entd = (IASEjbCMPEntityDescriptor) desc;
if (_logger.isLoggable(Logger.FINE)) {
_logger.fine(// NOI18N
"[CMPC] Home Object Impl name is " + entd.getLocalHomeImplClassName());
}
// The classloader needs to be set else we fail down the road.
ClassLoader ocl = entd.getClassLoader();
entd.setClassLoader(jcl);
try {
gen.generate(entd, stubsDir, stubsDir);
} catch (GeneratorException e) {
String msg = e.getMessage();
_logger.warning(msg);
generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
} finally {
entd.setClassLoader(ocl);
}
/* WARNING: IASRI 4683195
* JDO Code failed when there was a relationship involved
* because it depends upon the orginal ejbclasname and hence
* this code is shifted to just before the Remote Impl is
* generated.Remote/Home Impl generation depends upon this
* value
*/
}
}
// end while ejbs.hasNext()
beanName = null;
cmpFiles.addAll(gen.cleanup());
long end = System.currentTimeMillis();
_logger.fine("CMP Generation: " + (end - start) + " msec");
} catch (GeneratorException e) {
String msg = e.getMessage();
_logger.warning(msg);
generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
}
// Used in exception processing
bundle = null;
// Compile the generated classes
if (generatorExceptionMsg == null) {
long start = System.currentTimeMillis();
compileClasses(ctx, cmpFiles, stubsDir);
long end = System.currentTimeMillis();
_logger.fine("Java Compilation: " + (end - start) + " msec");
// Do Java2DB if needed
start = System.currentTimeMillis();
CMPProcessor processor = new CMPProcessor(ctx);
processor.process();
end = System.currentTimeMillis();
_logger.fine("Java2DB processing: " + (end - start) + " msec");
_logger.fine("cmpc.done_processing_cmp", application.getRegistrationName());
}
} catch (GeneratorException e) {
_logger.warning(e.getMessage());
throw new DeploymentException(e);
} catch (Throwable e) {
String eType = e.getClass().getName();
String appName = application.getRegistrationName();
String exMsg = e.getMessage();
String msg = null;
if (bundle == null) {
// Application or compilation error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_app_error", eType, appName, exMsg);
} else {
String bundleName = bundle.getModuleDescriptor().getArchiveUri();
if (beanName == null) {
// Module processing error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_module_error", new Object[] { eType, appName, bundleName, exMsg });
} else {
// CMP bean generation error
msg = I18NHelper.getMessage(messages, "cmpc.cmp_bean_error", new Object[] { eType, beanName, appName, bundleName, exMsg });
}
}
_logger.log(Logger.SEVERE, msg, e);
throw new DeploymentException(msg);
}
if (generatorExceptionMsg != null) {
// We already logged each separate part.
throw new DeploymentException(generatorExceptionMsg.toString());
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class CMPProcessor method process.
/**
* Create and execute the files.
*/
public void process() {
EjbBundleDescriptorImpl bundle = ctx.getModuleMetaData(EjbBundleDescriptorImpl.class);
ResourceReferenceDescriptor cmpResource = bundle.getCMPResourceReference();
// If this bundle's beans are not created by Java2DB, there is nothing to do.
if (!DeploymentHelper.isJavaToDatabase(cmpResource.getSchemaGeneratorProperties())) {
return;
}
helper = new Java2DBProcessorHelper(ctx);
helper.init();
String resourceName = cmpResource.getJndiName();
// NOI18N
helper.setProcessorType("CMP", bundle.getName());
helper.setJndiName(resourceName, bundle.getName());
// If CLI options are not set, use value from the create-tables-at-deploy
// or drop-tables-at-undeploy elements of the sun-ejb-jar.xml
boolean userCreateTables = cmpResource.isCreateTablesAtDeploy();
boolean createTables = helper.getCreateTables(userCreateTables);
boolean userDropTables = cmpResource.isDropTablesAtUndeploy();
if (logger.isLoggable(logger.FINE)) {
// NOI18N
logger.fine(// NOI18N
"ejb.CMPProcessor.createanddroptables", new Object[] { createTables, userDropTables });
}
if (!createTables && !userDropTables) {
// Nothing to do.
return;
}
helper.setCreateTablesValue(userCreateTables, bundle.getName());
helper.setDropTablesValue(userDropTables, bundle.getName());
constructJdbcFileNames(bundle);
if (logger.isLoggable(logger.FINE)) {
logger.fine("ejb.CMPProcessor.createanddropfilenames", helper.getCreateJdbcFileName(bundle.getName()), helper.getDropJdbcFileName(bundle.getName()));
}
if (createTables) {
// NOI18N
helper.createOrDropTablesInDB(true, "CMP");
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class InterceptorsHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
Interceptors interceptors = (Interceptors) ainfo.getAnnotation();
EjbBundleDescriptorImpl ejbBundle = ((EjbDescriptor) ejbContexts[0].getDescriptor()).getEjbBundleDescriptor();
// Process each of the interceptor classes.
for (Class interceptor : interceptors.value()) {
processInterceptorClass(interceptor, ejbBundle, ainfo);
}
for (EjbContext next : ejbContexts) {
EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();
// Create binding information.
InterceptorBindingDescriptor binding = new InterceptorBindingDescriptor();
binding.setEjbName(ejbDescriptor.getName());
for (Class interceptor : interceptors.value()) {
binding.appendInterceptorClass(interceptor.getName());
}
if (ElementType.METHOD.equals(ainfo.getElementType())) {
Method m = (Method) ainfo.getAnnotatedElement();
MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
binding.setBusinessMethod(md);
} else if (ElementType.CONSTRUCTOR.equals(ainfo.getElementType())) {
Constructor c = (Constructor) ainfo.getAnnotatedElement();
Class cl = c.getDeclaringClass();
Class[] ctorParamTypes = c.getParameterTypes();
String[] parameterClassNames = (new MethodDescriptor()).getParameterClassNamesFor(null, ctorParamTypes);
MethodDescriptor md = new MethodDescriptor(cl.getSimpleName(), null, parameterClassNames, MethodDescriptor.EJB_BEAN);
binding.setBusinessMethod(md);
}
// All binding information processed from annotations should go
// before the binding information processed from the descriptors.
// Since descriptors are processed first, always place the binding
// info at the front. The binding information from the descriptor
// is ordered, but there is no prescribed order in which the
// annotations are processed, so all that matters is that it's
// before the descriptor bindings and that the descriptor binding
// order is preserved.
ejbBundle.prependInterceptorBinding(binding);
}
return getDefaultProcessedResult();
}
Aggregations