Package org.jboss.gravia.runtime

Examples of org.jboss.gravia.runtime.ModuleContext


    @Test
    public void testResourceAccess() throws Exception {
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());
        ModuleContext context = module.getModuleContext();
        ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
        HttpService httpService = context.getService(sref);
        String reqspec = "/resource/message.txt";
        try {
            // Verify that the alias is not yet available
            assertNotAvailable(reqspec);

            // Register the test resource and make a call
            httpService.registerResources("/resource", "/res", null);
            Assert.assertEquals("Hello from Resource", performCall(reqspec));

            // Unregister the servlet alias
            httpService.unregister("/resource");

            // Verify that the alias is not available any more
            assertNotAvailable(reqspec);
        } finally {
            context.ungetService(sref);
        }
    }
View Full Code Here


        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module modA = runtime.getModule(getClass().getClassLoader());
        Assert.assertEquals(Module.State.ACTIVE, modA.getState());

        ModuleContext context = modA.getModuleContext();
        ServiceRegistration<String> sreg = context.registerService(String.class, new String("Hello"), null);
        Assert.assertNotNull("Null sreg", sreg);

        String service = context.getService(sreg.getReference());
        Assert.assertEquals("Hello", service);

        modA.stop();
        Assert.assertEquals(Module.State.INSTALLED, modA.getState());
View Full Code Here

    public void testBasicModule() throws Exception {

        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());

        ModuleContext ctxA = module.getModuleContext();
        ServiceReference<ServiceD> srefD = ctxA.getServiceReference(ServiceD.class);
        Assert.assertNotNull("ServiceReference not null", srefD);

        ServiceD srvD = ctxA.getService(srefD);
        Assert.assertEquals("ServiceD#1:ServiceD1#1:null:Hello", srvD.doStuff("Hello"));

        ConfigurationAdmin configAdmin = getConfigurationAdmin(module);
        Configuration config = configAdmin.getConfiguration(ServiceD1.class.getName());
        Assert.assertNotNull("Config not null", config);
View Full Code Here

        Assert.assertEquals("ServiceD#1:ServiceD1#1:bar:Hello", srvD.doStuff("Hello"));
    }

    protected ConfigurationAdmin getConfigurationAdmin(Module module) {
        ModuleContext context = module.getModuleContext();
        return context.getService(context.getServiceReference(ConfigurationAdmin.class));
    }
View Full Code Here

    @Test
    public void testServletAccess() throws Exception {
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());
        ModuleContext context = module.getModuleContext();
        ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
        HttpService httpService = context.getService(sref);
        String reqspec = "/service?test=param&param=Kermit";
        try {
            Map<String, String> headers = Collections.singletonMap("Authorization", "Basic " + Base64Encoder.encode("graviaUser:graviaPass"));

            // Verify that the alias is not yet available
            assertNotAvailable(reqspec, headers);

            HttpContext base = httpService.createDefaultHttpContext();
            String realm = RuntimeType.getRuntimeType() == RuntimeType.KARAF ? "gravia" : "ApplicationRealm";
            HttpContext secureContext = new SecureHttpContext(base, realm, "graviaRole");

            // Register the test servlet and make a call
            httpService.registerServlet("/service", new HttpServiceServlet(module), null, secureContext);
            Assert.assertEquals("Hello: Kermit", performCall(reqspec, headers));

            // Unregister the servlet alias
            httpService.unregister("/service");
            assertNotAvailable(reqspec, headers);

            // Verify that the alias is not available any more
            assertNotAvailable(reqspec, headers);
        } finally {
            context.ungetService(sref);
        }
    }
View Full Code Here

    @Test
    public void testResourceAccess() throws Exception {
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());
        ModuleContext context = module.getModuleContext();
        ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
        HttpService httpService = context.getService(sref);
        String reqspec = "/resource/message.txt";
        try {
            Map<String, String> headers = Collections.singletonMap("Authorization", "Basic " + Base64Encoder.encode("graviaUser:graviaPass"));

            // Verify that the alias is not yet available
            assertNotAvailable(reqspec, headers);

            HttpContext base = httpService.createDefaultHttpContext();
            String realm = RuntimeType.getRuntimeType() == RuntimeType.KARAF ? "gravia" : "ApplicationRealm";
            HttpContext secureContext = new SecureHttpContext(base, realm, "graviaRole");

            // Register the test resource and make a call
            httpService.registerResources("/resource", "/res", secureContext);
            Assert.assertEquals("Hello from Resource", performCall(reqspec, headers));

            // Unregister the servlet alias
            httpService.unregister("/resource");

            // Verify that the alias is not available any more
            assertNotAvailable(reqspec, headers);
        } finally {
            context.ungetService(sref);
        }
    }
View Full Code Here

    public void testServiceAvailability() throws Exception {

        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module modA = runtime.getModule(getClass().getClassLoader());

        ModuleContext ctxA = modA.getModuleContext();
        ServiceReference<ServiceA> srefA = ctxA.getServiceReference(ServiceA.class);
        Assert.assertNotNull("ServiceReference not null", srefA);

        ServiceA srvA = ctxA.getService(srefA);
        Assert.assertEquals("ServiceA#1:ServiceA1#1:Hello", srvA.doStuff("Hello"));

        assertDisableComponent(ctxA, srvA);
    }
View Full Code Here

            }
        }
    }

    private static ConfigurationAdmin getConfigurationAdmin() {
        ModuleContext syscontext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        ServiceReference<ConfigurationAdmin> sref = syscontext.getServiceReference(ConfigurationAdmin.class);
        return sref != null ? syscontext.getService(sref) : null;
    }
View Full Code Here

    public void start(StartContext startContext) throws StartException {
        ModelController modelController = injectedController.getValue();
        modelControllerClient = modelController.createClient(Executors.newCachedThreadPool());
        serverDeploymentManager = ServerDeploymentManager.Factory.create(modelControllerClient);

        ModuleContext syscontext = injectedModuleContext.getValue();
        registration = syscontext.registerService(ResourceInstaller.class, this, null);
    }
View Full Code Here

    @Override
    public void start(final StartContext startContext) throws StartException {
        LOGGER.info("Activating Gravia Subsystem");

        Runtime runtime = injectedRuntime.getValue();
        ModuleContext syscontext = runtime.getModuleContext();

        // Install and start this as a {@link Module}
        ModuleClassLoader classLoader = (ModuleClassLoader) getClass().getClassLoader();
        try {
            URL extensionURL = null;
View Full Code Here

TOP

Related Classes of org.jboss.gravia.runtime.ModuleContext

Copyright © 2018 www.massapicom. 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.