Search in sources :

Example 1 with EjbContainerUtil

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);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) NamingException(javax.naming.NamingException) PrivilegedActionException(java.security.PrivilegedActionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BaseContainer(com.sun.ejb.containers.BaseContainer) ModuleInfo(org.glassfish.internal.data.ModuleInfo) NamingException(javax.naming.NamingException) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 2 with EjbContainerUtil

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;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) Deployment(org.glassfish.internal.deployment.Deployment) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Example 3 with EjbContainerUtil

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());
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Example 4 with EjbContainerUtil

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);
}
Also used : EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) EJBTimerService(com.sun.ejb.containers.EJBTimerService) NonPersistentEJBTimerService(com.sun.ejb.containers.NonPersistentEJBTimerService) NonPersistentEJBTimerService(com.sun.ejb.containers.NonPersistentEJBTimerService) EjbTimerService(org.glassfish.ejb.config.EjbTimerService) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Aggregations

EjbContainerUtil (com.sun.ejb.containers.EjbContainerUtil)4 PropertyVetoException (java.beans.PropertyVetoException)2 File (java.io.File)2 CreateException (javax.ejb.CreateException)2 EJBException (javax.ejb.EJBException)2 FinderException (javax.ejb.FinderException)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 BaseContainer (com.sun.ejb.containers.BaseContainer)1 EJBTimerService (com.sun.ejb.containers.EJBTimerService)1 NonPersistentEJBTimerService (com.sun.ejb.containers.NonPersistentEJBTimerService)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 EJBLocalObject (javax.ejb.EJBLocalObject)1 EJBObject (javax.ejb.EJBObject)1 NamingException (javax.naming.NamingException)1 ActionReport (org.glassfish.api.ActionReport)1