use of com.sun.ejb.containers.EjbContainerUtil in project jersey by jersey.
the class EjbComponentProvider method registerEjbInterceptor.
private void registerEjbInterceptor() {
try {
final Object interceptor = new EjbComponentInterceptor(injectionManager);
initialContext = getInitialContext();
final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();
final ApplicationInfo appInfo = getApplicationInfo(ejbUtil);
final List<String> tempLibNames = new LinkedList<>();
for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
final String jarName = moduleInfo.getName();
if (jarName.endsWith(".jar") || jarName.endsWith(".war")) {
final String moduleName = jarName.substring(0, jarName.length() - 4);
tempLibNames.add(moduleName);
final Object bundleDescriptor = moduleInfo.getMetaData(EjbBundleDescriptorImpl.class.getName());
if (bundleDescriptor instanceof EjbBundleDescriptorImpl) {
final Collection<EjbDescriptor> ejbs = ((EjbBundleDescriptorImpl) bundleDescriptor).getEjbs();
for (final EjbDescriptor ejb : ejbs) {
final BaseContainer ejbContainer = EjbContainerUtilImpl.getInstance().getContainer(ejb.getUniqueId());
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
final Method registerInterceptorMethod = BaseContainer.class.getDeclaredMethod("registerSystemInterceptor", java.lang.Object.class);
registerInterceptorMethod.setAccessible(true);
registerInterceptorMethod.invoke(ejbContainer, interceptor);
return null;
}
});
} catch (PrivilegedActionException pae) {
final Throwable cause = pae.getCause();
LOGGER.log(Level.WARNING, LocalizationMessages.EJB_INTERCEPTOR_BINDING_WARNING(ejb.getEjbClassName()), cause);
}
}
}
}
}
libNames.addAll(tempLibNames);
final Object interceptorBinder = initialContext.lookup("java:org.glassfish.ejb.container.interceptor_binding_spi");
// the name
if (interceptorBinder == null) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE());
}
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
Method interceptorBinderMethod = interceptorBinder.getClass().getMethod("registerInterceptor", java.lang.Object.class);
interceptorBinderMethod.invoke(interceptorBinder, interceptor);
EjbComponentProvider.this.ejbInterceptorRegistered = true;
LOGGER.log(Level.CONFIG, LocalizationMessages.EJB_INTERCEPTOR_BOUND());
return null;
}
});
} catch (PrivilegedActionException pae) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_ERROR(), pae.getCause());
}
} catch (NamingException ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE(), ex);
} catch (LinkageError ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_LINKAGE_ERROR(), ex);
}
}
use of com.sun.ejb.containers.EjbContainerUtil in project Payara by payara.
the class PersistentEJBTimerService method deployEJBTimerService.
private static boolean deployEJBTimerService(File root, File appScratchFile, String resourceName, boolean is_upgrade) {
boolean deployed = false;
logger.log(Level.INFO, "Loading EJBTimerService. Please wait.");
File app = null;
try {
app = FileUtils.getManagedFile(TIMER_SERVICE_APP_NAME + ".war", new File(root, "lib/install/applications/"));
} catch (Exception e) {
logger.log(Level.WARNING, "Caught unexpected exception", e);
}
if (app == null || !app.exists()) {
logger.log(Level.WARNING, "Cannot deploy or load persistent EJBTimerService: " + "required WAR file (" + TIMER_SERVICE_APP_NAME + ".war) is not installed");
} else {
DeployCommandParameters params = new DeployCommandParameters(app);
params.name = TIMER_SERVICE_APP_NAME;
try {
EjbContainerUtil _ejbContainerUtil = EjbContainerUtilImpl.getInstance();
// first access of the Timer Service application
if (_ejbContainerUtil.isDas() && appScratchFile.createNewFile() && !is_upgrade) {
params.origin = OpsParams.Origin.deploy;
} else {
params.origin = OpsParams.Origin.load;
}
params.target = _ejbContainerUtil.getServerEnvironment().getInstanceName();
ActionReport report = _ejbContainerUtil.getServices().getService(ActionReport.class, "plain");
Deployment deployment = _ejbContainerUtil.getDeployment();
ExtendedDeploymentContext dc = deployment.getBuilder(logger, params, report).source(app).build();
dc.addTransientAppMetaData(DatabaseConstants.JTA_DATASOURCE_JNDI_NAME_OVERRIDE, resourceName);
Properties appProps = dc.getAppProps();
appProps.setProperty(ServerTags.OBJECT_TYPE, DeploymentProperties.SYSTEM_ALL);
deployment.deploy(dc);
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
logger.log(Level.WARNING, "Cannot deploy or load EJBTimerService: ", report.getFailureCause());
} else {
deployed = true;
}
} catch (Exception e) {
logger.log(Level.WARNING, "Cannot deploy or load EJBTimerService: ", e);
} finally {
if (!deployed && params.origin.isDeploy() && appScratchFile.exists()) {
// Remove marker file if deploy failed
if (!appScratchFile.delete()) {
logger.log(Level.WARNING, "Failed to remove the marker file " + appScratchFile);
}
}
}
}
return deployed;
}
use of com.sun.ejb.containers.EjbContainerUtil in project Payara by payara.
the class SunContainerHelper method getContainer.
/**
* Get a Container helper instance that will be passed unchanged to the
* required methods.
* This is SunContainerHelper specific code.
*
* The info argument is an Object array that consistes of a class to use
* for the class loader and concreteImpl bean class name.
* @see getEJBObject(Object, Object)
* @see getEJBLocalObject(Object, Object)
* @see getEJBLocalObject(Object, Object, EJBObject)
* @see removeByEJBLocalObject(EJBLocalObject, Object)
* @see removeByPK(Object, Object)
* @param info Object with the request information that is application server
* specific.
* @return a Container helper instance as an Object.
*/
public Object getContainer(Object info) {
Object[] params = (Object[]) info;
String appName = (String) params[0];
ServiceLocator habitat = Globals.getDefaultHabitat();
ApplicationRegistry reg = habitat.getService(ApplicationRegistry.class);
ApplicationInfo appInfo = reg.get(appName);
Application app = appInfo.getMetaData(Application.class);
EjbDescriptor desc = app.getEjbByName((String) params[1]);
return habitat.<EjbContainerUtil>getService(EjbContainerUtil.class).getContainer(desc.getUniqueId());
}
use of com.sun.ejb.containers.EjbContainerUtil in project Payara by payara.
the class PersistentEJBTimerService method initEJBTimerService.
static void initEJBTimerService(String target) {
EJBTimerService timerService = null;
EjbContainerUtil _ejbContainerUtil = EjbContainerUtilImpl.getInstance();
EjbTimerService _ejbt = _ejbContainerUtil.getEjbTimerService(target);
String resourceName = getTimerResource(_ejbt);
File root = _ejbContainerUtil.getServerContext().getInstallRoot();
boolean is_upgrade = isUpgrade(resourceName, _ejbt, root);
File rootScratchDir = _ejbContainerUtil.getServerEnvironment().getApplicationStubPath();
File appScratchFile = new File(rootScratchDir, TIMER_SERVICE_APP_NAME);
// Remember the value before the file is created during deploy
boolean removeOldTimers = is_upgrade && !appScratchFile.exists();
boolean available = _ejbContainerUtil.getDeployment().isRegistered(TIMER_SERVICE_APP_NAME);
if (available) {
logger.log(Level.WARNING, "EJBTimerService had been explicitly deployed.");
} else {
if (resourceName != null) {
available = deployEJBTimerService(root, appScratchFile, resourceName, is_upgrade);
} else {
logger.log(Level.WARNING, "Cannot deploy EJBTimerService: Timer resource for target " + target + " is not available");
}
}
if (available) {
try {
timerService = new PersistentEJBTimerService("java:global/" + TIMER_SERVICE_APP_NAME + "/" + TIMER_SERVICE_BEAN_NAME, removeOldTimers);
logger.log(Level.INFO, "ejb.timer_service_started", new Object[] { resourceName });
} catch (Exception ex) {
logger.log(Level.WARNING, "ejb.timer_service_init_error", ex);
}
}
EJBTimerService.setPersistentTimerService(timerService);
}
Aggregations