Java OSGi Centralized Network Configuration

I am looking to create an application based on an OSGi model. One of the elements of this will be network access (http and obr first).

I'm looking for a way to centralize network configuration (proxying, encryption, etc.), perhaps for a single package that the rest of the application can access.

Has anyone done this / got ideas?

thank

+2


source to share


1 answer


In this case, one possibility would be to create an OSGi service or set of services (possibly encapsulated in a separate package) that would provide all the necessary methods of accessing the network. The services themselves can be configured via the Configuration Admin Service , which is part of the OSGi Service Compendium.

Some of the methods provided by the service (s) can actually be factory methods for creating pre-configured network access objects like java.net. URLConnection or java.net.Socket . Example:



public interface NetworkService {
    public Socket createSocket();
}

class NetworkServiceImpl implements NetworkService {
    static final Proxy DEFAULT_PROXY = new Proxy(...);

    public Socket createSocket() {
        Socket s = new Socket(DEFAULT_PROXY);
        s.setReceiveBufferSize(4096);
        return s;
    } 
}

      

+4


source







All Articles