use of com.sun.enterprise.config.serverbeans.Applications in project jersey by jersey.
the class EjbComponentProvider method getApplicationInfo.
private ApplicationInfo getApplicationInfo(EjbContainerUtil ejbUtil) throws NamingException {
ApplicationRegistry appRegistry = ejbUtil.getServices().getService(ApplicationRegistry.class);
Applications applications = ejbUtil.getServices().getService(Applications.class);
String appNamePrefix = (String) initialContext.lookup("java:app/AppName");
Set<String> appNames = appRegistry.getAllApplicationNames();
Set<String> disabledApps = new TreeSet<>();
for (String appName : appNames) {
if (appName.startsWith(appNamePrefix)) {
Application appDesc = applications.getApplication(appName);
if (appDesc != null && !ejbUtil.getDeployment().isAppEnabled(appDesc)) {
// skip disabled version of the app
disabledApps.add(appName);
} else {
return ejbUtil.getDeployment().get(appName);
}
}
}
// grab the latest one, there is no way to make
// sure which one the user is actually enabling,
// so use the best case, i.e. upgrade
Iterator<String> it = disabledApps.iterator();
String lastDisabledApp = null;
while (it.hasNext()) {
lastDisabledApp = it.next();
}
if (lastDisabledApp != null) {
return ejbUtil.getDeployment().get(lastDisabledApp);
}
throw new NamingException("Application Information Not Found");
}
use of com.sun.enterprise.config.serverbeans.Applications in project Payara by payara.
the class VirtualServer method addContext.
/**
* Registers the given <tt>Context</tt> with this <tt>VirtualServer</tt>
* at the given context root.
*
* <p>If this <tt>VirtualServer</tt> has already been started, the
* given <tt>context</tt> will be started as well.
* @throws org.glassfish.embeddable.GlassFishException
*/
@Override
public void addContext(Context context, String contextRoot) throws ConfigException, GlassFishException {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.VS_ADDED_CONTEXT);
}
if (!(context instanceof ContextFacade)) {
// embedded context should always be created via ContextFacade
return;
}
if (!contextRoot.startsWith("/")) {
contextRoot = "/" + contextRoot;
}
ExtendedDeploymentContext deploymentContext = null;
try {
if (factory == null)
factory = services.getService(ArchiveFactory.class);
ContextFacade facade = (ContextFacade) context;
File docRoot = facade.getDocRoot();
ClassLoader classLoader = facade.getClassLoader();
ReadableArchive archive = factory.openArchive(docRoot);
if (report == null)
report = new PlainTextActionReporter();
ServerEnvironment env = services.getService(ServerEnvironment.class);
DeployCommandParameters params = new DeployCommandParameters();
params.contextroot = contextRoot;
params.enabled = Boolean.FALSE;
params.origin = OpsParams.Origin.deploy;
params.virtualservers = getName();
params.target = "server";
ExtendedDeploymentContext initialContext = new DeploymentContextImpl(report, archive, params, env);
if (deployment == null)
deployment = services.getService(Deployment.class);
ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
if (archiveHandler == null) {
throw new RuntimeException("Cannot find archive handler for source archive");
}
params.name = archiveHandler.getDefaultApplicationName(archive, initialContext);
Applications apps = domain.getApplications();
ApplicationInfo appInfo = deployment.get(params.name);
ApplicationRef appRef = domain.getApplicationRefInServer(params.target, params.name);
if (appInfo != null && appRef != null) {
if (appRef.getVirtualServers().contains(getName())) {
throw new ConfigException("Context with name " + params.name + " is already registered on virtual server " + getName());
} else {
String virtualServers = appRef.getVirtualServers();
virtualServers = virtualServers + "," + getName();
params.virtualservers = virtualServers;
params.force = Boolean.TRUE;
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Virtual server " + getName() + " added to context " + params.name);
}
return;
}
}
deploymentContext = deployment.getBuilder(_logger, params, report).source(archive).archiveHandler(archiveHandler).build(initialContext);
Properties properties = new Properties();
deploymentContext.getAppProps().putAll(properties);
if (classLoader != null) {
ClassLoader parentCL = clh.createApplicationParentCL(classLoader, deploymentContext);
ClassLoader cl = archiveHandler.getClassLoader(parentCL, deploymentContext);
deploymentContext.setClassLoader(cl);
}
ApplicationConfigInfo savedAppConfig = new ApplicationConfigInfo(apps.getModule(com.sun.enterprise.config.serverbeans.Application.class, params.name));
Properties appProps = deploymentContext.getAppProps();
String appLocation = DeploymentUtils.relativizeWithinDomainIfPossible(deploymentContext.getSource().getURI());
appProps.setProperty(ServerTags.LOCATION, appLocation);
appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
appProps.setProperty(ServerTags.CONTEXT_ROOT, contextRoot);
savedAppConfig.store(appProps);
Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
appInfo = deployment.deploy(deploymentContext);
if (appInfo != null) {
facade.setAppName(appInfo.getName());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.VS_ADDED_CONTEXT, new Object[] { getName(), appInfo.getName() });
}
deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
} else {
if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
throw new ConfigException(report.getMessage());
}
}
// Update web.xml with programmatically added servlets, filters, and listeners
File file = null;
boolean delete = true;
com.sun.enterprise.config.serverbeans.Application appBean = apps.getApplication(params.name);
if (appBean != null) {
file = new File(deploymentContext.getSource().getURI().getPath(), "/WEB-INF/web.xml");
if (file.exists()) {
delete = false;
}
updateWebXml(facade, file);
} else {
_logger.log(Level.SEVERE, LogFacade.APP_NOT_FOUND);
}
ReadableArchive source = appInfo.getSource();
UndeployCommandParameters undeployParams = new UndeployCommandParameters(params.name);
undeployParams.origin = UndeployCommandParameters.Origin.undeploy;
undeployParams.target = "server";
ExtendedDeploymentContext undeploymentContext = deployment.getBuilder(_logger, undeployParams, report).source(source).build();
deployment.undeploy(params.name, undeploymentContext);
params.origin = DeployCommandParameters.Origin.load;
params.enabled = Boolean.TRUE;
archive = factory.openArchive(docRoot);
deploymentContext = deployment.getBuilder(_logger, params, report).source(archive).build();
if (classLoader != null) {
ClassLoader parentCL = clh.createApplicationParentCL(classLoader, deploymentContext);
archiveHandler = deployment.getArchiveHandler(archive);
ClassLoader cl = archiveHandler.getClassLoader(parentCL, deploymentContext);
deploymentContext.setClassLoader(cl);
}
deployment.deploy(deploymentContext);
// Enable the app using the modified web.xml
// We can't use Deployment.enable since it doesn't take DeploymentContext with custom class loader
deployment.updateAppEnabledAttributeInDomainXML(params.name, params.target, true);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.VS_ENABLED_CONTEXT, new Object[] { getName(), params.name() });
}
if (delete) {
if (file != null) {
if (file.exists() && !file.delete()) {
String path = file.toString();
_logger.log(Level.WARNING, LogFacade.UNABLE_TO_DELETE, path);
}
}
}
if (contextRoot.equals("/")) {
contextRoot = "";
}
WebModule wm = (WebModule) findChild(contextRoot);
if (wm != null) {
facade.setUnwrappedContext(wm);
wm.setEmbedded(true);
if (config != null) {
wm.setDefaultWebXml(config.getDefaultWebXml());
}
} else {
throw new ConfigException("Deployed app not found " + contextRoot);
}
if (deploymentContext != null) {
deploymentContext.postDeployClean(true);
}
} catch (Exception ex) {
if (deployment != null && deploymentContext != null) {
deploymentContext.clean();
}
throw new GlassFishException(ex);
}
}
use of com.sun.enterprise.config.serverbeans.Applications in project Payara by payara.
the class ActiveJmsResourceAdapter method getJMSDestination.
/*
* Get JMS destination resource from deployed applications
*/
private JMSDestinationDefinitionDescriptor getJMSDestination(String logicalDestination) {
Domain domain = Globals.get(Domain.class);
Applications applications = domain.getApplications();
for (com.sun.enterprise.config.serverbeans.Application app : applications.getApplications()) {
ApplicationInfo appInfo = appRegistry.get(app.getName());
if (appInfo != null) {
Application application = appInfo.getMetaData(Application.class);
JMSDestinationDefinitionDescriptor destination = getJMSDestination(logicalDestination, application);
if (isValidDestination(destination)) {
return destination;
}
}
}
return null;
}
use of com.sun.enterprise.config.serverbeans.Applications in project Payara by payara.
the class ClusterReaderHelper method getWebModules.
/**
* Returns the web module readers for a set of application refs.
*
* @param _configCtx Current Config context
* @param refs Application ref(s) from cluster or stand alone
* instance
* @param target Name of the cluster or stand alone instance
*
* @return WebModuleReader[] Array of the corresponding web module
* reader(s).
*
* @throws LbReaderException In case of any error(s).
*/
public static WebModuleReader[] getWebModules(Domain domain, ApplicationRegistry appRegistry, List<ApplicationRef> refs, String target) {
List<WebModuleReader> list = new ArrayList<WebModuleReader>();
Set<String> contextRoots = new HashSet<String>();
Iterator<ApplicationRef> refAppsIter = refs.iterator();
HashMap<String, ApplicationRef> refferedApps = new HashMap<String, ApplicationRef>();
while (refAppsIter.hasNext()) {
ApplicationRef appRef = refAppsIter.next();
refferedApps.put(appRef.getRef(), appRef);
}
Applications applications = domain.getApplications();
Set<Application> apps = new HashSet<Application>();
apps.addAll(applications.getApplicationsWithSnifferType("web"));
apps.addAll(applications.getApplicationsWithSnifferType("webservices"));
Iterator<Application> appsIter = apps.iterator();
while (appsIter.hasNext()) {
Application app = appsIter.next();
String appName = app.getName();
if (!refferedApps.containsKey(appName)) {
continue;
}
ApplicationInfo appInfo = appRegistry.get(appName);
if (appInfo == null) {
String msg = LbLogUtil.getStringManager().getString("UnableToGetAppInfo", appName);
LbLogUtil.getLogger().log(Level.WARNING, msg);
continue;
}
com.sun.enterprise.deployment.Application depApp = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
Iterator<BundleDescriptor> bundleDescriptorIter = depApp.getBundleDescriptors().iterator();
while (bundleDescriptorIter.hasNext()) {
BundleDescriptor bundleDescriptor = bundleDescriptorIter.next();
try {
if (bundleDescriptor instanceof WebBundleDescriptor) {
WebModuleReader wmr = new WebModuleReaderImpl(appName, refferedApps.get(appName), app, (WebBundleDescriptor) bundleDescriptor);
if (!contextRoots.contains(wmr.getContextRoot())) {
contextRoots.add(wmr.getContextRoot());
list.add(wmr);
}
} else if (bundleDescriptor instanceof EjbBundleDescriptor) {
EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) bundleDescriptor;
if (!ejbBundleDescriptor.hasWebServices()) {
continue;
}
Iterator<WebServiceEndpoint> wsIter = ejbBundleDescriptor.getWebServices().getEndpoints().iterator();
while (wsIter.hasNext()) {
WebServiceEndpointReaderImpl wsr = new WebServiceEndpointReaderImpl(appName, refferedApps.get(appName), app, wsIter.next());
if (!contextRoots.contains(wsr.getContextRoot())) {
contextRoots.add(wsr.getContextRoot());
list.add(wsr);
}
}
}
} catch (LbReaderException ex) {
String msg = LbLogUtil.getStringManager().getString("UnableToGetContextRoot", appName, ex.getMessage());
LbLogUtil.getLogger().log(Level.WARNING, msg);
if (LbLogUtil.getLogger().isLoggable(Level.FINE)) {
LbLogUtil.getLogger().log(Level.FINE, "Exception when getting context root for application", ex);
}
}
}
}
contextRoots.clear();
// returns the web module reader as array
WebModuleReader[] webModules = new WebModuleReader[list.size()];
return (WebModuleReader[]) list.toArray(webModules);
}
use of com.sun.enterprise.config.serverbeans.Applications in project Payara by payara.
the class DOLUtils method isRAConnectionFactory.
/**
* Returns true if there is a resource connection definition of the type with the application
* @param habitat
* @param type
* @param thisApp
* @return
*/
public static boolean isRAConnectionFactory(ServiceLocator habitat, String type, Application thisApp) {
// adapter in this application
if (isRAConnectionFactory(type, thisApp)) {
return true;
}
// then check if this is a connection factory defined in a standalone
// resource adapter
Applications applications = habitat.getService(Applications.class);
if (applications != null) {
List<com.sun.enterprise.config.serverbeans.Application> raApps = applications.getApplicationsWithSnifferType(com.sun.enterprise.config.serverbeans.ServerTags.CONNECTOR, true);
ApplicationRegistry appRegistry = habitat.getService(ApplicationRegistry.class);
for (com.sun.enterprise.config.serverbeans.Application raApp : raApps) {
ApplicationInfo appInfo = appRegistry.get(raApp.getName());
if (appInfo == null)
continue;
if (isRAConnectionFactory(type, appInfo.getMetaData(Application.class))) {
return true;
}
}
}
return false;
}
Aggregations