sslcontextbuilder and SSLContexts deprecated
Asked Answered
T

3

25

I am using JDK1.8 with JDK Compilance JavaSE-1.7, Eclipse Luna, and Apache httpclient 4.4.1.

I am getting warning in Eclipse that sslcontextbuilder and SSLContexts are deprecated. What are alternatives for these classes?

Townsend answered 21/4, 2015 at 9:24 Comment(3)
Are you using OpenJDK?Alister
Can you please provide us some more information? Which eclipse, which JDK and which library are you using?Gladdie
I am using JDK1.8 with JDK Compilance JavaSE-1.7, Eclipse Luna And Apache httpclient 4.4.1 version.Townsend
T
45

I have actually just been looking at this and it appears that the HttpCLient SSLContexts class is in the process of being moved from org.apache.http.conn.ssl.SSLContexts to org.apache.http.ssl.SSLContexts. I changed my imports to these new packages and it appears to be good now. Not sure what your reference is for sslcontextbuilder but I am pretty sure it has an alternate implementation as well. Let me know more details and I can check.

Trainbearer answered 10/6, 2015 at 14:59 Comment(0)
R
1

you can change it as below code

// Fixing deprecated code to use current HttpClient implementations      Sekito.Lv 01/30/2019 11:29     Start
import org.apache.http.ssl.SSLContexts;
import org.apache.http.ssl.SSLContextBuilder;

//import org.apache.http.conn.ssl.SSLContexts;
//import org.apache.http.conn.ssl.SSLContextBuilder;
// Fixing deprecated code to use current HttpClient implementations      Sekito.Lv 01/30/2019 11:29     End
Ruthenian answered 30/1, 2019 at 11:13 Comment(0)
C
0
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;

public class SSLContextExample {
    public static SSLConnectionSocketFactory createSSLConnectionSocketFactory() throws Exception {
        TrustManager[] trustAllCerts = new TrustManager[] {
                new X509TrustManager() {
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return new java.security.cert.X509Certificate[]{};
                    }

                    public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                    }

                    public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                    }
                }
        };

        // Create a trust manager that does not validate certificate chains
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, null);

        return new SSLConnectionSocketFactory(sslContext);
    }
}
Claqueur answered 30/7, 2024 at 10:6 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Potoroo

© 2022 - 2025 — McMap. All rights reserved.