Skip to content

Commit

Permalink
Merge pull request #287 from miditeam/master
Browse files Browse the repository at this point in the history
enable keep-alive for HTTPS (static sslSocketFactory)
  • Loading branch information
briandilley authored May 24, 2023
2 parents 82e7373 + 4052858 commit 28e6910
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class JsonRpcHttpClient extends JsonRpcClient implements IJsonRpcClient {
private int connectionTimeoutMillis = 60 * 1000;
private int readTimeoutMillis = 60 * 1000 * 2;
private SSLContext sslContext = null;
private SSLSocketFactory sslSocketFactory = null;
private HostnameVerifier hostNameVerifier = null;
private String contentType = JSONRPC_CONTENT_TYPE;
private boolean gzipRequests = false;
Expand Down Expand Up @@ -239,8 +241,10 @@ private void setupSsl(HttpURLConnection connection) {
if (hostNameVerifier != null) {
https.setHostnameVerifier(hostNameVerifier);
}
if (sslContext != null) {
if (sslContext != null) {
https.setSSLSocketFactory(sslContext.getSocketFactory());
} else if (sslSocketFactory != null) {
https.setSSLSocketFactory(sslSocketFactory);
}
}
}
Expand Down Expand Up @@ -333,6 +337,13 @@ public void setSslContext(SSLContext sslContext) {
this.sslContext = sslContext;
}

/**
* @param sslSocketFactory the sslContext to set
*/
public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
}

/**
* @param hostNameVerifier the hostNameVerifier to set
*/
Expand Down

0 comments on commit 28e6910

Please sign in to comment.