Package org.papoose.http

Examples of org.papoose.http.HttpServer


        Properties properties = new Properties();

        properties.setProperty(HttpServer.HTTP_PORT, "8080");

        HttpServer server = JettyHttpServer.generate(properties);

        server.start();

        HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());

        httpService.start();
        bundleContext.registerService(HttpService.class.getName(), httpService, null);

        try
        {
            ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
            HttpService service = (HttpService) bundleContext.getService(sr);

            service.registerResources("/a/b", "/org/papoose/tck", new HttpContext()
            {
                public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
                {
                    return true;
                }

                public URL getResource(String name)
                {
                    return HttpServiceImplTest.class.getResource(name);
                }

                public String getMimeType(String name)
                {
                    return null;
                }
            });

            URL url = new URL("http://localhost:8080/a/b/http/HttpServiceImplTest.class");

            DataInputStream reader = new DataInputStream(url.openStream());

            assertEquals((byte) 0xca, reader.readByte());
            assertEquals((byte) 0xfe, reader.readByte());

            assertEquals((byte) 0xba, reader.readByte());
            assertEquals((byte) 0xbe, reader.readByte());

            service.unregister("/a/b");
        }
        finally
        {
            httpService.stop();
            server.stop();
        }
    }
View Full Code Here


        Properties properties = new Properties();

        properties.setProperty(HttpServer.HTTP_PORT, "8080");

        HttpServer server = JettyHttpServer.generate(properties);

        server.start();

        HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());

        httpService.start();
        bundleContext.registerService(HttpService.class.getName(), httpService, null);

        try
        {
            ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
            HttpService service = (HttpService) bundleContext.getService(sr);

            service.registerResources("/a/b", ".", new HttpContext()
            {
                public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
                {
                    return true;
                }

                public URL getResource(String name)
                {
                    name = name.replaceAll("^\\./", "");
                    name = name.replaceAll("/\\./", "/");
                    return HttpServiceImplTest.class.getResource(name);
                }

                public String getMimeType(String name)
                {
                    return null;
                }
            });

            URL url = new URL("http://localhost:8080/a/b/HttpServiceImplTest.class");

            DataInputStream reader = new DataInputStream(url.openStream());

            assertEquals((byte) 0xca, reader.readByte());
            assertEquals((byte) 0xfe, reader.readByte());

            assertEquals((byte) 0xba, reader.readByte());
            assertEquals((byte) 0xbe, reader.readByte());

            service.unregister("/a/b");
        }
        finally
        {
            httpService.stop();
            server.stop();
        }
    }
View Full Code Here

TOP

Related Classes of org.papoose.http.HttpServer

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.