/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never <code>null</code> * * @throws IllegalStateException * if the scheme with the given name is not registered */ public synchronized final Scheme getScheme(String name) { Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never {@code null} * * @throws IllegalStateException * if the scheme with the given name is not registered */ public final Scheme getScheme(final String name) { final Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never {@code null} * * @throws IllegalStateException * if the scheme with the given name is not registered */ public final Scheme getScheme(final String name) { final Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never <code>null</code> * * @throws IllegalStateException * if the scheme with the given name is not registered */ public synchronized final Scheme getScheme(String name) { Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never {@code null} * * @throws IllegalStateException * if the scheme with the given name is not registered */ public final Scheme getScheme(final String name) { final Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never {@code null} * * @throws IllegalStateException * if the scheme with the given name is not registered */ public final Scheme getScheme(final String name) { final Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never <code>null</code> * * @throws IllegalStateException * if the scheme with the given name is not registered */ public synchronized final Scheme getScheme(String name) { Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never <code>null</code> * * @throws IllegalStateException * if the scheme with the given name is not registered */ public synchronized final Scheme getScheme(String name) { Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never {@code null} * * @throws IllegalStateException * if the scheme with the given name is not registered */ public final Scheme getScheme(final String name) { final Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never <code>null</code> * * @throws IllegalStateException * if the scheme with the given name is not registered */ public final Scheme getScheme(final String name) { final Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
/** * Obtains a scheme by name. * * @param name the name of the scheme to look up (in lowercase) * * @return the scheme, never <code>null</code> * * @throws IllegalStateException * if the scheme with the given name is not registered */ public synchronized final Scheme getScheme(String name) { Scheme found = get(name); if (found == null) { throw new IllegalStateException ("Scheme '"+name+"' not registered."); } return found; }
public static void setHostNameVerifier(DefaultHttpClient httpClient, X509HostnameVerifier hostNameVerifier) { Scheme httpsScheme = httpClient.getConnectionManager().getSchemeRegistry().get("https"); if (httpsScheme != null) { SSLSocketFactory sslSocketFactory = (SSLSocketFactory) httpsScheme.getSchemeSocketFactory(); sslSocketFactory.setHostnameVerifier(hostNameVerifier); } }
@Override public WebResponse getResponse(final WebRequest request) throws IOException { String protocol = request.getUrl().getProtocol(); // Default web response is retrieved using commons HttpClient. // It assumes HttpClient created internally by HtmlUnit is using the // default registry. We check for supported schemes by the default // registry. boolean canHandle = SchemeRegistryFactory.createDefault() .get(protocol) != null; if (!canHandle) { // For unsupported schemes, it tries to read the response using // native URL connection. String data = ResourceUtils.readAsText(request.getUrl()); return new StringWebResponse(data, request.getUrl()); } return super.getResponse(request); } };
protected HttpClient createHttpClient() { DefaultHttpClient client = new DefaultHttpClient(createClientConnectionManager()); if (useCompression) { client.addRequestInterceptor( new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) { // We expect to received a compression response that we un-gzip request.addHeader("Accept-Encoding", "gzip"); } }); } if (getProxyHost() != null) { HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (client.getConnectionManager().getSchemeRegistry().get("http") == null) { client.getConnectionManager().getSchemeRegistry().register( new Scheme("http", getProxyPort(), PlainSocketFactory.getSocketFactory())); } if(getProxyUser() != null && getProxyPassword() != null) { client.getCredentialsProvider().setCredentials( new AuthScope(getProxyHost(), getProxyPort()), new UsernamePasswordCredentials(getProxyUser(), getProxyPassword())); } } HttpParams params = client.getParams(); HttpConnectionParams.setSoTimeout(params, soTimeout); HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY); return client; }
protected HttpClient createHttpClient() { DefaultHttpClient client = new DefaultHttpClient(createClientConnectionManager()); if (useCompression) { client.addRequestInterceptor( new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) { // We expect to received a compression response that we un-gzip request.addHeader("Accept-Encoding", "gzip"); } }); } if (getProxyHost() != null) { HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (client.getConnectionManager().getSchemeRegistry().get("http") == null) { client.getConnectionManager().getSchemeRegistry().register( new Scheme("http", getProxyPort(), PlainSocketFactory.getSocketFactory())); } if(getProxyUser() != null && getProxyPassword() != null) { client.getCredentialsProvider().setCredentials( new AuthScope(getProxyHost(), getProxyPort()), new UsernamePasswordCredentials(getProxyUser(), getProxyPassword())); } } HttpParams params = client.getParams(); HttpConnectionParams.setSoTimeout(params, soTimeout); HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY); return client; }
protected HttpClient createHttpClient() { DefaultHttpClient client = new DefaultHttpClient(createClientConnectionManager()); if (useCompression) { client.addRequestInterceptor( new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) { // We expect to received a compression response that we un-gzip request.addHeader("Accept-Encoding", "gzip"); } }); } if (getProxyHost() != null) { HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (client.getConnectionManager().getSchemeRegistry().get("http") == null) { client.getConnectionManager().getSchemeRegistry().register( new Scheme("http", getProxyPort(), PlainSocketFactory.getSocketFactory())); } if(getProxyUser() != null && getProxyPassword() != null) { client.getCredentialsProvider().setCredentials( new AuthScope(getProxyHost(), getProxyPort()), new UsernamePasswordCredentials(getProxyUser(), getProxyPassword())); } } HttpParams params = client.getParams(); HttpConnectionParams.setSoTimeout(params, soTimeout); HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY); return client; }