use of org.apache.http.client.config.RequestConfig in project libresonic by Libresonic.
the class LyricsService method executeGetRequest.
private String executeGetRequest(String url) throws IOException {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(15000).setSocketTimeout(15000).build();
HttpGet method = new HttpGet(url);
method.setConfig(requestConfig);
try (CloseableHttpClient client = HttpClients.createDefault()) {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
return client.execute(method, responseHandler);
}
}
use of org.apache.http.client.config.RequestConfig in project libresonic by Libresonic.
the class PodcastService method doRefreshChannel.
@SuppressWarnings({ "unchecked" })
private void doRefreshChannel(PodcastChannel channel, boolean downloadEpisodes) {
InputStream in = null;
try (CloseableHttpClient client = HttpClients.createDefault()) {
channel.setStatus(PodcastStatus.DOWNLOADING);
channel.setErrorMessage(null);
podcastDao.updateChannel(channel);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(// 2 minutes
2 * 60 * 1000).setSocketTimeout(// 10 minutes
10 * 60 * 1000).build();
HttpGet method = new HttpGet(channel.getUrl());
method.setConfig(requestConfig);
try (CloseableHttpResponse response = client.execute(method)) {
in = response.getEntity().getContent();
Document document = new SAXBuilder().build(in);
Element channelElement = document.getRootElement().getChild("channel");
channel.setTitle(StringUtil.removeMarkup(channelElement.getChildTextTrim("title")));
channel.setDescription(StringUtil.removeMarkup(channelElement.getChildTextTrim("description")));
channel.setImageUrl(getChannelImageUrl(channelElement));
channel.setStatus(PodcastStatus.COMPLETED);
channel.setErrorMessage(null);
podcastDao.updateChannel(channel);
downloadImage(channel);
refreshEpisodes(channel, channelElement.getChildren("item"));
}
} catch (Exception x) {
LOG.warn("Failed to get/parse RSS file for Podcast channel " + channel.getUrl(), x);
channel.setStatus(PodcastStatus.ERROR);
channel.setErrorMessage(getErrorMessage(x));
podcastDao.updateChannel(channel);
} finally {
IOUtils.closeQuietly(in);
}
if (downloadEpisodes) {
for (final PodcastEpisode episode : getEpisodes(channel.getId())) {
if (episode.getStatus() == PodcastStatus.NEW && episode.getUrl() != null) {
downloadEpisode(episode);
}
}
}
}
use of org.apache.http.client.config.RequestConfig in project c4sg-services by Code4SocialGood.
the class SlackUtils method createHttpClient.
public static CloseableHttpClient createHttpClient(int timeout) {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
return httpClient;
}
use of org.apache.http.client.config.RequestConfig in project opennms by OpenNMS.
the class GrafanaDashletConfigurationWindow method getGrafanaDashboards.
private Map<String, String> getGrafanaDashboards() throws GrafanaDashletException {
/**
* Loading the required properties...
*/
final String grafanaApiKey = System.getProperty("org.opennms.grafanaBox.apiKey", "");
final String grafanaProtocol = System.getProperty("org.opennms.grafanaBox.protocol", "http");
final String grafanaHostname = System.getProperty("org.opennms.grafanaBox.hostname", "localhost");
final int grafanaPort = Integer.parseInt(System.getProperty("org.opennms.grafanaBox.port", "3000"));
final int grafanaConnectionTimeout = Integer.parseInt(System.getProperty("org.opennms.grafanaBox.connectionTimeout", "500"));
final int grafanaSoTimeout = Integer.parseInt(System.getProperty("org.opennms.grafanaBox.soTimeout", "500"));
if (!"".equals(grafanaApiKey) && !"".equals(grafanaHostname) && !"".equals(grafanaProtocol) && ("http".equals(grafanaProtocol) || "https".equals(grafanaProtocol))) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(grafanaConnectionTimeout).setSocketTimeout(grafanaSoTimeout).build();
final URI uri = new URIBuilder().setScheme(grafanaProtocol).setHost(grafanaHostname).setPort(grafanaPort).setPath("/api/search/").build();
final HttpGet httpGet = new HttpGet(uri);
httpGet.setConfig(requestConfig);
/**
* Adding the API key...
*/
httpGet.setHeader("Authorization", "Bearer " + grafanaApiKey);
final Map<String, String> resultSet = new TreeMap<>();
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
/**
* Fill the result set...
*/
final String responseString = IOUtils.toString(httpEntity.getContent(), StandardCharsets.UTF_8.name());
if (!Strings.isNullOrEmpty(responseString)) {
try {
final JSONArray arr = new JSONObject("{dashboards:" + responseString + "}").getJSONArray("dashboards");
for (int i = 0; i < arr.length(); i++) {
resultSet.put(arr.getJSONObject(i).getString("title"), arr.getJSONObject(i).getString("uri"));
}
} catch (JSONException e) {
throw new GrafanaDashletException(e.getMessage());
}
}
}
}
return resultSet;
} catch (Exception e) {
throw new GrafanaDashletException(e.getMessage());
}
} else {
throw new GrafanaDashletException("Invalid configuration");
}
}
use of org.apache.http.client.config.RequestConfig in project Xponents by OpenSextant.
the class SharepointClient method getClient.
/**
* Sharepoint requires NTLM. This client requires a non-null user/passwd/domain.
*
*/
@Override
public HttpClient getClient() {
if (currentConn != null) {
return currentConn;
}
HttpClientBuilder clientHelper = HttpClientBuilder.create();
if (proxyHost != null) {
clientHelper.setProxy(proxyHost);
}
RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
CredentialsProvider creds = new BasicCredentialsProvider();
creds.setCredentials(AuthScope.ANY, new NTCredentials(user, passwd, server, domain));
clientHelper.setDefaultCredentialsProvider(creds);
HttpClient httpClient = clientHelper.setDefaultRequestConfig(globalConfig).build();
return httpClient;
}
Aggregations