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.openejb.AppContext

            deployedApplications.remove(appInfo.path);
            logger.info("destroyApplication.start", appInfo.path);

            fireBeforeApplicationDestroyed(appInfo);

            final AppContext appContext = containerSystem.getAppContext(appInfo.appId);

            for (Map.Entry<String, Object> value : appContext.getBindings().entrySet()) {
                String path = value.getKey();
                if (path.startsWith("global")) {
                    path = "java:" + path;
                }
                if (!path.startsWith("java:global")) {
                    continue;
                }

                try {
                    containerSystem.getJNDIContext().unbind(path);
                } catch (NamingException ignored) {
                    // no-op
                }
            }
            try {
                containerSystem.getJNDIContext().unbind("java:global");
            } catch (NamingException ignored) {
                // no-op
            }

            EjbResolver globalResolver = new EjbResolver(null, EjbResolver.Scope.GLOBAL);
            for (AppInfo info : deployedApplications.values()) {
                globalResolver.addAll(info.ejbJars);
            }
            SystemInstance.get().setComponent(EjbResolver.class, globalResolver);


            Context globalContext = containerSystem.getJNDIContext();
            UndeployException undeployException = new UndeployException(messages.format("destroyApplication.failed", appInfo.path));

            WebAppBuilder webAppBuilder = SystemInstance.get().getComponent(WebAppBuilder.class);
            if (webAppBuilder != null) {
                try {
                    webAppBuilder.undeployWebApps(appInfo);
                } catch (Exception e) {
                    undeployException.getCauses().add(new Exception("App: " + appInfo.path + ": " + e.getMessage(), e));
                }
            }

            // get all of the ejb deployments
            List<BeanContext> deployments = new ArrayList<BeanContext>();
            for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
                for (EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
                    String deploymentId = beanInfo.ejbDeploymentId;
                    BeanContext beanContext = containerSystem.getBeanContext(deploymentId);
                    if (beanContext == null) {
                        undeployException.getCauses().add(new Exception("deployment not found: " + deploymentId));
                    } else {
                        deployments.add(beanContext);
                    }
                }
            }

            // Just as with startup we need to get things in an
            // order that respects the singleton @DependsOn information
            // Theoreticlly if a Singleton depends on something in its
            // @PostConstruct, it can depend on it in its @PreDestroy.
            // Therefore we want to make sure that if A dependsOn B,
            // that we destroy A first then B so that B will still be
            // usable in the @PreDestroy method of A.

            // Sort them into the original starting order
            deployments = sort(deployments);
            // reverse that to get the stopping order
            Collections.reverse(deployments);

            // stop
            for (BeanContext deployment : deployments) {
                String deploymentID = deployment.getDeploymentID() + "";
                try {
                    Container container = deployment.getContainer();
                    container.stop(deployment);
                } catch (Throwable t) {
                    undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));
                }
            }

            // undeploy
            for (BeanContext bean : deployments) {
                String deploymentID = bean.getDeploymentID() + "";
                try {
                    Container container = bean.getContainer();
                    container.undeploy(bean);
                    bean.setContainer(null);
                } catch (Throwable t) {
                    undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));
                } finally {
                    bean.setDestroyed(true);
                }
            }

            // get the client ids
            List<String> clientIds = new ArrayList<String>();
            for (ClientInfo clientInfo : appInfo.clients) {
                clientIds.add(clientInfo.moduleId);
                for (String className : clientInfo.localClients) {
                    clientIds.add(className);
                }
                for (String className : clientInfo.remoteClients) {
                    clientIds.add(className);
                }
            }

            if (appContext != null) for (WebContext webContext : appContext.getWebContexts()) {
                containerSystem.removeWebContext(webContext);
            }

        // Clear out naming for all components first
            for (BeanContext deployment : deployments) {
    View Full Code Here

    Examples of org.apache.openejb.AppContext

        private DeploymentIndex deploymentIndex;

        @Before
        public void setUp() throws SystemException {
            method = Method.class.getMethods()[0];
            beanContext = new BeanContext("aDeploymentId", null, new ModuleContext("", null, "", new AppContext("", SystemInstance.get(), null, null, null, false), null), DeploymentIndexTest.class, null, null, null, null, null, null, null, null, null, null, false);
            deploymentIndex = new DeploymentIndex(new BeanContext[] {beanContext, beanContext});
        }
    View Full Code Here

    Examples of org.apache.openejb.AppContext

            return bindings;
        }

        public static class BeanManagerHelper {
            public Object beanFromClass(final String appName, final String classname) {
                final AppContext appContext = appContext(appName);
                final BeanManager bm = appContext.getBeanManager();
                final Class<?> clazz;
                try {
                    clazz = appContext.getClassLoader().loadClass(classname);
                } catch (ClassNotFoundException e) {
                    throw new OpenEJBRuntimeException(e);
                }
                final Set<Bean<?>> beans = bm.getBeans(clazz);
                return instance(bm, beans, clazz);
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                return appContext(appName).getBeanManager();
            }

            private AppContext appContext(final String appName) {
                final ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
                final AppContext appContext = cs.getAppContext(appName);
                if (appContext == null) {
                    throw new OpenEJBRuntimeException("can't find application " + appName);
                }
                return appContext;
            }
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                final File file = new File(tempDir, name);
                ARCHIVES.put(archive, file);
              archive.as(ZipExporter.class).exportTo(file, true);


                AppContext appContext = container.deploy(name, file);

                HTTPContext httpContext = new HTTPContext("localhost", configuration.getHttpPort());
                httpContext.add(new Servlet("ArquillianServletRunner", "/" + getArchiveNameWithoutExtension(archive)));
                beanManagerInstance.set(appContext.getBeanManager());
                return new ProtocolMetaData().addContext(httpContext);
            } catch (Exception e) {
                e.printStackTrace();
                throw new DeploymentException("Unable to deploy", e);
            }
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                return factory.getApplication();
            }

            if (wrappedApplication == null) {

                final AppContext appContext = webBeansContext.getService(AppContext.class);

                if (appContext != null && !appContext.isCdiEnabled()) {

                    wrappedApplication = factory.getApplication();

                } else {
    View Full Code Here

    Examples of org.apache.openejb.AppContext

        //ee6 specified ejb bindings in module, app, and global contexts

        private void bindJava(BeanContext cdi, Class intrface, Reference ref, Bindings bindings, EnterpriseBeanInfo beanInfo) throws NamingException {
            final ModuleContext module = cdi.getModuleContext();
            final AppContext application = module.getAppContext();

            Context moduleContext = module.getModuleJndiContext();
            Context appContext = application.getAppJndiContext();
            Context globalContext = application.getGlobalJndiContext();

            String appName = application.isStandaloneModule() ? "" : application.getId() + "/";
            String moduleName = cdi.getModuleName() + "/";
            String beanName = cdi.getEjbName();
            if (intrface != null) {
                beanName = beanName + "!" + intrface.getName();
            }
            try {
                String globalName = "global/" + appName + moduleName + beanName;

                if (embeddedEjbContainerApi
                        && !globalName.endsWith(".Comp") && !globalName.endsWith(".Comp!org.apache.openejb.BeanContext$Comp")
                        && !(beanInfo instanceof ManagedBeanInfo && ((ManagedBeanInfo) beanInfo).hidden)) {
                    logger.info(String.format("Jndi(name=\"java:%s\")", globalName));
                }
                globalContext.bind(globalName, ref);
                application.getBindings().put(globalName, ref);

                bind("openejb/global/" + globalName, ref, bindings, beanInfo, intrface);
            } catch (NameAlreadyBoundException e) {
                //one interface in more than one role (e.g. both Local and Remote
                return;
            }

            appContext.bind("app/" + moduleName + beanName, ref);
            application.getBindings().put("app/" + moduleName + beanName, ref);

            moduleContext.bind("module/" + beanName, ref);
            application.getBindings().put("module/" + beanName, ref);
        }
    View Full Code Here

    Examples of org.apache.openejb.AppContext

            appModule.getWebModules().add(webModule);
            appModule.getEjbModules().add(new EjbModule(ejbJar));
            annotationDeployer.deploy(appModule);

            AppInfo appInfo = factory.configureApplication(appModule);
            final AppContext application = assembler.createApplication(appInfo);

            Context ctx = (Context) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{Context.class}, new InvocationHandler() {
                @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    if (args.length == 1 && args[0].equals("SimpleEJBLocalBean")) {
                        return new SimpleEJB();
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                    Assembler assembler = new Assembler();
                    assembler.buildContainerSystem(config.getOpenEjbConfiguration());

                    final AppInfo appInfo = config.configureApplication(appModule);

                    final AppContext appContext = assembler.createApplication(appInfo);

                    try {
                        final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
                        final BeanContext context = containerSystem.getBeanContext(javaClass.getName());

                        ThreadContext callContext = new ThreadContext(context, null, Operation.INJECTION);
                        ThreadContext oldContext = ThreadContext.enter(callContext);
                        try {
                            final InjectionProcessor processor = new InjectionProcessor(testInstance, context.getInjections(), context.getJndiContext());

                            processor.createInstance();

                            try {
                                OWBInjector beanInjector = new OWBInjector(appContext.getWebBeansContext());
                                beanInjector.inject(testInstance);
                            } catch (Throwable t) {
                                // TODO handle this differently
                                // this is temporary till the injector can be rewritten
                            }
                        } finally {
                            ThreadContext.exit(oldContext);
                        }

                        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());

                        System.getProperties().put(OPENEJB_APPLICATION_COMPOSER_CONTEXT, appContext.getGlobalJndiContext());

                        final ThreadContext previous = ThreadContext.enter(new ThreadContext(context, null, Operation.BUSINESS));
                        try {
                            next.evaluate();
                        } finally {
    View Full Code Here

    Examples of org.apache.openejb.AppContext

                        final ConfigurationFactory configurationFactory = new ConfigurationFactory();
                        final AppInfo appInfo = configurationFactory.configureApplication(appModule);
                        appInfo.appId = "bundle_" + bundle.getBundleId();

                        final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
                        final AppContext appContext = assembler.createApplication(appInfo, osgiCl);
                        LOGGER.info("Application deployed: " + appInfo.path);

                        paths.put(bundle, appInfo.path);

                        registrations.put(bundle, new ArrayList<ServiceRegistration>());
    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.