Examples of AppContext

  • sisc.AppContext
  • sisc.interpreter.AppContext
  • sun.awt.AppContext
    The AppContext is a table referenced by ThreadGroup which stores application service instances. (If you are not writing an application service, or don't know what one is, please do not use this class.) The AppContext allows applet access to what would otherwise be potentially dangerous services, such as the ability to peek at EventQueues or change the look-and-feel of a Swing application.

    Most application services use a singleton object to provide their services, either as a default (such as getSystemEventQueue or getDefaultToolkit) or as static methods with class data (System). The AppContext works with the former method by extending the concept of "default" to be ThreadGroup-specific. Application services lookup their singleton in the AppContext.

    For example, here we have a Foo service, with its pre-AppContext code:

     public class Foo { private static Foo defaultFoo = new Foo(); public static Foo getDefaultFoo() { return defaultFoo; } ... Foo service methods }

    The problem with the above is that the Foo service is global in scope, so that applets and other untrusted code can execute methods on the single, shared Foo instance. The Foo service therefore either needs to block its use by untrusted code using a SecurityManager test, or restrict its capabilities so that it doesn't matter if untrusted code executes it.

    Here's the Foo class written to use the AppContext:

     public class Foo { public static Foo getDefaultFoo() { Foo foo = (Foo)AppContext.getAppContext().get(Foo.class); if (foo == null) { foo = new Foo(); getAppContext().put(Foo.class, foo); } return foo; } ... Foo service methods }

    Since a separate AppContext can exist for each ThreadGroup, trusted and untrusted code have access to different Foo instances. This allows untrusted code access to "system-wide" services -- the service remains within the AppContext "sandbox". For example, say a malicious applet wants to peek all of the key events on the EventQueue to listen for passwords; if separate EventQueues are used for each ThreadGroup using AppContexts, the only key events that applet will be able to listen to are its own. A more reasonable applet request would be to change the Swing default look-and-feel; with that default stored in an AppContext, the applet's look-and-feel will change without disrupting other applets or potentially the browser itself.

    Because the AppContext is a facility for safely extending application service support to applets, none of its methods may be blocked by a a SecurityManager check in a valid Java implementation. Applets may therefore safely invoke any of its methods without worry of being blocked. Note: If a SecurityManager is installed which derives from sun.awt.AWTSecurityManager, it may override the AWTSecurityManager.getAppContext() method to return the proper AppContext based on the execution context, in the case where the default ThreadGroup-based AppContext indexing would return the main "system" AppContext. For example, in an applet situation, if a system thread calls into an applet, rather than returning the main "system" AppContext (the one corresponding to the system thread), an installed AWTSecurityManager may return the applet's AppContext based on the execution context. @author Thomas Ball @author Fred Ecks


  • Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        CommitterEventHandler commitHandler =
            createCommitterEventHandler(dispatcher, committer);
        commitHandler.init(conf);
        commitHandler.start();

        AppContext mockContext = mock(AppContext.class);
        when(mockContext.isLastAMRetry()).thenReturn(false);
        JobImpl job = createStubbedJob(conf, dispatcher, 2, mockContext);
        JobId jobId = job.getID();
        job.handle(new JobEvent(jobId, JobEventType.JOB_INIT));
        assertJobState(job, JobStateInternal.INITED);
        job.handle(new JobStartEvent(jobId));
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        CommitterEventHandler commitHandler =
            createCommitterEventHandler(dispatcher, committer);
        commitHandler.init(conf);
        commitHandler.start();

        AppContext mockContext = mock(AppContext.class);
        when(mockContext.isLastAMRetry()).thenReturn(true);
        JobImpl job = createRunningStubbedJob(conf, dispatcher, 2, mockContext);
        completeJobTasks(job);
        assertJobState(job, JobStateInternal.COMMITTING);

        syncBarrier.await();
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

      }

      private static CommitterEventHandler createCommitterEventHandler(
          Dispatcher dispatcher, OutputCommitter committer) {
        final SystemClock clock = new SystemClock();
        AppContext appContext = mock(AppContext.class);
        when(appContext.getEventHandler()).thenReturn(
            dispatcher.getEventHandler());
        when(appContext.getClock()).thenReturn(clock);
        RMHeartbeatHandler heartbeatHandler = new RMHeartbeatHandler() {
          @Override
          public long getLastHeartbeatTime() {
            return clock.getTime();
          }
          @Override
          public void runOnNextHeartbeat(Runnable callback) {
            callback.run();
          }
        };
        ApplicationAttemptId id =
          ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
        when(appContext.getApplicationID()).thenReturn(id.getApplicationId());
        when(appContext.getApplicationAttemptId()).thenReturn(id);
        CommitterEventHandler handler =
            new CommitterEventHandler(appContext, committer, heartbeatHandler);
        dispatcher.register(CommitterEventType.class, handler);
        return handler;
      }
    View Full Code Here

    Examples of org.apache.openejb.AppContext

            }
            return null;
        }

        public BeanContext bean(final String app, final String name) {
            AppContext appCtx = app(app);
            if (appCtx == null) {
                return null;
            }
            for (BeanContext ctx : appCtx.getBeanContexts()) {
                if (ctx.getDeploymentID().equals(name)) {
                    return ctx;
                }
            }
            return null;
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                        webApp.moduleId = name;
                    }
                }
            }

            AppContext context = assembler.createApplication(appInfo);
            appContexts.put(name, context);
            moduleIds.put(name, appInfo.path);
            return context;
        }
    View Full Code Here

    Examples of org.apache.openejb.AppContext

            if (a == null) {
                logger.warning("OpenEJB has not been initialized so war will not be scanned for nested modules " + standardContext.getPath());
                return;
            }

            AppContext appContext = null;
            //Look for context info, maybe context is already scanned
            ContextInfo contextInfo = getContextInfo(standardContext);
            final ClassLoader classLoader = standardContext.getLoader().getClassLoader();
            if (contextInfo == null) {
                AppModule appModule = loadApplication(standardContext);
                if (appModule != null) {
                    try {
                        contextInfo = addContextInfo(standardContext.getHostname(), standardContext);
                        AppInfo appInfo = configurationFactory.configureApplication(appModule);
                        contextInfo.appInfo = appInfo;

                        appContext = a.createApplication(contextInfo.appInfo, classLoader);
                        // todo add watched resources to context
                    } catch (Exception e) {
                        undeploy(standardContext, contextInfo);
                        logger.error("Unable to deploy collapsed ear in war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
                        // just to force tomee to start without EE part
                        if (System.getProperty(TOMEE_EAT_EXCEPTION_PROP) == null) {
                            final TomEERuntimeException tre = new TomEERuntimeException(e);
                            DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
                            dem.saveDeploymentException(contextInfo.appInfo, tre);
                            throw tre;
                        }
                        return;
                    }
                }
            }
           
            if (appContext == null) {
              String contextRoot = standardContext.getName();
              if (contextRoot.startsWith("/")) {
                contextRoot = contextRoot.replaceAll("^/+", "");
              }
            }

            contextInfo.standardContext = standardContext;

            WebAppInfo webAppInfo = null;
            // appInfo is null when deployment fails
            if (contextInfo.appInfo != null) {
                for (WebAppInfo w : contextInfo.appInfo.webApps) {
                    if (("/" + w.contextRoot).equals(standardContext.getPath()) || isRootApplication(standardContext)) {
                        webAppInfo = w;
                       
                        if (appContext == null) {
                          appContext = cs.getAppContext(contextInfo.appInfo.appId);
                        }
                       
                        break;
                    }
                }
            }

            if (webAppInfo != null) {
                if (appContext == null) {
                    appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);
                }

                // save jsf stuff
                final Map<String, Set<String>> scannedJsfClasses = new HashMap<String, Set<String>>();
                for (ClassListInfo info : webAppInfo.jsfAnnotatedClasses) {
                    scannedJsfClasses.put(info.name, info.list);
                }
                jsfClasses.put(standardContext.getLoader().getClassLoader(), scannedJsfClasses);

                try {

                    // determine the injections
                    final Set<Injection> injections = new HashSet<Injection>();
                    injections.addAll(appContext.getInjections());
                    injections.addAll(new InjectionBuilder(classLoader).buildInjections(webAppInfo.jndiEnc));

                    // jndi bindings
                    final Map<String, Object> bindings = new HashMap<String, Object>();
                    bindings.putAll(appContext.getBindings());
                    bindings.putAll(getJndiBuilder(classLoader, webAppInfo, injections).buildBindings(JndiEncBuilder.JndiScope.comp));

                    // merge OpenEJB jndi into Tomcat jndi
                    final TomcatJndiBuilder jndiBuilder = new TomcatJndiBuilder(standardContext, webAppInfo, injections);
                    jndiBuilder.mergeJndi();

                    // add WebDeploymentInfo to ContainerSystem
                    final WebContext webContext = new WebContext(appContext);
                    webContext.setClassLoader(classLoader);
                    webContext.setId(webAppInfo.moduleId);
                    webContext.setBindings(bindings);
                    webContext.getInjections().addAll(injections);
                    appContext.getWebContexts().add(webContext);
                    cs.addWebContext(webContext);

                    standardContext.setInstanceManager(new JavaeeInstanceManager(webContext, standardContext));
                    standardContext.getServletContext().setAttribute(InstanceManager.class.getName(), standardContext.getInstanceManager());

                } catch (Exception e) {
                    logger.error("Error merging Java EE JNDI entries in to war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
                }

                JspFactory factory = JspFactory.getDefaultFactory();
                if (factory != null) {
                    JspApplicationContext applicationCtx = factory.getJspApplicationContext(standardContext.getServletContext());
                    WebBeansContext context = appContext.getWebBeansContext();
                    if (context != null && context.getBeanManagerImpl().isInUse()) {
                        // Registering ELResolver with JSP container
                        ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
                        ELResolver resolver = elAdaptor.getOwbELResolver();
                        applicationCtx.addELResolver(resolver);
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                }
            }
        }

        private WebBeansListener getWebBeansContext(ContextInfo contextInfo) {
            final AppContext appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);

            if (appContext == null) return null;

            final WebBeansContext webBeansContext = appContext.getWebBeansContext();

            if (webBeansContext == null) return null;

            return new WebBeansListener(webBeansContext);
        }
    View Full Code Here

    Examples of org.apache.openejb.AppContext



        @Override
        public void initialize(StartupObject startupObject) {
            AppContext appContext = startupObject.getAppContext();

            appContext.setCdiEnabled(hasBeans(startupObject.getAppInfo()));

            //initialize owb context, cf geronimo's OpenWebBeansGBean
            Properties properties = new Properties();
            Map<Class<?>, Object> services = new HashMap<Class<?>, Object>();
            properties.setProperty(OpenWebBeansConfiguration.APPLICATION_IS_JSP, "true");
            properties.setProperty(OpenWebBeansConfiguration.USE_EJB_DISCOVERY, "true");
            //from CDI builder
            properties.setProperty(OpenWebBeansConfiguration.INTERCEPTOR_FORCE_NO_CHECKED_EXCEPTIONS, "false");
            properties.setProperty(SecurityService.class.getName(), ManagedSecurityService.class.getName());
            properties.setProperty(OpenWebBeansConfiguration.CONVERSATION_PERIODIC_DELAY, "1800000");
            properties.setProperty(OpenWebBeansConfiguration.APPLICATION_SUPPORTS_CONVERSATION, "true");
            properties.setProperty(OpenWebBeansConfiguration.IGNORED_INTERFACES, "org.apache.aries.proxy.weaving.WovenProxy");

            services.put(AppContext.class, appContext);
            services.put(TransactionService.class, new OpenEJBTransactionService());
            services.put(ELAdaptor.class,new CustomELAdapter(appContext));
            services.put(ContextsService.class, new CdiAppContextsService(true));
            services.put(ResourceInjectionService.class, new CdiResourceInjectionService());
            services.put(ScannerService.class, new CdiScanner());
            services.put(LoaderService.class, new OptimizedLoaderService());

            optional(services, ConversationService.class, "org.apache.webbeans.jsf.DefaultConversationService");

            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
            ClassLoader cl;
            if (oldClassLoader != ThreadSingletonServiceImpl.class.getClassLoader()) {
                cl = new MultipleClassLoader(oldClassLoader, ThreadSingletonServiceImpl.class.getClassLoader());
            } else {
                cl = oldClassLoader;
            }
            Thread.currentThread().setContextClassLoader(cl);
            WebBeansContext webBeansContext;
            Object old = null;
            try {
                webBeansContext = new WebBeansContext(services, properties);
                appContext.set(WebBeansContext.class, webBeansContext);
                old = contextEntered(webBeansContext);
                setConfiguration(webBeansContext.getOpenWebBeansConfiguration());
                try {
                    webBeansContext.getService(ContainerLifecycle.class).startApplication(startupObject);
                } catch (Exception e) {
    View Full Code Here

    Examples of org.apache.openejb.AppContext

            webBeansContext.getPluginLoader().startUp();

            //Get Plugin
            CdiPlugin cdiPlugin = (CdiPlugin) webBeansContext.getPluginLoader().getEjbPlugin();

            final AppContext appContext = stuff.getAppContext();

            cdiPlugin.setAppContext(appContext);
            appContext.setWebBeansContext(webBeansContext);
            cdiPlugin.startup();

            //Configure EJB Deployments
            cdiPlugin.configureDeployments(stuff.getBeanContexts());
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                File generatedJar = cmpJarBuilder.getJarFile();
                if (generatedJar != null) {
                    classLoader = ClassLoaderUtil.createClassLoader(appInfo.path, new URL []{generatedJar.toURI().toURL()}, classLoader);
                }

                final AppContext appContext = new AppContext(appInfo.appId, SystemInstance.get(), classLoader, globalJndiContext, appJndiContext, appInfo.standaloneModule);
                appContext.getInjections().addAll(injections);
                appContext.getBindings().putAll(globalBindings);
                appContext.getBindings().putAll(appBindings);

                containerSystem.addAppContext(appContext);

                final Context containerSystemContext = containerSystem.getJNDIContext();
               
                if (!SystemInstance.get().hasProperty("openejb.geronimo")) {
                    // Bean Validation
                    // ValidatorFactory needs to be put in the map sent to the entity manager factory
                    // so it has to be constructed before
                    final List<CommonInfoObject> vfs = new ArrayList<CommonInfoObject>();
                    for (ClientInfo clientInfo : appInfo.clients) {
                        vfs.add(clientInfo);
                    }
                    for (ConnectorInfo connectorInfo : appInfo.connectors) {
                        vfs.add(connectorInfo);
                    }
                    for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
                        vfs.add(ejbJarInfo);
                    }
                    for (WebAppInfo webAppInfo : appInfo.webApps) {
                        vfs.add(webAppInfo);
                    }

                    final Map<String, ValidatorFactory> validatorFactories = new HashMap<String, ValidatorFactory>();
                    for (CommonInfoObject info : vfs) {
                        ValidatorFactory factory = null;
                        try {
                            factory = ValidatorBuilder.buildFactory(classLoader, info.validationInfo);
                        } catch (ValidationException ve) {
                            logger.warning("can't build the validation factory for module " + info.uniqueId, ve);
                        }
                        if (factory != null) {
                            validatorFactories.put(info.uniqueId, factory);
                        }
                    }
                    moduleIds.addAll(validatorFactories.keySet());

                    // validators bindings
                    for (Entry<String, ValidatorFactory> validatorFactory : validatorFactories.entrySet()) {
                        String id = validatorFactory.getKey();
                        ValidatorFactory factory = validatorFactory.getValue();
                        try {
                            containerSystemContext.bind(VALIDATOR_FACTORY_NAMING_CONTEXT + id, factory);
                            containerSystemContext.bind(VALIDATOR_NAMING_CONTEXT + id, factory.usingContext().getValidator());
                        } catch (NameAlreadyBoundException e) {
                            throw new OpenEJBException("ValidatorFactory already exists for module " + id, e);
                        } catch (Exception e) {
                            throw new OpenEJBException(e);
                        }
                    }
                }
               
                // JPA - Persistence Units MUST be processed first since they will add ClassFileTransformers
                // to the class loader which must be added before any classes are loaded
                Map<String, String> units = new HashMap<String, String>();
                PersistenceBuilder persistenceBuilder = new PersistenceBuilder(persistenceClassLoaderHandler);
                for (PersistenceUnitInfo info : appInfo.persistenceUnits) {
                    ReloadableEntityManagerFactory factory;
                    try {
                        factory = persistenceBuilder.createEntityManagerFactory(info, classLoader);
                        containerSystem.getJNDIContext().bind(PERSISTENCE_UNIT_NAMING_CONTEXT + info.id, factory);
                        units.put(info.name, PERSISTENCE_UNIT_NAMING_CONTEXT + info.id);
                    } catch (NameAlreadyBoundException e) {
                        throw new OpenEJBException("PersistenceUnit already deployed: " + info.persistenceUnitRootUrl);
                    } catch (Exception e) {
                        throw new OpenEJBException(e);
                    }

                    factory.register();
                }

                // Connectors
                for (ConnectorInfo connector : appInfo.connectors) {
                    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(classLoader);
                    try {
                        // todo add undeployment code for these
                        if (connector.resourceAdapter != null) {
                            createResource(connector.resourceAdapter);
                        }
                        for (ResourceInfo outbound : connector.outbound) {
                            createResource(outbound);
                        }
                        for (MdbContainerInfo inbound : connector.inbound) {
                            createContainer(inbound);
                        }
                        for (ResourceInfo adminObject : connector.adminObject) {
                            createResource(adminObject);
                        }
                    } finally {
                        Thread.currentThread().setContextClassLoader(oldClassLoader);
                    }
                }

                List<BeanContext> allDeployments = new ArrayList<BeanContext>();

                // EJB
                EjbJarBuilder ejbJarBuilder = new EjbJarBuilder(props, appContext);
                for (EjbJarInfo ejbJar : appInfo.ejbJars) {
                    HashMap<String, BeanContext> deployments = ejbJarBuilder.build(ejbJar, injections);

                    JaccPermissionsBuilder jaccPermissionsBuilder = new JaccPermissionsBuilder();
                    PolicyContext policyContext = jaccPermissionsBuilder.build(ejbJar, deployments);
                    jaccPermissionsBuilder.install(policyContext);

                    TransactionPolicyFactory transactionPolicyFactory = createTransactionPolicyFactory(ejbJar, classLoader);
                    for (BeanContext beanContext : deployments.values()) {

                        beanContext.setTransactionPolicyFactory(transactionPolicyFactory);
                    }

                    MethodTransactionBuilder methodTransactionBuilder = new MethodTransactionBuilder();
                    methodTransactionBuilder.build(deployments, ejbJar.methodTransactions);

                    MethodConcurrencyBuilder methodConcurrencyBuilder = new MethodConcurrencyBuilder();
                    methodConcurrencyBuilder.build(deployments, ejbJar.methodConcurrency);

                    for (BeanContext beanContext : deployments.values()) {
                        containerSystem.addDeployment(beanContext);
                    }

                    //bind ejbs into global jndi
                    jndiBuilder.build(ejbJar, deployments);

                    // setup timers/asynchronous methods - must be after transaction attributes are set
                    for (BeanContext beanContext : deployments.values()) {
                        if (beanContext.getComponentType() != BeanType.STATEFUL) {
                            Method ejbTimeout = beanContext.getEjbTimeout();
                            boolean timerServiceRequired = false;
                            if (ejbTimeout != null) {
                                // If user set the tx attribute to RequiresNew change it to Required so a new transaction is not started
                                if (beanContext.getTransactionType(ejbTimeout) == TransactionType.RequiresNew) {
                                    beanContext.setMethodTransactionAttribute(ejbTimeout, TransactionType.Required);
                                }
                                timerServiceRequired = true;
                            }
                            for (Iterator<Map.Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext();) {
                                Map.Entry<Method, MethodContext> entry = it.next();
                                MethodContext methodContext = entry.getValue();
                                if (methodContext.getSchedules().size() > 0) {
                                    timerServiceRequired = true;
                                    Method method = entry.getKey();
                                    //TODO Need ?
                                    if (beanContext.getTransactionType(method) == TransactionType.RequiresNew) {
                                        beanContext.setMethodTransactionAttribute(method, TransactionType.Required);
                                    }
                                }
                            }
                            if (timerServiceRequired) {
                                // Create the timer
                                EjbTimerServiceImpl timerService = new EjbTimerServiceImpl(beanContext);
                                //Load auto-start timers
                                TimerStore timerStore = timerService.getTimerStore();
                                for (Iterator<Map.Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext();) {
                                    Map.Entry<Method, MethodContext> entry = it.next();
                                    MethodContext methodContext = entry.getValue();
                                    for(ScheduleData scheduleData : methodContext.getSchedules()) {
                                        timerStore.createCalendarTimer(timerService, (String) beanContext.getDeploymentID(), null, entry.getKey(), scheduleData.getExpression(), scheduleData.getConfig());
                                    }
                                }
                                beanContext.setEjbTimerService(timerService);
                            } else {
                                beanContext.setEjbTimerService(new NullEjbTimerServiceImpl());
                            }
                        }
                        //set asynchronous methods transaction
                        //TODO ???
                        for (Iterator<Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext();) {
                            Entry<Method, MethodContext> entry = it.next();
                            if (entry.getValue().isAsynchronous() && beanContext.getTransactionType(entry.getKey()) == TransactionType.RequiresNew) {
                                beanContext.setMethodTransactionAttribute(entry.getKey(), TransactionType.Required);
                            }
                        }
                    }
                    // process application exceptions
                    for (ApplicationExceptionInfo exceptionInfo : ejbJar.applicationException) {
                        try {
                            Class exceptionClass = classLoader.loadClass(exceptionInfo.exceptionClass);
                            for (BeanContext beanContext : deployments.values()) {
                                beanContext.addApplicationException(exceptionClass, exceptionInfo.rollback, exceptionInfo.inherited);
                            }
                        } catch (ClassNotFoundException e) {
                            logger.error("createApplication.invalidClass", e, exceptionInfo.exceptionClass, e.getMessage());
                        }
                    }

                    allDeployments.addAll(deployments.values());
                }

                allDeployments = sort(allDeployments);

                appContext.getBeanContexts().addAll(allDeployments);

                new CdiBuilder().build(appInfo, appContext, allDeployments);

                ensureWebBeansContext(appContext);

                appJndiContext.bind("app/BeanManager", appContext.getBeanManager());
                appContext.getBindings().put("app/BeanManager", appContext.getBeanManager());

                // now that everything is configured, deploy to the container
                if (start) {
                    // deploy
                    for (BeanContext deployment : allDeployments) {
                        try {
                            Container container = deployment.getContainer();
                            container.deploy(deployment);
                            if (!((String) deployment.getDeploymentID()).endsWith(".Comp")
                                    && !deployment.isHidden()) {
                                logger.info("createApplication.createdEjb", deployment.getDeploymentID(), deployment.getEjbName(), container.getContainerID());
                            }
                            if (logger.isDebugEnabled()) {
                                for (Map.Entry<Object, Object> entry : deployment.getProperties().entrySet()) {
                                    logger.info("createApplication.createdEjb.property", deployment.getEjbName(), entry.getKey(), entry.getValue());
                                }
                            }
                        } catch (Throwable t) {
                            throw new OpenEJBException("Error deploying '"+deployment.getEjbName()+"'.  Exception: "+t.getClass()+": "+t.getMessage(), t);
                        }
                    }

                    // start
                    for (BeanContext deployment : allDeployments) {
                        try {
                            Container container = deployment.getContainer();
                            container.start(deployment);
                            if (!((String) deployment.getDeploymentID()).endsWith(".Comp")
                                    && !deployment.isHidden()) {
                                logger.info("createApplication.startedEjb", deployment.getDeploymentID(), deployment.getEjbName(), container.getContainerID());
                            }
                        } catch (Throwable t) {
                            throw new OpenEJBException("Error starting '"+deployment.getEjbName()+"'.  Exception: "+t.getClass()+": "+t.getMessage(), t);
                        }
                    }
                }

                // App Client
                for (ClientInfo clientInfo : appInfo.clients) {
                    // determine the injections
                    List<Injection> clientInjections = injectionBuilder.buildInjections(clientInfo.jndiEnc);

                    // build the enc
                    JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc, clientInjections, "Bean", clientInfo.moduleId, null, clientInfo.uniqueId, classLoader);
                    // if there is at least a remote client classes
                    // or if there is no local client classes
                    // then, we can set the client flag
                    if ((clientInfo.remoteClients.size() > 0) || (clientInfo.localClients.size() == 0)) {
                        jndiEncBuilder.setClient(true);

                    }
                    jndiEncBuilder.setUseCrossClassLoaderRef(false);
                    Context context = jndiEncBuilder.build(JndiEncBuilder.JndiScope.comp);

    //                Debug.printContext(context);

                    containerSystemContext.bind("openejb/client/" + clientInfo.moduleId, context);

                    if (clientInfo.path != null) {
                        context.bind("info/path", clientInfo.path);
                    }
                    if (clientInfo.mainClass != null) {
                        context.bind("info/mainClass", clientInfo.mainClass);
                    }
                    if (clientInfo.callbackHandler != null) {
                        context.bind("info/callbackHandler", clientInfo.callbackHandler);
                    }
                    context.bind("info/injections", clientInjections);

                    for (String clientClassName : clientInfo.remoteClients) {
                        containerSystemContext.bind("openejb/client/" + clientClassName, clientInfo.moduleId);
                    }

                    for (String clientClassName : clientInfo.localClients) {
                        containerSystemContext.bind("openejb/client/" + clientClassName, clientInfo.moduleId);
                        logger.getChildLogger("client").info("createApplication.createLocalClient", clientClassName, clientInfo.moduleId);
                    }
                }

                SystemInstance systemInstance = SystemInstance.get();

                // WebApp

                WebAppBuilder webAppBuilder = systemInstance.getComponent(WebAppBuilder.class);
                if (webAppBuilder != null) {
                    webAppBuilder.deployWebApps(appInfo, classLoader);
                }

                if (start) {
                    EjbResolver globalEjbResolver = systemInstance.getComponent(EjbResolver.class);
                    globalEjbResolver.addAll(appInfo.ejbJars);
                }

                // bind all global values on global context
                for (Map.Entry<String, Object> value : appContext.getBindings().entrySet()) {
                    String path = value.getKey();
                    if (!path.startsWith("global") || path.equalsIgnoreCase("global/dummy")) { // dummy bound for each app
                        continue;
                    }

                    // a bit weird but just to be consistent if user doesn't lookup directly the resource
                    Context lastContext = Contexts.createSubcontexts(containerSystemContext, path);
                    try {
                        lastContext.bind(path.substring(path.lastIndexOf("/") + 1, path.length()), value.getValue());
                    } catch (NameAlreadyBoundException nabe) {
                        nabe.printStackTrace();
                    }
                    containerSystemContext.rebind(path, value.getValue());
                }

                // deploy MBeans
                for (String mbean : appInfo.mbeans) {
                    deployMBean(appContext.getBeanManager(), classLoader, mbean, appInfo.jmx, appInfo.appId);
                }
                for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
                    for (String mbean : ejbJarInfo.mbeans) {
                        deployMBean(appContext.getBeanManager(), classLoader, mbean, appInfo.jmx, ejbJarInfo.moduleName);
                    }
                }
                for (ConnectorInfo connectorInfo : appInfo.connectors) {
                    for (String mbean : connectorInfo.mbeans) {
                        deployMBean(appContext.getBeanManager(), classLoader, mbean, appInfo.jmx, appInfo.appId + ".add-lib");
                    }
                }


                logger.info("createApplication.success", appInfo.path);
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.