Skip to content

Commit 0ed49b9

Browse files
committed
Simplified ECFSSLContextFactory constructor and made more robust.
1 parent 28d52fd commit 0ed49b9

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ECFSSLContextFactory.java

+20-5
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,27 @@
2525
*/
2626
public class ECFSSLContextFactory implements SSLContextFactory {
2727

28-
private final ServiceTracker<Provider, Provider> providerTracker;
28+
private ServiceTracker<Provider, Provider> providerTracker;
2929
private final String defaultProtocol;
3030
private final String defaultProviderName;
3131

32-
public ECFSSLContextFactory(BundleContext context, String defaultProtocol) {
32+
public ECFSSLContextFactory(BundleContext context) throws NoSuchAlgorithmException {
33+
this(context, null);
34+
}
35+
36+
public ECFSSLContextFactory(BundleContext context, String defaultProtocol) throws NoSuchAlgorithmException {
3337
this(context, defaultProtocol, null);
3438
}
3539

36-
public ECFSSLContextFactory(BundleContext context, String defaultProtocol, String defaultProviderName) {
40+
public ECFSSLContextFactory(BundleContext context, String defaultProtocol, String defaultProviderName) throws NoSuchAlgorithmException {
41+
if (context == null)
42+
throw new NullPointerException("context must not be null"); //$NON-NLS-1$
43+
if (defaultProviderName == null) {
44+
defaultProviderName = SSLContext.getDefault().getProvider().getName();
45+
}
46+
if (defaultProtocol == null) {
47+
defaultProtocol = SSLContext.getDefault().getProtocol();
48+
}
3749
this.defaultProtocol = defaultProtocol;
3850
this.defaultProviderName = defaultProviderName;
3951
this.providerTracker = new ServiceTracker<Provider, Provider>(context, Provider.class, null);
@@ -60,8 +72,11 @@ public SSLContext getInstance(String protocol) throws NoSuchAlgorithmException,
6072
return getInstance0(protocol, this.defaultProviderName);
6173
}
6274

63-
public void close() {
64-
this.providerTracker.close();
75+
public synchronized void close() {
76+
if (this.providerTracker != null) {
77+
this.providerTracker.close();
78+
this.providerTracker = null;
79+
}
6580
}
6681

6782
protected Provider findProvider(String providerName) {

framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
package org.eclipse.ecf.internal.core;
1313

1414
import java.util.*;
15-
import javax.net.ssl.SSLContext;
1615
import org.eclipse.core.runtime.*;
1716
import org.eclipse.ecf.core.*;
1817
import org.eclipse.ecf.core.identity.ID;
@@ -229,8 +228,7 @@ public void ungetService(Bundle bundle, ServiceRegistration registration, Object
229228
containerManagerServiceRegistration = ctxt.registerService(IContainerManager.class.getName(), sf, null);
230229

231230
// Register SSLContextFactory
232-
SSLContext defaultContext = SSLContext.getDefault();
233-
ecfSSLContextFactory = new ECFSSLContextFactory(ctxt, defaultContext.getProtocol(), defaultContext.getProvider().getName());
231+
ecfSSLContextFactory = new ECFSSLContextFactory(ctxt);
234232
sslContextFactoryRegistration = ctxt.registerService(SSLContextFactory.class, ecfSSLContextFactory, null);
235233

236234
SafeRunner.run(new ExtensionRegistryRunnable(this.context) {

0 commit comments

Comments
 (0)