I have tried several of the usual methods of accessing a rest service using httpclient, urlconnection, etc., to no avail.
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.
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 ClientHTTPBuilder
.
So here are a couple of examples:
This example works for this URL...But not the one using tls1.2
URL url = new URL("https://wikipedia.org");
URLConnection urlConnection = url.openConnection();
InputStream in = urlConnection.getInputStream();
str = getStringByBufferedReader(in);
Second example:
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);
Both connection types get the following error:
Exception in Test method = javax.net.ssl.SSLException: Received fatal alert: protocol_version
I have imported the certificate as well. I have also tried jdk 1.8 to no avail.