Menu

#71 INDIURLStreamHandlerFactory and NetbeansPlatfrom application

1.50
closed
bug (2)
2015-10-30
2015-09-29
No

URL.setURLStreamHandlerFactory (URLStreamHandlerFactory factory) and modular applications. When you use this class in the NetBeans Platfrom environment we can not easily run the application, because NetBeanPlatform provides its own factory, which is able to manage a URLStreamHandler provided by special Annotation. Every attempt to connect to external server will faild with error thrown by URL.setURLStreamHandlerFactory.
java.lang.Error: factory already defined
at java.net.URL.setURLStreamHandlerFactory(URL.java:1105)
at org.indilib.i4j.protocol.url.INDIURLStreamHandlerFactory.init(INDIURLStreamHandlerFactory.java:49)
at org.indilib.i4j.protocol.INDIProtocol.<clinit>(INDIProtocol.java:31)
at org.indilib.i4j.client.INDIServerConnection.askForDevices(INDIServerConnection.java:274)</clinit>

Maybe you can add code to management INDIURLStreamHandlerFactory.init () method, by passing the settings on the command line or some other solution to disable automatic initialize URL.setURLStreamHandlerFactory.

Discussion

  • Richard van Nieuwenhoven

    solved this by checking a system property INDIURLStreamHandlerFactory.auto.register if this is not set to true (default) than the init of the factory is sciped. Will be deployed is 30 minutes, please test an give a feetback?

     
  • Richard van Nieuwenhoven

    • labels: --> bug
    • assigned_to: Richard van Nieuwenhoven
     
  • Jakub Hudziak

    Jakub Hudziak - 2015-10-18

    Tested, it is ok.
    This is class example, how to register URLConnection Factory in Netbeans Platform. If you want you can put this somewhere in documentation.

    import java.io.IOException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.net.URLStreamHandler;
    import org.indilib.i4j.protocol.url.INDIURLConnection;
    import org.openide.util.URLStreamHandlerRegistration;
    
    /**
     *
    
     * @author jhudziak
     */
    @URLStreamHandlerRegistration(protocol = {"indi"})
    public class INDIURLStreamHandlerFactoryNBPRegistration extends URLStreamHandler {
    
        public INDIURLStreamHandlerFactoryNBPRegistration() {
            System.out.println("INDIURLStreamHandlerFactoryNBPRegistration switching off INDIURLStreamHandlerFactory");
            System.setProperty("INDIURLStreamHandlerFactory.auto.register", "false");
            System.out.println("INDIURLStreamHandlerFactory.auto.register:" + System.getProperty("INDIURLStreamHandlerFactory.auto.register"));
        }
    
        @Override
        protected URLConnection openConnection(URL u) throws IOException {
            return new NBIndiUrlConnection(u);
        }
    
        private final class NBIndiUrlConnection extends INDIURLConnection {
    
            public NBIndiUrlConnection(URL url) {
                super(url);
            }
        }
    }
    
     
  • Richard van Nieuwenhoven

    thats good news! Maybe it would be usefull to provide indi as a netbeans module? could/would you help with such a task?

     
  • Richard van Nieuwenhoven

    • status: open --> closed
     
  • Jakub Hudziak

    Jakub Hudziak - 2015-10-19

    No problem. For now there is only the one class to register URLConnection, to work with the NBP. I can send the Maven module.
    Who will want to use need only hook up the module as a dependency to main NB Aplication.

     
  • Richard van Nieuwenhoven

    yes please send it, thats a very nice adition. I think I will create the same for eclipse RCP.

     
  • Jakub Hudziak

    Jakub Hudziak - 2015-10-19

    as an attachment here, or project commit?

     
  • Richard van Nieuwenhoven

    do it as an attachment because, I do not know the procedure for pull requests on sourceforge

     
  • Jakub Hudziak

    Jakub Hudziak - 2015-10-20

    If some one add this module as dependency to NBP App it should be enabled to use INDI in NBP environment.

    You can add this to main project.
    Extract zip to main container.
    Add to main pom <module>i4j-nbp-integration</module> in <modules> section.</modules>

     
  • Richard van Nieuwenhoven

    great thantks, but one question. there is a repository defined inside the module. that means I must exclude the module from being deployed to central. Is there a way to define the module with only dependencies from central? (the module will be deployed to the download section of sourceforge till I know a better solution)

     

    Last edit: Richard van Nieuwenhoven 2015-10-23
  • Jakub Hudziak

    Jakub Hudziak - 2015-10-27

    I have to think about it.

     
  • Richard van Nieuwenhoven

    If it not (easy) possible we could profide a own repo for netbeans, or publish into an other public netbeans repo. If you can provide some pointers on how to do that.

     

Log in to post a comment.

MongoDB Logo MongoDB