Search in sources :

Example 1 with ModuleInfo

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

use of org.glassfish.internal.data.ModuleInfo in project Payara by payara.

the class ConfigProviderResolverImpl method getAppInfo.

ApplicationInfo getAppInfo(ClassLoader loader) {
    ApplicationInfo appInfo = null;
    // fast check against current app
    ComponentInvocation currentInvocation = invocationManager.getCurrentInvocation();
    if (currentInvocation == null) {
        // OK we are not a normal request see if we can find the app name from the
        // app registry via the classloader
        Set<String> allApplicationNames = applicationRegistry.getAllApplicationNames();
        for (String allApplicationName : allApplicationNames) {
            ApplicationInfo testInfo = applicationRegistry.get(allApplicationName);
            if (loader.equals(testInfo.getAppClassLoader())) {
                appInfo = testInfo;
                return appInfo;
            } else {
                // search the modules within the app info to see if they have the classloader
                for (ModuleInfo mi : testInfo.getModuleInfos()) {
                    if (loader.equals(mi.getModuleClassLoader())) {
                        return testInfo;
                    }
                }
            }
        }
    } else {
        String appName = currentInvocation.getAppName();
        appInfo = applicationRegistry.get(appName);
    }
    if (appInfo != null && appInfo.getAppClassLoader().equals(loader)) {
        return appInfo;
    }
    // search the modules
    if (appInfo != null) {
        for (ModuleInfo mInfo : appInfo.getModuleInfos()) {
            if (loader.equals(mInfo.getModuleClassLoader())) {
                return appInfo;
            }
        }
    }
    // fast check fails search the app registry
    for (String name : applicationRegistry.getAllApplicationNames()) {
        ApplicationInfo testInfo = applicationRegistry.get(name);
        if (testInfo.getClassLoaders().contains(loader)) {
            return testInfo;
        }
    }
    return appInfo;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) ModuleInfo(org.glassfish.internal.data.ModuleInfo) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo)

Example 3 with ModuleInfo

use of org.glassfish.internal.data.ModuleInfo in project Payara by payara.

the class AppServRegistry method getWebModule.

/*
     * This function is called once for every endpoint registration.
     * and the WebModule corresponding to that endpoint is stored.
     */
static WebModule getWebModule(WebServiceEndpoint wsep) {
    ApplicationRegistry appRegistry = org.glassfish.internal.api.Globals.getDefaultHabitat().getService(ApplicationRegistry.class);
    String appName = wsep.getBundleDescriptor().getApplication().getAppName();
    ApplicationInfo appInfo = appRegistry.get(appName);
    WebApplication webApp = null;
    if (appInfo != null) {
        Collection<ModuleInfo> moduleInfos = appInfo.getModuleInfos();
        Set<EngineRef> engineRefs = null;
        WebBundleDescriptor requiredWbd = (WebBundleDescriptor) wsep.getBundleDescriptor();
        for (ModuleInfo moduleInfo : moduleInfos) {
            engineRefs = moduleInfo.getEngineRefs();
            for (EngineRef engineRef : engineRefs) {
                if (engineRef.getApplicationContainer() instanceof WebApplication) {
                    webApp = (WebApplication) engineRef.getApplicationContainer();
                    WebBundleDescriptor wbd = webApp.getDescriptor();
                    if (wbd.equals(requiredWbd)) {
                        // WebApp corresponding to wsep is found.
                        break;
                    } else {
                        webApp = null;
                    }
                }
            }
        }
    }
    // get the required WebModule from the webApp.
    if (webApp != null) {
        String requiredModule = ((WebBundleDescriptor) wsep.getBundleDescriptor()).getModuleName();
        Set<WebModule> webModules = webApp.getWebModules();
        for (WebModule wm : webModules) {
            if (wm.getModuleName().equalsIgnoreCase(requiredModule)) {
                return wm;
            }
        }
    }
    return null;
}
Also used : ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) ModuleInfo(org.glassfish.internal.data.ModuleInfo) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) WebModule(com.sun.enterprise.web.WebModule) WebApplication(com.sun.enterprise.web.WebApplication) EngineRef(org.glassfish.internal.data.EngineRef)

Example 4 with ModuleInfo

use of org.glassfish.internal.data.ModuleInfo in project Payara by payara.

the class GetDeploymentConfigurationsCommand method execute.

/**
 * Entry point from the framework into the command execution
 * @param context context for the command.
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    final ApplicationInfo appInfo = appRegistry.get(appname);
    if (appInfo == null) {
        return;
    }
    try {
        if (appInfo.getEngineRefs().size() > 0) {
            // composite archive case, i.e. ear
            for (EngineRef ref : appInfo.getEngineRefs()) {
                Sniffer appSniffer = ref.getContainerInfo().getSniffer();
                addToResultDDList("", appSniffer.getDeploymentConfigurations(appInfo.getSource()), part);
            }
            for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
                for (Sniffer moduleSniffer : moduleInfo.getSniffers()) {
                    ReadableArchive moduleArchive = appInfo.getSource().getSubArchive(moduleInfo.getName());
                    addToResultDDList(moduleInfo.getName(), moduleSniffer.getDeploymentConfigurations(moduleArchive), part);
                }
            }
        } else {
            // standalone module
            for (Sniffer sniffer : appInfo.getSniffers()) {
                addToResultDDList(appname, sniffer.getDeploymentConfigurations(appInfo.getSource()), part);
            }
        }
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ModuleInfo(org.glassfish.internal.data.ModuleInfo) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Sniffer(org.glassfish.api.container.Sniffer) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) EngineRef(org.glassfish.internal.data.EngineRef)

Aggregations

ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)4 ModuleInfo (org.glassfish.internal.data.ModuleInfo)4 EngineRef (org.glassfish.internal.data.EngineRef)2 BaseContainer (com.sun.ejb.containers.BaseContainer)1 EjbContainerUtil (com.sun.ejb.containers.EjbContainerUtil)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 WebApplication (com.sun.enterprise.web.WebApplication)1 WebModule (com.sun.enterprise.web.WebModule)1 IOException (java.io.IOException)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 ActionReport (org.glassfish.api.ActionReport)1 Sniffer (org.glassfish.api.container.Sniffer)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1