You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Heather Carter <he...@gmail.com> on 2016/03/25 04:56:59 UTC
Bizarre issue with CloseableHttpClient , every other httpget works
I have a program that goes out and gets a file from a https site, which for
now I have
simulated with a method on my service since the real site isn't ready.
The simulating method that returns a file with lines to process (it reads a
file from a local resource dir and streams it out):
https://mymachine:8443/myapp/contentsim/file1
The method that will make the HttpGet call to the simulator to get the file
and do the work
https://mymachine:8443/myapp/processfile/file1
I had to put in a timeout in my code so that I move past an issue where the
calls were hanging.
It now will successfully make the SSL handshake every other time.
HttpGet get = null;
RequestConfig params =
RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build();
String docRetrievalUrl = "
https://mymachine:8443/myapp/contentsim/file1";
get = new HttpGet(docRetrievalUrl);
get.setConfig(params);
LOGGER.info(">>> getDoc{}");
//sslClientFactory sets up keystore and truststore and
trustmanagers & keymanagers
//for 2 way ssl
try (CloseableHttpClient httpClient =
this.sslClientFactory.getHttpClient();
CloseableHttpResponse response = httpClient.execute(get) ){
if (response !=null) {
LOGGER.debug("Begin");
HttpEntity entity = response.getEntity();
if (entity !=null) {
InputStream is = entity.getContent();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
LOGGER.error("Beggining to process content as csv");
try ( CSVReader csvReader = new CSVReader(br,',','"') )
{
String[] cells;
while ( (cells = csvReader.readNext()) != null ){
csvLines.add( new DataRow(cells) );
}
}
br.close();
}
LOGGER.debug("done");
}
} catch (IOException ex) {
LOGGER("Problem " + ex.getMessage(),ex);
}