use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-framework by spring-projects.
the class HttpComponentsHttpInvokerRequestExecutorTests method defaultSettingsOfHttpClientMergedOnExecutorCustomization.
@Test
public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws IOException {
RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build();
CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class));
Configurable configurable = (Configurable) client;
when(configurable.getConfig()).thenReturn(defaultConfig);
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(client);
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
HttpPost httpPost = executor.createHttpPost(config);
assertSame("Default client configuration is expected", defaultConfig, httpPost.getConfig());
executor.setConnectionRequestTimeout(4567);
HttpPost httpPost2 = executor.createHttpPost(config);
assertNotNull(httpPost2.getConfig());
assertEquals(4567, httpPost2.getConfig().getConnectionRequestTimeout());
// Default connection timeout merged
assertEquals(1234, httpPost2.getConfig().getConnectTimeout());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project apn-proxy by apn-proxy.
the class TestProxyWithHttpClient method test.
private void test(String uri, int exceptCode, String exceptHeaderName, String exceptHeaderValue) {
ConnectionConfig connectionConfig = ConnectionConfig.custom().setCharset(Consts.UTF_8).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(2000);
cm.setDefaultMaxPerRoute(40);
cm.setDefaultConnectionConfig(connectionConfig);
CloseableHttpClient httpClient = HttpClients.custom().setUserAgent("Mozilla/5.0 xx-dev-web-common httpclient/4.x").setConnectionManager(cm).disableContentCompression().disableCookieManagement().build();
HttpHost proxy = new HttpHost("127.0.0.1", ApnProxyConfig.getConfig().getPort());
RequestConfig config = RequestConfig.custom().setProxy(proxy).setExpectContinueEnabled(true).setConnectionRequestTimeout(5000).setConnectTimeout(10000).setSocketTimeout(10000).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
HttpGet request = new HttpGet(uri);
request.setConfig(config);
try {
CloseableHttpResponse httpResponse = httpClient.execute(request);
Assert.assertEquals(exceptCode, httpResponse.getStatusLine().getStatusCode());
if (StringUtils.isNotBlank(exceptHeaderName) && StringUtils.isNotBlank(exceptHeaderValue)) {
Assert.assertEquals(exceptHeaderValue, httpResponse.getFirstHeader(exceptHeaderName).getValue());
}
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responseHandler.handleResponse(httpResponse);
httpResponse.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project felix by apache.
the class SessionHandlingTest method testSessionTimeout.
@Test
public void testSessionTimeout() throws Exception {
setupContext("test1", "/");
setupLatches(1);
setupServlet("foo", new String[] { "/foo" }, 1, "test1");
assertTrue(initLatch.await(5, TimeUnit.SECONDS));
RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BEST_MATCH).build();
final CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(globalConfig).setDefaultCookieStore(new BasicCookieStore()).build();
JsonObject json;
// session should not be available
// check for foo servlet
json = getJSONResponse(httpclient, "/foo");
assertFalse(json.getBoolean("session"));
// create session for context of servlet foo
// check session and timeout (should be 10 seconds)
json = getJSONResponse(httpclient, "/foo?create=true&timeout=true");
assertTrue(json.getBoolean("session"));
assertEquals("10", json.getString("timeout"));
final String sessionId1 = json.getString("sessionId");
assertNotNull(sessionId1);
// after four seconds the session should still be there
Thread.sleep(4000);
json = getJSONResponse(httpclient, "/foo");
assertTrue(json.getBoolean("session"));
assertEquals("10", json.getString("timeout"));
assertEquals(sessionId1, json.getString("sessionId"));
// wait 10 seconds, session should be gone
Thread.sleep(10000);
json = getJSONResponse(httpclient, "/foo");
assertFalse(json.getBoolean("session"));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project SEPA by arces-wot.
the class SPARQL11Protocol method update.
/**
* Implements a SPARQL 1.1 update operation
* (https://www.w3.org/TR/sparql11-protocol/)
*
* <pre>
* update via URL-encoded POST
* - HTTP Method: POST
* - Query String Parameters: None
* - Request Content Type: <b>application/x-www-form-urlencoded</b>
* - Request Message Body: URL-encoded, ampersand-separated query parameters. <b>update</b> (exactly 1). using-graph-uri (0 or more). using-named-graph-uri (0 or more)
*
* update via POST directly
* - HTTP Method: POST
* - Query String parameters: using-graph-uri (0 or more); using-named-graph-uri (0 or more)
* - Request Content Type: <b>application/sparql-update</b>
* - Request Message Body: Unencoded SPARQL update request string
* </pre>
*
* UPDATE 2.2 update operation The response to an update request indicates
* success or failure of the request via HTTP response status code.
*/
public Response update(UpdateRequest req, int timeout) {
StringEntity requestEntity = null;
CloseableHttpResponse httpResponse = null;
HttpEntity responseEntity = null;
int responseCode = 0;
String responseBody = null;
try {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build();
// Set request entity
if (properties.getQueryMethod().equals(HTTPMethod.GET)) {
// ***********************
// OpenLink VIRTUOSO PATCH
// ***********************
// SPARQL 1.1 Update are issued as GET requests using the "query" URL parameter
// The "default-graph-uri" parameter is REQUIRED
String query = "query=" + URLEncoder.encode(req.getSPARQL(), "UTF-8") + "&format=" + URLEncoder.encode(properties.getUpdateAcceptHeader(), "UTF-8");
if (properties.getDefaultGraphURI() != null) {
query += "&default-graph-uri=" + URLEncoder.encode(properties.getDefaultGraphURI(), "UTF-8");
}
String url;
if (properties.getHttpPort() != -1)
url = "http://" + properties.getHost() + ":" + properties.getHttpPort() + "/" + properties.getUpdatePath() + "?" + query;
else
url = "http://" + properties.getHost() + "/" + properties.getUpdatePath() + "?" + query;
HttpGet queryGetRequest;
queryGetRequest = new HttpGet(url);
queryGetRequest.setConfig(requestConfig);
updateRequest = queryGetRequest;
} else {
if (properties.getUpdateMethod().equals(HTTPMethod.URL_ENCODED_POST)) {
requestEntity = new StringEntity("update=" + URLEncoder.encode(req.getSPARQL(), "UTF-8"));
} else if (properties.getUpdateMethod().equals(HTTPMethod.POST)) {
requestEntity = new StringEntity(req.getSPARQL(), Consts.UTF_8);
}
updatePostRequest.setEntity(requestEntity);
updatePostRequest.setConfig(requestConfig);
updateRequest = updatePostRequest;
}
// Execute HTTP request
logger.debug("Execute SPARQL 1.1 QUERY (timeout: " + timeout + " ms) " + updatePostRequest.toString(), timeout);
long timing = System.nanoTime();
httpResponse = httpClient.execute(updateRequest);
timing = System.nanoTime() - timing;
logger.debug("UPDATE_TIME (" + timing / 1000000 + " ms)");
// Status code
responseCode = httpResponse.getStatusLine().getStatusCode();
// Body
responseEntity = httpResponse.getEntity();
responseBody = EntityUtils.toString(responseEntity, Charset.forName("UTF-8"));
EntityUtils.consume(responseEntity);
} catch (IOException e) {
return new ErrorResponse(req.getToken(), HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
} finally {
try {
if (httpResponse != null)
httpResponse.close();
} catch (IOException e) {
return new ErrorResponse(req.getToken(), HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
requestEntity = null;
responseEntity = null;
}
if (responseCode >= 400) {
try {
return new ErrorResponse(req.getToken(), new JsonParser().parse(responseBody).getAsJsonObject());
} catch (JsonParseException e) {
return new ErrorResponse(req.getToken(), responseCode, responseBody);
}
}
return new UpdateResponse(req.getToken(), responseBody);
}
Aggregations