use of org.apache.http.impl.client.LaxRedirectStrategy in project Signal-Android by WhisperSystems.
the class LegacyMmsConnection method constructHttpClient.
protected CloseableHttpClient constructHttpClient() throws IOException {
RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000).setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build();
URL mmsc = new URL(apn.getMmsc());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
if (apn.hasAuthentication()) {
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()), new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
}
return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()).setRedirectStrategy(new LaxRedirectStrategy()).setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT)).setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config).setDefaultCredentialsProvider(credsProvider).build();
}
use of org.apache.http.impl.client.LaxRedirectStrategy in project opennms by OpenNMS.
the class HttpClientWrapper method getClient.
public CloseableHttpClient getClient() {
if (m_httpClient == null) {
final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (!m_reuseConnections) {
httpClientBuilder.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
}
if (m_usePreemptiveAuth) {
enablePreemptiveAuth(httpClientBuilder);
}
if (m_useSystemProxySettings) {
httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
}
if (!isEmpty(m_cookieSpec)) {
requestConfigBuilder.setCookieSpec(m_cookieSpec);
}
if (m_cookieStore != null) {
httpClientBuilder.setDefaultCookieStore(m_cookieStore);
}
if (m_username != null) {
setCredentials(httpClientBuilder, m_username, m_password);
}
if (m_socketTimeout != null) {
requestConfigBuilder.setSocketTimeout(m_socketTimeout);
}
if (m_connectionTimeout != null) {
requestConfigBuilder.setConnectTimeout(m_connectionTimeout);
}
if (m_retries != null) {
httpClientBuilder.setRetryHandler(new HttpRequestRetryOnExceptionHandler(m_retries, false));
}
if (m_sslContext.size() != 0) {
configureSSLContext(httpClientBuilder);
}
for (final HttpRequestInterceptor interceptor : m_requestInterceptors) {
httpClientBuilder.addInterceptorLast(interceptor);
}
for (final HttpResponseInterceptor interceptor : m_responseInterceptors) {
httpClientBuilder.addInterceptorLast(interceptor);
}
if (m_useLaxRedirect) {
httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
}
httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
m_httpClient = httpClientBuilder.build();
}
return m_httpClient;
}
use of org.apache.http.impl.client.LaxRedirectStrategy in project opennms by OpenNMS.
the class DiscoveryIT method canDiscoverRemoteNodes.
@Test
public void canDiscoverRemoteNodes() throws ClientProtocolException, IOException {
Date startOfTest = new Date();
final String tomcatIp = minionSystem.getContainerInfo(ContainerAlias.TOMCAT).networkSettings().ipAddress();
final InetSocketAddress opennmsHttp = minionSystem.getServiceAddress(ContainerAlias.OPENNMS, 8980);
final HttpHost opennmsHttpHost = new HttpHost(opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort());
HttpClient instance = HttpClientBuilder.create().setRedirectStrategy(// Ignore the 302 response to the POST
new LaxRedirectStrategy()).build();
Executor executor = Executor.newInstance(instance).auth(opennmsHttpHost, "admin", "admin").authPreemptive(opennmsHttpHost);
// Configure Discovery with the specific address of our Tomcat server
// No REST endpoint is currently available to configure the Discovery daemon
// so we resort to POSTin nasty form data
executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=AddSpecific", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("specificipaddress", tomcatIp).add("specifictimeout", "2000").add("specificretries", "1").add("initialsleeptime", "30000").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=SaveAndRestart", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("initialsleeptime", "1").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).toCriteria();
await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
}
use of org.apache.http.impl.client.LaxRedirectStrategy in project cloudstack by apache.
the class HttpClientHelper method createHttpClient.
public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration();
final BasicCookieStore cookieStore = new BasicCookieStore();
return HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)).setRedirectStrategy(new LaxRedirectStrategy()).setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).setMaxRedirects(maxRedirects).build()).setDefaultCookieStore(cookieStore).setRetryHandler(new StandardHttpRequestRetryHandler()).build();
}
Aggregations