earContext.addGBean(appClientModuleGBeanData);
} catch (GBeanAlreadyExistsException e) {
throw new DeploymentException("Could not add application client module gbean to configuration", e);
}
EARContext appClientDeploymentContext = appClientModule.getEarContext();
// Create a Module ID Builder defaulting to similar settings to use for any children we create
ModuleIDBuilder idBuilder = new ModuleIDBuilder();
idBuilder.setDefaultGroup(appClientModule.getClientEnvironment().getConfigId().getGroupId());
idBuilder.setDefaultVersion(appClientModule.getClientEnvironment().getConfigId().getVersion());
try {
try {
//register the message destinations in the app client ear context.
namingBuilders.initContext(appClient, geronimoAppClient, appClientDeploymentContext.getConfiguration(), earContext.getConfiguration(), appClientModule);
// extract the client Jar file into a standalone packed jar file and add the contents to the output
URI moduleBase = new URI(appClientModule.getTargetPath());
try {
appClientDeploymentContext.addIncludeAsPackedJar(moduleBase, moduleFile);
} catch (IOException e) {
throw new DeploymentException("Unable to copy app client module jar into configuration: " + moduleFile.getName());
}
// add manifest class path entries to the app client context
addManifestClassPath(appClientDeploymentContext, appClientModule.getEarFile(), moduleFile, moduleBase);
// get the classloader
ClassLoader appClientClassLoader = appClientDeploymentContext.getClassLoader();
// pop in all the gbeans declared in the geronimo app client file
if (geronimoAppClient != null) {
serviceBuilder.build(geronimoAppClient, appClientDeploymentContext, appClientDeploymentContext);
//deploy the resource adapters specified in the geronimo-application.xml
for (ConnectorModule connectorModule : appClientModule.getResourceModules()) {
getConnectorModuleBuilder().addGBeans(appClientDeploymentContext, connectorModule, appClientClassLoader, repositories);
}
}
//Holder may be loaded in the "client" module classloader here, whereas
//NamingBuilder.INJECTION_KEY.get(buildingContext) returns a Holder loaded in the j2ee-server classloader.
Object holder;
// add the app client static jndi provider
//TODO track resource ref shared and app managed security
AbstractName jndiContextName = earContext.getNaming().createChildName(appClientDeploymentContext.getModuleName(), "StaticJndiContext", "StaticJndiContext");
GBeanData jndiContextGBeanData = new GBeanData(jndiContextName, StaticJndiContextPlugin.GBEAN_INFO);
try {
Map<NamingBuilder.Key, Object> buildingContext = new HashMap<NamingBuilder.Key, Object>();
buildingContext.put(NamingBuilder.GBEAN_NAME_KEY, jndiContextName);
Configuration localConfiguration = appClientDeploymentContext.getConfiguration();
Configuration remoteConfiguration = earContext.getConfiguration();
if (!appClient.getMetadataComplete()) {
// Create a classfinder and populate it for the naming builder(s). The absence of a
// classFinder in the module will convey whether metadata-complete is set
// (or not)
appClientModule.setClassFinder(createAppClientClassFinder(appClient, appClientModule));
}
namingBuilders.buildNaming(appClient, geronimoAppClient, localConfiguration, remoteConfiguration, appClientModule, buildingContext);
if (!appClient.getMetadataComplete()) {
appClient.setMetadataComplete(true);
module.setOriginalSpecDD(module.getSpecDD().toString());
}
appClientModuleGBeanData.setAttribute("deploymentDescriptor", appClientModule.getOriginalSpecDD());
holder = NamingBuilder.INJECTION_KEY.get(buildingContext);
jndiContextGBeanData.setAttribute("context", NamingBuilder.JNDI_KEY.get(buildingContext));
} catch (DeploymentException e) {
throw e;
} catch (Exception e) {
throw new DeploymentException("Unable to construct jndi context for AppClientModule GBean "+
appClientModule.getName(), e);
}
appClientDeploymentContext.addGBean(jndiContextGBeanData);
// finally add the app client container
AbstractName appClientContainerName = appClientDeploymentContext.getModuleName();
GBeanData appClientContainerGBeanData = new GBeanData(appClientContainerName, AppClientContainer.GBEAN_INFO);
try {
appClientContainerGBeanData.setAttribute("mainClassName", appClientModule.getMainClassName());
appClientContainerGBeanData.setAttribute("appClientModuleName", appClientModuleName);
String callbackHandlerClassName = null;
if (appClient.isSetCallbackHandler()) {
callbackHandlerClassName = appClient.getCallbackHandler().getStringValue().trim();
}
if (geronimoAppClient.isSetCallbackHandler()) {
callbackHandlerClassName = geronimoAppClient.getCallbackHandler().trim();
}
String realmName = null;
if (geronimoAppClient.isSetRealmName()) {
realmName = geronimoAppClient.getRealmName().trim();
}
if (callbackHandlerClassName != null && realmName == null) {
throw new DeploymentException("You must specify a realm name with the callback handler");
}
if (realmName != null) {
appClientContainerGBeanData.setAttribute("realmName", realmName);
appClientContainerGBeanData.setAttribute("callbackHandlerClassName", callbackHandlerClassName);
} else if (geronimoAppClient.isSetDefaultPrincipal()) {
DefaultPrincipal defaultPrincipal = getSecurityBuilder().buildDefaultPrincipal(geronimoAppClient.getDefaultPrincipal());
appClientContainerGBeanData.setAttribute("defaultPrincipal", defaultPrincipal);
}
appClientContainerGBeanData.setReferencePattern("JNDIContext", jndiContextName);
appClientContainerGBeanData.setAttribute("holder", holder);
} catch (Exception e) {
throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
}
appClientDeploymentContext.addGBean(appClientContainerGBeanData);
// get the configuration data
earContext.addAdditionalDeployment(appClientDeploymentContext.getConfigurationData());
} finally {
if (appClientDeploymentContext != null) {
try {
appClientDeploymentContext.close();
} catch (IOException e) {
//nothing we can do
}
}
}
} catch (Throwable e) {
File appClientDir = appClientDeploymentContext.getBaseDir();
cleanupAppClientDir(appClientDir);
if (e instanceof Error) {
throw (Error) e;
} else if (e instanceof DeploymentException) {
throw (DeploymentException) e;