Package org.osgi.service.http

Examples of org.osgi.service.http.HttpContext


            this.webManagerRoot = "/" + this.webManagerRoot;
        }

        // register the servlet and resources
        try {
            HttpContext httpContext = this.httpService.createDefaultHttpContext();
            this.httpService.registerServlet(this.webManagerRoot, this,
                context.getProperties(), httpContext);
        } catch (Exception e) {
            // TODO: handle
        }
View Full Code Here


    public void testHandleResourceRegistrationOk() throws Exception
    {
        CountDownLatch initLatch = new CountDownLatch(1);
        CountDownLatch destroyLatch = new CountDownLatch(1);

        HttpContext context = new HttpContext()
        {
            public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
            {
                return true;
            }
View Full Code Here

    public void testCorrectPathInfoInHttpContextOk() throws Exception
    {
        CountDownLatch initLatch = new CountDownLatch(1);
        CountDownLatch destroyLatch = new CountDownLatch(1);

        HttpContext context = new HttpContext()
        {
            public String getMimeType(String name)
            {
                return null;
            }
View Full Code Here

    public void testHandleSecurityInFilterOk() throws Exception
    {
        CountDownLatch initLatch = new CountDownLatch(1);
        CountDownLatch destroyLatch = new CountDownLatch(1);

        HttpContext context = new HttpContext()
        {
            public String getMimeType(String name)
            {
                return null;
            }
View Full Code Here

    public void testUseServletContextOk() throws Exception
    {
        CountDownLatch initLatch = new CountDownLatch(1);
        CountDownLatch destroyLatch = new CountDownLatch(1);

        HttpContext context = new HttpContext()
        {
            public String getMimeType(String name)
            {
                return null;
            }

            public URL getResource(String name)
            {
                try
                {
                    File f = new File("src/test/resources/resource/" + name);
                    if (f.exists())
                    {
                        return f.toURI().toURL();
                    }
                }
                catch (MalformedURLException e)
                {
                    fail();
                }
                return null;
            }

            public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
            {
                return true;
            }
        };

        TestServlet servlet = new TestServlet(initLatch, destroyLatch)
        {
            private static final long serialVersionUID = 1L;

            @Override
            public void init(ServletConfig config) throws ServletException
            {
                ServletContext context = config.getServletContext();
                try
                {
                    assertEquals("", context.getContextPath());
                    assertNotNull(context.getResource("test.html"));
                    assertNotNull(context.getRealPath("test.html"));
                }
                catch (MalformedURLException e)
                {
                    fail();
                }
View Full Code Here

    }

    @Test
    public void testGetServletContext()
    {
        HttpContext httpCtx = Mockito.mock(HttpContext.class);
        ServletContext result1 = this.manager.getServletContext(httpCtx);
        ServletContext result2 = this.manager.getServletContext(httpCtx);

        Assert.assertNotNull(result1);
        Assert.assertNotNull(result2);
View Full Code Here

        String password = ConfigurationUtil.getProperty(config, PROP_PASSWORD, DEFAULT_PASSWORD);

        // register the servlet and resources
        try
        {
            HttpContext httpContext = new OsgiManagerHttpContext(httpService,
                securityProviderTracker, userId, password, realm);

            Dictionary servletConfig = toStringConfig(config);

            // register this servlet and take note of this
View Full Code Here

        final String id = createId(bundle1, SAMPLE_CONTEXT_ID);
        hcm.addHttpContext(bundle1, SAMPLE_CONTEXT_ID, sampleContext);

        // Servlet 1 gets the context
        final ServletMapping bundle1Servlet = new ServletMapping(bundle1, null, BUNDLE_1_ALIAS);
        HttpContext ctx1 = hcm.getHttpContext(bundle1, SAMPLE_CONTEXT_ID, bundle1Servlet);
        TestCase.assertNotNull(ctx1);
        TestCase.assertSame(ctx1, bundle1Servlet.getContext());
        TestCase.assertSame(sampleContext, ctx1);
        TestCase.assertTrue(hcm.getHttpContexts().get(id).getMappings().contains(bundle1Servlet));
        Map<String, Set<AbstractMapping>> orphans1 = hcm.getOrphanMappings();
View Full Code Here

        final String id1 = createId(bundle1, SAMPLE_CONTEXT_ID);
        hcm.addHttpContext(bundle1, SAMPLE_CONTEXT_ID, sampleContext);

        // Servlet 2 is an orphan
        final ServletMapping bundle2Servlet = new ServletMapping(bundle2, null, BUNDLE_2_ALIAS);
        HttpContext ctx2 = hcm.getHttpContext(bundle2, SAMPLE_CONTEXT_ID, bundle2Servlet);
        TestCase.assertNull(ctx2);
        TestCase.assertNull(bundle2Servlet.getContext());
        TestCase.assertTrue(hcm.getHttpContexts().get(id1).getMappings().isEmpty());
        Map<String, Set<AbstractMapping>> orphans2 = hcm.getOrphanMappings();
        TestCase.assertEquals(1, orphans2.size());
View Full Code Here

        final String id = createId(SAMPLE_CONTEXT_ID);
        hcm.addHttpContext(null, SAMPLE_CONTEXT_ID, sampleContext);

        // Servlet 1 gets the context
        final ServletMapping bundle1Servlet = new ServletMapping(bundle1, null, BUNDLE_1_ALIAS);
        HttpContext ctx1 = hcm.getHttpContext(bundle1, SAMPLE_CONTEXT_ID, bundle1Servlet);
        TestCase.assertNotNull(ctx1);
        TestCase.assertSame(ctx1, bundle1Servlet.getContext());
        TestCase.assertSame(sampleContext, ctx1);
        TestCase.assertEquals(1, hcm.getHttpContexts().get(id).getMappings().size());
        TestCase.assertTrue(hcm.getHttpContexts().get(id).getMappings().contains(bundle1Servlet));
        Map<String, Set<AbstractMapping>> orphans1 = hcm.getOrphanMappings();
        TestCase.assertTrue(orphans1.isEmpty());

        // unregister serlvet 1 --> all references clear
        hcm.ungetHttpContext(bundle1, SAMPLE_CONTEXT_ID, bundle1Servlet);
        TestCase.assertNull(bundle1Servlet.getContext());
        TestCase.assertTrue(hcm.getHttpContexts().get(id).getMappings().isEmpty());
        TestCase.assertTrue(hcm.getOrphanMappings().isEmpty());

        // Servlet 2 gets the context
        final ServletMapping bundle2Servlet = new ServletMapping(bundle2, null, BUNDLE_2_ALIAS);
        HttpContext ctx2 = hcm.getHttpContext(bundle2, SAMPLE_CONTEXT_ID, bundle2Servlet);
        TestCase.assertNotNull(ctx2);
        TestCase.assertSame(ctx2, bundle2Servlet.getContext());
        TestCase.assertSame(sampleContext, ctx2);
        TestCase.assertEquals(1, hcm.getHttpContexts().get(id).getMappings().size());
        TestCase.assertTrue(hcm.getHttpContexts().get(id).getMappings().contains(bundle2Servlet));
        TestCase.assertTrue(hcm.getOrphanMappings().isEmpty());

        // register Servlet 1 again --> gets context
        hcm.getHttpContext(bundle1, SAMPLE_CONTEXT_ID, bundle1Servlet);
        HttpContext ctx3 = hcm.getHttpContext(bundle1, SAMPLE_CONTEXT_ID, bundle1Servlet);
        TestCase.assertNotNull(ctx3);
        TestCase.assertSame(ctx3, bundle1Servlet.getContext());
        TestCase.assertSame(sampleContext, ctx3);
        TestCase.assertEquals(2, hcm.getHttpContexts().get(id).getMappings().size());
        TestCase.assertTrue(hcm.getHttpContexts().get(id).getMappings().contains(bundle1Servlet));
View Full Code Here

TOP

Related Classes of org.osgi.service.http.HttpContext

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.