Search in sources :

Example 1 with ApplicationInfo

use of org.glassfish.internal.data.ApplicationInfo 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)

Aggregations

BaseContainer (com.sun.ejb.containers.BaseContainer)1 EjbContainerUtil (com.sun.ejb.containers.EjbContainerUtil)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 NamingException (javax.naming.NamingException)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1 ModuleInfo (org.glassfish.internal.data.ModuleInfo)1