1

I have tried to establish https connection. I have loaded trustStore and password through following code:

HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
String path = "/path to trust store";
String password = "password of trust store";
KeyStore keyStore = KeyStore.getInstance("p12");
InputStream inputStream = new FileInputStream(path);
keyStore.load(inputStream,password.toCharArray());
httpClientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial((TrustStrategy) keyStore).build()));
CloseableHttpClient httpClient = httpClientBuilder.build();
HttpGet request = new HttpGet(this.backendUrl + url);
request.addHeader("Accept", "application/json");
   String responseString = null;
        try {
            HttpResponse response = httpClient.execute(request);
            if (logger.isDebugEnabled()) {
                logger.debug("Request successful for " + url);
            }
            responseString = EntityUtils.toString(response.getEntity(), "UTF-8");

        } catch (IllegalStateException e) {
            logger.error("The response is empty ");
        } catch (NullPointerException e) {
            logger.error("Bad request to the URL");
        } catch (IOException e) {
            logger.error("mke");
        }

I got an error in browser as:

The character encoding of the plain text document was not declared. 
The document will render with garbled text in some browser configurations 
if the document contains characters from outside the US-ASCII range.
The character encoding of the file needs to be declared in the 
transfer protocol or file needs to use a byte order 
mark as an encoding signature.
usergs
  • 1,344
  • 3
  • 9
  • 18
  • I found out that error is due to key specified keystore. I have created key store using [1]. Not found a solution yet :( [1] https://stackoverflow.com/questions/11952274/how-can-i-create-keystore-from-an-existing-certificate-abc-crt-and-abc-key-fil – usergs Apr 05 '18 at 04:03

0 Answers0