List of usage examples for org.apache.http.conn.params ConnRouteParams getDefaultProxy
public static HttpHost getDefaultProxy(final HttpParams params)
From source file:com.puppetlabs.geppetto.injectable.eclipse.impl.ProxiedRoutePlanner.java
@Override public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException { if (request == null) { throw new IllegalStateException("Request must not be null."); }/* ww w . j a v a 2 s.c o m*/ // If we have a forced route, we can do without a target. HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams()); if (route != null) return route; // If we get here, there is no forced route. // So we need a target to compute a route. if (target == null) { throw new IllegalStateException("Target host must not be null."); } final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams()); final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams()); final Scheme schm; try { schm = schemeRegistry.getScheme(target.getSchemeName()); } catch (IllegalStateException ex) { throw new HttpException(ex.getMessage()); } // as it is typically used for TLS/SSL, we assume that // a layered scheme implies a secure connection final boolean secure = schm.isLayered(); if (proxy != null) return new HttpRoute(target, local, proxy, secure); IProxyData[] select = Activator.getInstance().getProxyService().select(URI.create(target.toURI())); for (IProxyData proxyData : select) if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { HttpHost proxyHost = new HttpHost(proxyData.getHost(), proxyData.getPort()); return new HttpRoute(target, null, proxyHost, secure); } return new HttpRoute(target, local, secure); }
From source file:nya.miku.wishmaster.http.recaptcha.RecaptchaAjax.java
static String getChallenge(String key, CancellableTask task, HttpClient httpClient, String scheme) throws Exception { if (sHandler == null) throw new Exception("handler == null (not initialized in UI thread)"); if (scheme == null) scheme = "http"; String address = scheme + "://127.0.0.1/"; String data = "<script type=\"text/javascript\"> " + "var RecaptchaOptions = { " + "theme : 'custom', " + "custom_theme_widget: 'recaptcha_widget' " + "}; " + "</script>" + "<div id=\"recaptcha_widget\" style=\"display:none\"> " + "<div id=\"recaptcha_image\"></div> " + "<input type=\"text\" id=\"recaptcha_response_field\" name=\"recaptcha_response_field\" /> " + "</div>" + "<script type=\"text/javascript\" src=\"" + scheme + "://www.google.com/recaptcha/api/challenge?k=" + key + "\"></script>"; HttpHost proxy = null;/* w w w. j a v a 2s . c om*/ if (httpClient instanceof ExtendedHttpClient) { proxy = ((ExtendedHttpClient) httpClient).getProxy(); } else if (httpClient != null) { try { proxy = ConnRouteParams.getDefaultProxy(httpClient.getParams()); } catch (Exception e) { /*ignore*/ } } if (proxy != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { return Intercepting.getInternal(address, data, task, httpClient); } else { return getChallengeInternal(address, data, task, proxy); } }
From source file:org.sonatype.nexus.error.reporting.NexusPRConnectorTest.java
@Test public void testProxyEnabled() { final String host = "host"; final int port = 1234; when(proxySettings.isEnabled()).thenReturn(true); when(proxySettings.getHostname()).thenReturn(host); when(proxySettings.getPort()).thenReturn(port); assertThat(ConnRouteParams.getDefaultProxy(underTest.client().getParams()), notNullValue()); }
From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java
/** * -? cloudflare//w w w . j av a2 s.com * @param exception Cloudflare ? * @param httpClient HTTP * @param task ?? * @param activity ?, ? WebView (webkit) * @return ? cookie null, ? , */ public Cookie checkAntiDDOS(CloudflareException exception, HttpClient httpClient, CancellableTask task, Activity activity) { if (exception.isRecaptcha()) throw new IllegalArgumentException(); HttpHost proxy = null; if (httpClient instanceof ExtendedHttpClient) { proxy = ((ExtendedHttpClient) httpClient).getProxy(); } else if (httpClient != null) { try { proxy = ConnRouteParams.getDefaultProxy(httpClient.getParams()); } catch (Exception e) { /*ignore*/ } } if (proxy != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (httpClient instanceof ExtendedHttpClient) { return InterceptingAntiDDOS.getInstance().check(exception, (ExtendedHttpClient) httpClient, task, activity); } else { throw new IllegalArgumentException( "cannot run anti-DDOS checking with proxy settings; http client is not instance of ExtendedHttpClient"); } } else { return checkAntiDDOS(exception, proxy, task, activity); } }
From source file:org.sonatype.nexus.error.reporting.NexusPRConnectorTest.java
@Test public void testProxyAuth() { final String host = "host"; final int port = 1234; when(proxySettings.isEnabled()).thenReturn(true); when(proxySettings.getHostname()).thenReturn(host); when(proxySettings.getPort()).thenReturn(port); when(proxySettings.getProxyAuthentication()).thenReturn(proxyAuth); when(proxyAuth.getUsername()).thenReturn("user"); when(proxyAuth.getPassword()).thenReturn("pass"); final HttpClient client = underTest.client(); final HttpParams params = client.getParams(); assertThat(ConnRouteParams.getDefaultProxy(params), notNullValue()); assertThat(params.getParameter(AuthPNames.PROXY_AUTH_PREF), notNullValue()); assertThat(((DefaultHttpClient) client).getCredentialsProvider().getCredentials(new AuthScope(host, port)), notNullValue());// w w w . java 2 s .c o m }
From source file:org.sonatype.nexus.error.reporting.NexusPRConnectorTest.java
@Test public void testProxyReconfigure() { final String host = "host"; final int port = 1234; when(proxySettings.isEnabled()).thenReturn(true); when(proxySettings.getHostname()).thenReturn(host); when(proxySettings.getPort()).thenReturn(port); DefaultHttpClient client = (DefaultHttpClient) underTest.client(); HttpParams params = client.getParams(); assertThat(ConnRouteParams.getDefaultProxy(params), notNullValue()); assertThat(params.getParameter(AuthPNames.PROXY_AUTH_PREF), nullValue()); assertThat(client.getCredentialsProvider().getCredentials(new AuthScope(host, port)), nullValue()); when(proxySettings.getProxyAuthentication()).thenReturn(proxyAuth); when(proxyAuth.getUsername()).thenReturn("user"); when(proxyAuth.getPassword()).thenReturn("pass"); final DefaultHttpClient reconfigured = (DefaultHttpClient) underTest.client(); params = reconfigured.getParams();/* w ww . j a v a2 s. co m*/ assertThat(reconfigured, equalTo(client)); assertThat(ConnRouteParams.getDefaultProxy(params), notNullValue()); assertThat(params.getParameter(AuthPNames.PROXY_AUTH_PREF), notNullValue()); assertThat(reconfigured.getCredentialsProvider().getCredentials(new AuthScope(host, port)), notNullValue()); }
From source file:org.sonatype.nexus.error.reporting.NexusPRConnectorTest.java
@Test public void testNonProxyHosts() throws HttpException { final String host = "host"; final int port = 1234; when(proxySettings.isEnabled()).thenReturn(true); when(proxySettings.getHostname()).thenReturn(host); when(proxySettings.getPort()).thenReturn(port); when(proxySettings.getNonProxyHosts()).thenReturn(Sets.newHashSet(".*")); final DefaultHttpClient client = (DefaultHttpClient) underTest.client(); assertThat(ConnRouteParams.getDefaultProxy(client.getParams()), notNullValue()); final HttpRoutePlanner planner = client.getRoutePlanner(); final HttpRequest request = mock(HttpRequest.class); when(request.getParams()).thenReturn(mock(HttpParams.class)); planner.determineRoute(new HttpHost("host"), request, mock(HttpContext.class)); ArgumentCaptor<HttpParams> captor = ArgumentCaptor.forClass(HttpParams.class); verify(request).setParams(captor.capture()); assertThat(ConnRouteParams.getDefaultProxy(captor.getValue()), nullValue()); }