A website in OSGi that uses a REST web service in the background

I spent many days trying to figure out how to add a site to OSGi.

I have a hava Web service launched with the Jetty extension to use Jetty as a connector. This feature provides various resources at multiple URLs.

But I would also like to have a small website running on the system that the user can access. I wanted to use some HTML, Javascript, CSS and provide the current status of the data using some graphs and images.

I assume that since Jetty is running in the background, I can deploy this site to Jetty and possibly call the server resources provided by Restlet in Javascript.

Apparently nothing worked except relaxation services.

My question is, can I add a WAB package and wait for it to work (since Jetty is running in the background)? Or is there a better way to add a site to OSGi? Or The only option that I have now, since you can return the HTML form as a view, add all the javascript code inside the HTML form and send it in response to a GET request (which I think is a mess).

Everything will work in raspberry pi, so that I can only have a small size. I am using Equinox, Restlet 2.3.0 and Jetty 9.2.6.

I would really appreciate if someone knows a link where I can get information on how to get at least a sample page in OSGi. I tried many, no luck.

+4
source share
3

Jetty Restlet . , ( ) .

, Restlet . , , Restlet WAB-, .. .

:

  • , Restlet OSGi. FrameworkListener, , ..... Restlet:

    private Component component;
    
    public void start(BundleContext bundleContext) throws Exception {
        bundleContext.addFrameworkListener(new FrameworkListener() {
            component = new Component();
            (...)
            component.start();
        });
    }
    
    public void stop(BundleContext bundleContext) throws Exception {
        component.stop();
    }
    
  • , , , Restlet. OSGi-, Restlet, .

    ServiceReference[] restletAppRefs = bundleContext.getServiceReferences(
         "restletApplication",
                    null);
    
    if (restletAppsRefs != null) {
        for (ServiceReference restletAppRef : restletAppsRefs) {
            RestletApplicationService descriptor
                 = (RestletApplicationService) bundleContext
                   .getService(serviceReference);
            String path = descriptor.getPath();
            Application restletApplication = descriptor.getApplication();
    
            // Register the application against the component
            (...)
        }
    }
    

    try {
        VirtualHost virtualHost = getExistingVirtualHost(
                       component, hostDomain, hostPort);
        if (virtualHost == null) {
            virtualHost = new VirtualHost();
            virtualHost.setHostDomain(hostDomain);
            virtualHost.setHostPort(hostPort);
    
            component.getHosts().add(virtualHost);
        }
    
        Context context = component.getContext().createChildContext();
        virtualHost.setContext(context);
    
        virtualHost.attachDefault(application);
    
        component.updateHosts();
    
        application.start();
    } catch(Exception ex) {
        (...)
    }
    
  • OSGi. , OSGi.

    bundleContext.addServiceListener(new ServiceListener() {
        public void serviceChanged(ServiceEvent event) {
            if (isServiceClass(event, RestletApplicationService)) {
                int type = event.getType();
    
                if (type == ServiceEvent.REGISTERED) {
                    // Register the Restlet application against the component
                } else if (type == ServiceEvent.UNREGISTERING) {
                    // Unregister the Restlet application
                }
            }
        }
    });
    

, , Thierry

0

- OSGi , . OSGi, :

  • - WAB. , OSGi. , - Jetty , , OSGi .

org.apache.felix.http.jetty WAB. 2.2.2 1,3 Jetty. (, Pax-Web, Karaf, Jetty)

  • - OSGi Http ( , (, Felix). org.osgi.service.http.HttpService.registerResources() .

, , Restlet OSGi http, Jetty.

Jetty . Jetty, , . Jetty, , Restlet Jetty. .

0

Source: https://habr.com/ru/post/1619935/


All Articles