Package org.osgi.service.http

Examples of org.osgi.service.http.HttpService


        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


    this.context = context;
  }

  @Override
  public Object addingService(ServiceReference reference) {
    HttpService http = (HttpService) super.addingService(reference);
    HttpResourceTracker tracker = new HttpResourceTracker(context, http);
    tracker.open();
    return tracker;
  }
View Full Code Here

            _context,
            HttpService.class.getName(),
            new ServiceTrackerCustomizer() {
                public Object addingService(ServiceReference serviceReference) {
                    try {
                        HttpService service = (HttpService)_context.getService(serviceReference);
                        Dictionary<String, String> initParams = new Hashtable<String, String>();
                        initParams.put("javax.ws.rs.Application", SampleApplication.class.getName());
                        service.registerServlet(_path, new SampleServlet(), initParams, null);
                        return service;
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        throw new RuntimeException(ex);
                    }
                }

                public void modifiedService(ServiceReference serviceReference, Object o) {
                    // do nothing
                }

                public void removedService(ServiceReference serviceReference, Object o) {
                    HttpService service = (HttpService)_context.getService(serviceReference);
                    if (service != null) {
                        service.unregister(_path);
                    }
                }
            }
        );
        _tracker.open();
View Full Code Here

    protected void registerServlet(BundleContext bundleContext) throws Exception {
        httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName());

        if (httpServiceRef != null && !registerService) {
            LOG.info("Register the servlet service");
            final HttpService httpService = (HttpService)bundleContext.getService(httpServiceRef);
            if (httpService != null) {
                // create a default context to share between registrations
                final HttpContext httpContext = httpService.createDefaultHttpContext();
                // register the hello world servlet
                final Dictionary<String, String> initParams = new Hashtable<String, String>();
                initParams.put("servlet-name", "TestServlet");
                httpService.registerServlet("/test/services", // alias
                        new MyServlet(), // register servlet
                        initParams, // init params
                        httpContext // http context
                );
                registerService = true;
View Full Code Here

        String alias = (String)sr.getProperty(SERVLET_URI);

        Object[] httpServices = httpTracker.getServices();

        for (int i = 0; httpServices != null && i < httpServices.length; i++) {
            HttpService http = (HttpService)httpServices[i];
            try {
                http.registerServlet(alias, servlet, null, null);
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
    }
View Full Code Here

    void unregisterServlet(ServiceReference sr) {
        String alias = (String)sr.getProperty(SERVLET_URI);
        Object[] httpServices = httpTracker.getServices();

        for (int i = 0; httpServices != null && i < httpServices.length; i++) {
            HttpService http = (HttpService)httpServices[i];
            try {
                http.unregister(alias);
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
            bc.ungetService(sr);
        }
View Full Code Here

            super(bc, HttpService.class.getName(), null);
        }

        @Override
        public Object addingService(ServiceReference reference) {
            HttpService httpService = (HttpService)super.addingService(reference);
            // Register existing servlets
            String filter = "(objectclass=" + Servlet.class.getName() + ")";
            ServiceReference[] servlets = null;
            try {
                servlets = bc.getServiceReferences(null, filter);
            } catch (InvalidSyntaxException e) {
                throw new IllegalStateException(e);
            }
            for (int i = 0; servlets != null && i < servlets.length; i++) {
                Servlet servlet = (Servlet)bc.getService(servlets[i]);
                String alias = (String)servlets[i].getProperty(SERVLET_URI);

                try {
                    httpService.registerServlet(alias, servlet, null, null);
                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }
            }
            return httpService;
View Full Code Here

    protected void registerServlet(BundleContext bundleContext) throws Exception {
        httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName());
       
        if (httpServiceRef != null && !registerService) {
            LOG.info("Regist the servlet service");
            final HttpService httpService = (HttpService)bundleContext.getService(httpServiceRef);
            if (httpService != null) {
                // create a default context to share between registrations
                final HttpContext httpContext = httpService.createDefaultHttpContext();
                // register the hello world servlet
                final Dictionary initParams = new Hashtable();
                initParams.put("matchOnUriPrefix", "false");
                initParams.put("servlet-name", "camelServlet");
                httpService.registerServlet("/camel/services", // alias
                    (Servlet)new CamelHttpTransportServlet(), // register servlet
                    initParams, // init params
                    httpContext // http context
                );
                registerService = true;
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public void start(BundleContext bc) throws Exception {
        httpServiceRef = bc.getServiceReference(HttpService.class.getName());
        if (httpServiceRef != null) {
            final HttpService httpService = (HttpService)bc.getService(httpServiceRef);
            if (httpService != null) {
                // create a default context to share between registrations
                final HttpContext httpContext = httpService.createDefaultHttpContext();
                // register the hello world servlet
                final Dictionary initParams = new Hashtable();
                initParams.put("matchOnUriPrefix", "false");
                initParams.put("servlet-name", "camelServlet");
                httpService.registerServlet("/camel/services", // alias
                    (Servlet)new CamelHttpTransportServlet(), // register servlet
                    initParams, // init params
                    httpContext // http context
                );

View Full Code Here

    protected void registerServlet(BundleContext bundleContext) throws Exception {
        httpServiceRef = bundleContext.getServiceReference(HttpService.class.getName());
       
        if (httpServiceRef != null && !registerService) {
            LOG.info("Register the servlet service");
            final HttpService httpService = (HttpService)bundleContext.getService(httpServiceRef);
            if (httpService != null) {
                // create a default context to share between registrations
                final HttpContext httpContext = httpService.createDefaultHttpContext();
                // register the hello world servlet
                final Dictionary<String, String> initParams = new Hashtable<String, String>();
                initParams.put("matchOnUriPrefix", "false");
                initParams.put("servlet-name", "CamelServlet");
                httpService.registerServlet("/camel/services", // alias
                    new CamelHttpTransportServlet(), // register servlet
                    initParams, // init params
                    httpContext // http context
                );
                registerService = true;
View Full Code Here

TOP

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

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.