} else if (uri.getScheme().equalsIgnoreCase("https")) {
port = 443;
}
}
ClientBootstrap clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
File tmpFile;
try {
tmpFile = File.createTempFile("http", "download");
} catch (IOException e) {
throw new DeploymentFailedException("Cannot create temporary file for fetching s4r data from http server",
e);
}
clientBootstrap.setPipelineFactory(new HttpClientPipelineFactory(tmpFile));
ChannelFuture channelFuture = clientBootstrap.connect(new InetSocketAddress(host, port));
// TODO timeout?
Channel channel = channelFuture.awaitUninterruptibly().getChannel();
if (!channelFuture.isSuccess()) {
clientBootstrap.releaseExternalResources();
throw new DeploymentFailedException("Cannot connect to http uri [" + uri.toString() + "]",
channelFuture.getCause());
}
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toASCIIString());
request.setHeader(HttpHeaders.Names.HOST, host);
request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
request.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
channel.write(request);
channel.getCloseFuture().awaitUninterruptibly();
clientBootstrap.releaseExternalResources();
logger.debug("Finished downloading s4r file through http {}", uri.toString());
try {
return new FileInputStream(tmpFile);
} catch (FileNotFoundException e) {