views:

73

answers:

1

I'm looking to create an app based on the OSGi model. One of the elements of this will be network access (http and obr initially)

I am looking for a way of centralising the network config (proxying, encryption, etc) perhaps to a single bundle that the rest of the app can call into.

Has anybody done this/got ideas?

Thanks

+4  A: 

In that case one possibility would be to create an OSGi service or a set of services (possibly encapsulated in a separate bundle) that would provide all the required network access methods. The service(s) themselves could be configured through Configuration Admin Service that is part of 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;
    } 
}
Pavol Juhos