Skip to content

Commit a66f661

Browse files
committed
Added support for usage of sslContextFactory.getInstance(protocol) and
sslContextFactory.getInstance(protocol,provider) in creation of HttpClient.Builder in ECFHttpClientFactory.newClient()
1 parent b2cab28 commit a66f661

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/ECFHttpClientFactory.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.eclipse.core.runtime.IStatus;
2929
import org.eclipse.core.runtime.Status;
30+
import org.eclipse.ecf.core.security.SSLContextFactory;
3031
import org.eclipse.ecf.core.util.Trace;
3132
import org.eclipse.ecf.internal.provider.filetransfer.DebugOptions;
3233
import org.eclipse.ecf.provider.filetransfer.httpclientjava.HttpClientOptions;
@@ -50,12 +51,25 @@ public class ECFHttpClientFactory implements IHttpClientFactory {
5051

5152
@Override
5253
public HttpClient.Builder newClient() {
53-
5454
HttpClient.Builder builder = HttpClient.newBuilder().followRedirects(Redirect.NORMAL);
55+
String sslContextProvider = HttpClientOptions.HTTPCLIENT_SSLCONTEXT_PROVIDER;
56+
String sslContextProtocol = HttpClientOptions.HTTPCLIENT_SSLCONTEXT_PROTOCOL;
57+
SSLContextFactory sslContextFactory = Activator.getDefault().getSSLContextFactory();
5558
try {
56-
builder.sslContext(Activator.getDefault().getSSLContextFactory().getDefault());
59+
if (sslContextProvider == null) {
60+
if (sslContextProtocol == null) {
61+
builder.sslContext(sslContextFactory.getDefault());
62+
} else {
63+
builder.sslContext(sslContextFactory.getInstance(sslContextProtocol));
64+
}
65+
} else {
66+
if (sslContextProtocol == null)
67+
throw new NoSuchProviderException("Null protocol not supported for provider=" + sslContextProvider);
68+
builder.sslContext(sslContextFactory.getInstance(sslContextProtocol, sslContextProvider));
69+
}
5770
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
58-
Activator.getDefault().log(new Status(IStatus.ERROR,Activator.PLUGIN_ID,"Could not set SSLContext when creating jre HttpClient", e));
71+
Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
72+
"Could not set SSLContext when creating jre HttpClient", e));
5973
}
6074
builder = Activator.getDefault().runModifiers(builder, new ModifierRunner<HttpClient.Builder>() {
6175
@Override

providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/provider/filetransfer/httpclientjava/HttpClientOptions.java

+9
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@ public interface HttpClientOptions {
3333
int NTLM_PROXY_RESPONSE_CODE = 477;
3434
String FORCE_NTLM_PROP = "org.eclipse.ecf.provider.filetransfer.httpclient4.options.ForceNTLMProxy"; //$NON-NLS-1$
3535

36+
/**
37+
* @since 2.0
38+
*/
39+
String HTTPCLIENT_SSLCONTEXT_PROTOCOL = System.getProperty("org.eclipse.ecf.provider.filetransfer.httpclient.sslcontext.protocol"); //$NON-NLS-1$
40+
41+
/**
42+
* @since 2.0
43+
*/
44+
String HTTPCLIENT_SSLCONTEXT_PROVIDER = System.getProperty("org.eclipse.ecf.provider.filetransfer.httpclient.sslcontext.provider"); //$NON-NLS-1$
3645
}

0 commit comments

Comments
 (0)