Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference:file: bundles can not be loaded if org.knopflerfish.osgi.registerserviceurlhandler=false #47

Closed
dpolivaev opened this issue Oct 20, 2018 · 2 comments

Comments

@dpolivaev
Copy link
Contributor

dpolivaev commented Oct 20, 2018

freeplane uses knopflerfish as OSGi framework.
Recently it was added an API which allows to embed it into java applications.
One special use case is running in servlet to perform calculations defined in mind maps.

Because URL.setURLStreamHandlerFactory is already used by Tomcat ( embedded in spring boot)
I used configuration option org.knopflerfish.osgi.registerserviceurlhandler=false
Unfortunately as a consequence protocol 'reference' was no more resolved.

However it is needed at Bundles.install0 which tries to create the bundle URL calling URL url = new URL(location);

 BundleImpl install0(String location, InputStream in, Object checkContext, Bundle caller)
    throws BundleException {
    InputStream bin;
    BundleArchive ba = null;
    try {
      if (in == null) {
        // Do it the manual way to have a chance to
        // set request properties
        final URL url  = new URL(location);
        final URLConnection conn = url.openConnection();

As a work around I added following static block to one of the components:

       try {
            Constructor<ServiceURLStreamHandlerFactory> constructor = ServiceURLStreamHandlerFactory.class.getDeclaredConstructor();
            constructor.setAccessible(true);
            ServiceURLStreamHandlerFactory systemUrlStreamHandlerFactory = constructor.newInstance();
            TomcatURLStreamHandlerFactory.getInstance().addUserFactory(systemUrlStreamHandlerFactory);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

It creates ServiceURLStreamHandlerFactory from knopflerfish and registers it as user factory by TomcatURLStreamHandlerFactory.

If the constructor was public or I could at least access FrameworkContext.systemUrlStreamHandlerFactory or some static method to create it I would not need the trick with the reflection.

It would be even better if the correct handler was used directly at the position where URL is created.

Could you consider any of that?
Let me know if I can help by submitting a pull request.

dpolivaev added a commit to dpolivaev/knopflerfish.org that referenced this issue Oct 23, 2018
@janste63
Copy link
Contributor

janste63 commented Oct 24, 2018 via email

@janste63
Copy link
Contributor

Seems ok, I've merged it (#48). Thanks for the improvement.

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

No branches or pull requests

2 participants