Java Code Examples for java.net.Proxy.Type#SOCKS

The following examples show how to use java.net.Proxy.Type#SOCKS . 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: PollingStatusServiceImpl.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private Proxy getProxy(URI uri) {
  if (proxyService == null) {
    return Proxy.NO_PROXY;
  }
  IProxyData[] proxies = proxyService.select(uri);
  for (IProxyData proxyData : proxies) {
    switch (proxyData.getType()) {
      case IProxyData.HTTPS_PROXY_TYPE:
      case IProxyData.HTTP_PROXY_TYPE:
        return new Proxy(
            Type.HTTP, new InetSocketAddress(proxyData.getHost(), proxyData.getPort()));
      case IProxyData.SOCKS_PROXY_TYPE:
        return new Proxy(
            Type.SOCKS, new InetSocketAddress(proxyData.getHost(), proxyData.getPort()));
      default:
        logger.warning("Unknown proxy-data type: " + proxyData.getType()); //$NON-NLS-1$
        break;
    }
  }
  return Proxy.NO_PROXY;
}
 
Example 2
Source File: ProxyFactory.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public Proxy createProxy(URI uri) {
  Preconditions.checkNotNull(uri, "uri is null");
  Preconditions.checkArgument(!"http".equals(uri.getScheme()), "http is not a supported schema");

  IProxyService proxyServiceCopy = proxyService;
  if (proxyServiceCopy == null) {
    return Proxy.NO_PROXY;
  }

  IProxyData[] proxyDataForUri = proxyServiceCopy.select(uri);
  for (final IProxyData iProxyData : proxyDataForUri) {
    switch (iProxyData.getType()) {
      case IProxyData.HTTPS_PROXY_TYPE:
        return new Proxy(Type.HTTP, new InetSocketAddress(iProxyData.getHost(),
                                                          iProxyData.getPort()));
      case IProxyData.SOCKS_PROXY_TYPE:
        return new Proxy(Type.SOCKS, new InetSocketAddress(iProxyData.getHost(),
                                                           iProxyData.getPort()));
      default:
        logger.warning("Unsupported proxy type: " + iProxyData.getType());
        break;
    }
  }
  return Proxy.NO_PROXY;
}
 
Example 3
Source File: HttpClientService.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
private Proxy getProxyFromProxyData(IProxyData proxyData) throws UnknownHostException {
	
	Type proxyType;
	if (IProxyData.HTTP_PROXY_TYPE.equals(proxyData.getType())) {
		proxyType = Type.HTTP;
	} else if (IProxyData.SOCKS_PROXY_TYPE.equals(proxyData.getType())) {
		proxyType = Type.SOCKS;
	} else if (IProxyData.HTTPS_PROXY_TYPE.equals(proxyData.getType())) {
		proxyType = Type.HTTP;
	} else {
		throw new IllegalArgumentException("Invalid proxy type " + proxyData.getType());
	}

	InetSocketAddress sockAddr = new InetSocketAddress(InetAddress.getByName(proxyData.getHost()), proxyData.getPort());
	Proxy proxy = new Proxy(proxyType, sockAddr);
	if (!Strings.isNullOrEmpty(proxyData.getUserId())) {
		Authenticator.setDefault(new ProxyAuthenticator(proxyData.getUserId(), proxyData.getPassword()));  
	}
	return proxy;
}
 
Example 4
Source File: ProxyConfig.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
public Proxy toProxy() {
	if (hasValidProxySettings()) {
		switch (type) {
		case HTTP:
		case HTTPS:
			return new Proxy(Type.HTTP, new InetSocketAddress(host, port));
		case SOCKS:
			return new Proxy(Type.SOCKS, new InetSocketAddress(host, port));
		}
	}

	return null;
}
 
Example 5
Source File: RSSocketFactory.java    From Game with GNU General Public License v3.0 4 votes vote down vote up
private Socket open(Proxy proxy) throws IOException {
	try {
		if (proxy.type() != Type.DIRECT) {
			SocketAddress var3 = proxy.address();
			if (var3 instanceof InetSocketAddress) {
				InetSocketAddress var4 = (InetSocketAddress) var3;
				if (proxy.type() == Type.HTTP) {
					String var16 = null;

					try {
						Class<?> var6 = Class.forName("sun.net.www.protocol.http.AuthenticationInfo");
						Method var7 = var6.getDeclaredMethod("getProxyAuth",
							String.class, Integer.TYPE);
						var7.setAccessible(true);
						Object var8 = var7.invoke(null,
							var4.getHostName(), valueOf(var4.getPort()));
						if (null != var8) {
							Method var9 = var6.getDeclaredMethod("supportsPreemptiveAuthorization");
							var9.setAccessible(true);
							if ((Boolean) var9.invoke(var8, new Object[0])) {
								Method var10 = var6.getDeclaredMethod("getHeaderName");
								var10.setAccessible(true);
								Method var11 = var6.getDeclaredMethod("getHeaderValue",
									URL.class, String.class);
								var11.setAccessible(true);
								String var12 = (String) var10.invoke(var8, new Object[0]);
								String var13 = (String) var11.invoke(var8,
									new Object[]{new URL("https://" + this.socketHost + "/"), "https"});
								var16 = var12 + ": " + var13;
							}
						}
					} catch (Exception ignored) {
					}

					return this.openConnect(var4.getPort(), 1514, var16, var4.getHostName());
				} else if (proxy.type() != Type.SOCKS) {
					return null;
				} else {
					Socket var5 = new Socket(proxy);
					var5.connect(new InetSocketAddress(this.socketHost, this.socketPort));
					return var5;
				}
			} else {
				return null;
			}
		} else {
			return this.openRaw();
		}
	} catch (RuntimeException var15) {
		throw GenUtil.makeThrowable(var15,
			"gb.F(" + (proxy != null ? "{...}" : "null") + ',' + "dummy" + ')');
	}
}
 
Example 6
Source File: XMLHttpRequest.java    From proxyee-down with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
  URL u = new URL("http://www.baidu.com");
  Proxy proxy = new Proxy(Type.SOCKS, new InetSocketAddress("127.0.0.1", 1088));
  HttpURLConnection connection = (HttpURLConnection) u.openConnection(proxy);
  System.out.println(connection.getResponseCode());
}