title: How to get a simple Java client in eclipse to connect to a server using TLS1.2 protocol
body: <p>I have tried several of the usual methods of accessing a rest service using httpclient, urlconnection, etc., to no avail. </p>
  
  <p>I have read countless Stack Overflow articles on how to do this, nothing works in my eclipse mobilefirst/RSA environment. I am running jdk 1.7 with mobilefirst 7.1.1 And RSA 9.1.1.</p>
  
  <p>From what I have read, you have to set the SSLContext to talk to a tls1.2 server...As the same code works fine on other servers. There is only one way I have seen that allows you to set the SSLContext and that is with <code>ClientHTTPBuilder</code>.</p>
  
  <p>So here are a couple of examples:</p>
  
  <p><strong>This example works for this URL...But not the one using tls1.2</strong></p>
  
  <pre><code>URL url = new URL("https://wikipedia.org");
          URLConnection urlConnection = url.openConnection();
          InputStream in = urlConnection.getInputStream();
          str = getStringByBufferedReader(in);
  </code></pre>
  
  <p>Second example:</p>
  
  <pre><code>SSLContext context = SSLContext.getInstance("TLS");
      context.init(null, null, null);
  HttpClientBuilder clientBuilder = HttpClientBuilder.create().setSslcontext(context);
  HttpGet request = new HttpGet(baseURL);
  request.addHeader("Authorization", basicAuthorization);
  request.addHeader("Accept", "text/plain");
  CloseableHttpClient httpClient = clientBuilder.build();
  CloseableHttpResponse httpResponse = httpClient.execute(request);
  </code></pre>
  
  <p>Both connection types get the following error:</p>
  
  <pre><code>Exception in Test method = javax.net.ssl.SSLException: Received fatal alert: protocol_version
  </code></pre>
  
  <p>I have imported the certificate as well. I have also tried jdk 1.8 to no avail.</p>