Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

OSGI support: add resources publish via HttpService #74

Open
arotnov opened this issue Apr 13, 2018 · 0 comments
Open

OSGI support: add resources publish via HttpService #74

arotnov opened this issue Apr 13, 2018 · 0 comments

Comments

@arotnov
Copy link

arotnov commented Apr 13, 2018

In OSGI environment all static resources must be published by HttpService to be available through http. Vaadin has its own Service to publish Vaadin-dependent resources. And it publish its own resources like vaadinBootstrap.js by this Service. So, here is working code of Declarative Component for publish ChartJs resources by HttpService:

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;

import com.vaadin.osgi.resources.OsgiVaadinResources;
import com.vaadin.osgi.resources.VaadinResourceService;
import com.vaadin.osgi.resources.OsgiVaadinResources.ResourceBundleInactiveException;

@Component(immediate = true)
public class VaadinChartJsResourcesContribution {
	private static final String[] RESOURCES = { 
			"chartjs/Chart.min.js", 
			"chartjs/chartjs-connector.js",
			"chartjs/chartjs-plugin-annotation.min.js",
			"chartjs/chartjs-plugin-zoom.min.js", 
			"chartjs/hammer.min.js" };
    private HttpService httpService;

    @Activate
    void startup() throws NamespaceException, ResourceBundleInactiveException {
        VaadinResourceService service = OsgiVaadinResources.getService();
        for (String resourceName : RESOURCES) {
            service.publishResource(resourceName, httpService);
        }
    }

    @Reference
    void setHttpService(HttpService service) {
        httpService = service;
    }

    void unsetHttpService(HttpService service) {
        httpService = null;
    }
}

Declarative Service Component annotations could be used from org.osgi:osgi.cmpn:6.0.0. To create definition of DS component (@component annotation not processed in runtime) maven-bundle-plugin could be used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants