com.akdeniz.googleplaycrawler.Utils Java Examples

The following examples show how to use com.akdeniz.googleplaycrawler.Utils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayManager.java    From raccoon4 with Apache License 2.0 6 votes vote down vote up
/**
 * create a proxy client
 * 
 * @return either a client or null if none is configured
 * @throws KeyManagementException
 * @throws NumberFormatException
 *           if that port could not be parsed.
 * @throws NoSuchAlgorithmException
 */
private static HttpClient createProxyClient(PlayProfile profile)
		throws KeyManagementException, NoSuchAlgorithmException {
	if (profile.getProxyAddress() == null) {
		return null;
	}

	PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
			SchemeRegistryFactory.createDefault());
	connManager.setMaxTotal(100);
	connManager.setDefaultMaxPerRoute(30);

	DefaultHttpClient client = new DefaultHttpClient(connManager);
	client.getConnectionManager().getSchemeRegistry()
			.register(Utils.getMockedScheme());
	HttpHost proxy = new HttpHost(profile.getProxyAddress(),
			profile.getProxyPort());
	client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
	if (profile.getProxyUser() != null && profile.getProxyPassword() != null) {
		client.getCredentialsProvider().setCredentials(
				new AuthScope(proxy),
				new UsernamePasswordCredentials(profile.getProxyUser(), profile
						.getProxyPassword()));
	}
	return client;
}
 
Example #2
Source File: Archive.java    From Raccoon with Apache License 2.0 5 votes vote down vote up
/**
 * Get a proxy client, if it is configured.
 * 
 * @return either a client or null
 * @throws IOException
 *           if reading the config file fails
 * @throws KeyManagementException
 * @throws NumberFormatException
 *           if that port could not be parsed.
 * @throws NoSuchAlgorithmException
 */
public HttpClient getProxyClient() throws IOException, KeyManagementException,
		NoSuchAlgorithmException, NumberFormatException {
	File cfgfile = new File(root, NETCFG);
	if (cfgfile.exists()) {
		Properties cfg = new Properties();
		cfg.load(new FileInputStream(cfgfile));
		String ph = cfg.getProperty(PROXYHOST, null);
		String pp = cfg.getProperty(PROXYPORT, null);
		String pu = cfg.getProperty(PROXYUSER, null);
		String pw = cfg.getProperty(PROXYPASS, null);
		if (ph == null || pp == null) {
			return null;
		}
		PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
				SchemeRegistryFactory.createDefault());
		connManager.setMaxTotal(100);
		connManager.setDefaultMaxPerRoute(30);

		DefaultHttpClient client = new DefaultHttpClient(connManager);
		client.getConnectionManager().getSchemeRegistry().register(Utils.getMockedScheme());
		HttpHost proxy = new HttpHost(ph, Integer.parseInt(pp));
		client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
		if (pu != null && pw != null) {
			client.getCredentialsProvider().setCredentials(new AuthScope(proxy),
					new UsernamePasswordCredentials(pu, pw));
		}
		return client;
	}
	return null;
}