use of org.apache.http.HttpHost in project ignition by mttkay.
the class IgnitedHttp method updateProxySettings.
/**
* Updates the underlying HTTP client's proxy settings with what the user has entered in the APN
* settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)}
* has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE}
* permission</b>.
*
* @param context
* the current context
*/
public void updateProxySettings(Context context) {
if (context == null) {
return;
}
HttpParams httpParams = httpClient.getParams();
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nwInfo = connectivity.getActiveNetworkInfo();
if (nwInfo == null) {
return;
}
Log.i(LOG_TAG, nwInfo.toString());
if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
String proxyHost = Proxy.getHost(context);
if (proxyHost == null) {
proxyHost = Proxy.getDefaultHost();
}
int proxyPort = Proxy.getPort(context);
if (proxyPort == -1) {
proxyPort = Proxy.getDefaultPort();
}
if (proxyHost != null && proxyPort > -1) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
} else {
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
}
} else {
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
}
}
use of org.apache.http.HttpHost in project goci by EBISPOT.
the class SolrQueryService method querySolr.
// public HttpEntity querySolr(String searchString) throws IOException{
public List<PublishedStudy> querySolr(String searchString) throws IOException {
System.out.println(searchString);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(searchString);
if (System.getProperty("http.proxyHost") != null) {
HttpHost proxy;
if (System.getProperty("http.proxyPort") != null) {
proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
} else {
proxy = new HttpHost(System.getProperty("http.proxyHost"));
}
httpGet.setConfig(RequestConfig.custom().setProxy(proxy).build());
}
// HttpEntity entity = null;
List<PublishedStudy> studies = new ArrayList<>();
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
getLog().debug("Received HTTP response: " + response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String output;
while ((output = br.readLine()) != null) {
SolrDataProcessingService jsonProcessor = new SolrDataProcessingService(output);
studies = jsonProcessor.processJson();
}
EntityUtils.consume(entity);
}
// return entity;
return studies;
}
use of org.apache.http.HttpHost in project goci by EBISPOT.
the class SolrSearchController method dispatchDownloadSearch.
private void dispatchDownloadSearch(String searchString, OutputStream outputStream, boolean efo, String facet, boolean ancestry) throws IOException {
getLog().trace(searchString);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(searchString);
if (System.getProperty("http.proxyHost") != null) {
HttpHost proxy;
if (System.getProperty("http.proxyPort") != null) {
proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
} else {
proxy = new HttpHost(System.getProperty("http.proxyHost"));
}
httpGet.setConfig(RequestConfig.custom().setProxy(proxy).build());
}
String file = null;
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
getLog().debug("Received HTTP response: " + response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String output;
while ((output = br.readLine()) != null) {
JsonProcessingService jsonProcessor = new JsonProcessingService(output, efo, facet, ancestry);
file = jsonProcessor.processJson();
}
EntityUtils.consume(entity);
}
if (file == null) {
//TO DO throw exception here and add error handler
file = "Some error occurred during your request. Please try again or contact the GWAS Catalog team for assistance";
}
PrintWriter outputWriter = new PrintWriter(outputStream);
outputWriter.write(file);
outputWriter.flush();
}
use of org.apache.http.HttpHost in project android_frameworks_base by ResurrectionRemix.
the class CookiesTest method testCookiesWithNonMatchingCase.
/**
* Test that cookies aren't case-sensitive with respect to hostname.
* http://b/3167208
*/
public void testCookiesWithNonMatchingCase() throws Exception {
// use a proxy so we can manipulate the origin server's host name
server = new MockWebServer();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
server.play();
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
getCookies.getEntity().consumeContent();
server.takeRequest();
HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
sendCookies.getEntity().consumeContent();
RecordedRequest sendCookiesRequest = server.takeRequest();
assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
use of org.apache.http.HttpHost 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));
}
Aggregations