当前位置: 首页>>代码示例>>Java>>正文


Java Type.SOCKS属性代码示例

本文整理汇总了Java中java.net.Proxy.Type.SOCKS属性的典型用法代码示例。如果您正苦于以下问题:Java Type.SOCKS属性的具体用法?Java Type.SOCKS怎么用?Java Type.SOCKS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.net.Proxy.Type的用法示例。


在下文中一共展示了Type.SOCKS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createProxy

@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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:26,代码来源:ProxyFactory.java

示例2: convert

protected void convert(String pacResult, List<Proxy> result) {
    Matcher m = PAC_RESULT_PATTERN.matcher(pacResult);
    while (m.find()) {
        String scriptProxyType = m.group(1);
        if ("DIRECT".equals(scriptProxyType)) {
            result.add(Proxy.NO_PROXY);
        } else {
            Type proxyType;
            if ("PROXY".equals(scriptProxyType)) {
                proxyType = Type.HTTP;
            } else if ("SOCKS".equals(scriptProxyType)) {
                proxyType = Type.SOCKS;
            } else {
                // Should never happen, already filtered by Pattern.
                throw new RuntimeException("Unrecognized proxy type.");
            }
            result.add(new Proxy(proxyType, new InetSocketAddress(m
                    .group(2), Integer.parseInt(m.group(3)))));
        }
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:21,代码来源:PacProxySelector.java

示例3: getProxyFromProxyData

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;
}
 
开发者ID:kwin,项目名称:cppcheclipse,代码行数:20,代码来源:HttpClientService.java

示例4: createSocket

public Socket createSocket(String host, int port) throws IOException,
        UnknownHostException {
    String socksHost = System.getProperty("socksProxyHost");
    Socket s;
    InetSocketAddress addr = new InetSocketAddress(host, port);
    if (socksHost != null) {
        Proxy proxy = new Proxy(Type.SOCKS, new InetSocketAddress(
                socksHost, 1080));
        s = new Socket(proxy);
        s.connect(addr);
    } else {
        log.error(addr);
        SocketChannel sc = SocketChannel.open(addr);
        s = sc.socket();
    }
    s.setTcpNoDelay(true);
    return s;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:18,代码来源:SSHSocketImplFactory.java

示例5: shouldPipeline

private boolean shouldPipeline()
{
    if (!this.pipeline)
    {
        return false;
    }
    else
    {
        Proxy proxy = Minecraft.getMinecraft().getProxy();
        return proxy.type() != Type.DIRECT && proxy.type() != Type.SOCKS ? false : this.imageUrl.startsWith("http://");
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:12,代码来源:ThreadDownloadImageData.java

示例6: resetNextInetSocketAddress

private void resetNextInetSocketAddress(Proxy proxy) throws IOException {
    String socketHost;
    int socketPort;
    this.inetSocketAddresses = new ArrayList();
    if (proxy.type() == Type.DIRECT || proxy.type() == Type.SOCKS) {
        socketHost = this.address.getUriHost();
        socketPort = this.address.getUriPort();
    } else {
        SocketAddress proxyAddress = proxy.address();
        if (proxyAddress instanceof InetSocketAddress) {
            InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
            socketHost = getHostString(proxySocketAddress);
            socketPort = proxySocketAddress.getPort();
        } else {
            throw new IllegalArgumentException("Proxy.address() is not an InetSocketAddress: " +
                    "" + proxyAddress.getClass());
        }
    }
    if (socketPort < 1 || socketPort > 65535) {
        throw new SocketException("No route to " + socketHost + ":" + socketPort + "; port is" +
                " out of range");
    }
    if (proxy.type() == Type.SOCKS) {
        this.inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost,
                socketPort));
    } else {
        List<InetAddress> addresses = this.address.getDns().lookup(socketHost);
        int size = addresses.size();
        for (int i = 0; i < size; i++) {
            this.inetSocketAddresses.add(new InetSocketAddress((InetAddress) addresses.get(i)
                    , socketPort));
        }
    }
    this.nextInetSocketAddressIndex = 0;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:35,代码来源:RouteSelector.java

示例7: toType

Type toType(){
    switch (this){
        case SOCKS: return Type.SOCKS;
        case HTTP: return Type.HTTP;
    }
    return  Type.DIRECT;
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:7,代码来源:HTTPProxy.java

示例8: testHttpsResponseFromBrowser

@Test
public void testHttpsResponseFromBrowser() throws URISyntaxException {
    proxySelector.setBrowserResponse(new URI("https://" + PROXY_HOST + ":" + PROXY_PORT));

    List<Proxy> result = proxySelector.select(new URI("https://example.org"));

    // FIXME if a browser returns a https URI, that does not mean socks
    Proxy expectedProxy = new Proxy(Type.SOCKS, new InetSocketAddress(PROXY_HOST, PROXY_PORT));

    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(expectedProxy, result.get(0));
}
 
开发者ID:GITNE,项目名称:icedtea-web,代码行数:13,代码来源:PluginProxySelectorTest.java

示例9: testFtpResponseFromBrowser

@Test
public void testFtpResponseFromBrowser() throws URISyntaxException {
    proxySelector.setBrowserResponse(new URI("ftp://" + PROXY_HOST + ":" + PROXY_PORT));

    List<Proxy> result = proxySelector.select(new URI("ftp://example.org"));

    // FIXME if a browser returns a ftp URI, that doesn't mean socks
    Proxy expectedProxy = new Proxy(Type.SOCKS, new InetSocketAddress(PROXY_HOST, PROXY_PORT));

    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(expectedProxy, result.get(0));
}
 
开发者ID:GITNE,项目名称:icedtea-web,代码行数:13,代码来源:PluginProxySelectorTest.java

示例10: testSocketResponseFromBrowser

@Test
public void testSocketResponseFromBrowser() throws URISyntaxException {
    TestSelector proxySelector = new TestSelector(config);

    // TODO does firefox actually return a "socks" URI? or a "socket" uri?
    proxySelector.setBrowserResponse(new URI("socks://" + PROXY_HOST + ":" + PROXY_PORT));

    List<Proxy> result = proxySelector.select(new URI("socket://example.org"));

    Proxy expectedProxy = new Proxy(Type.SOCKS, new InetSocketAddress(PROXY_HOST, PROXY_PORT));

    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(expectedProxy, result.get(0));
}
 
开发者ID:GITNE,项目名称:icedtea-web,代码行数:15,代码来源:PluginProxySelectorTest.java

示例11: select

@Override
public List<Proxy> select(URI uri) {
    Proxy proxy;
    switch(proxyPolicy) {
    case USE_SYSTEM_SETTINGS:
        if (!JVM_WILL_USE_SYSTEM_PROXIES) {
            System.err.println("Warning: the JVM is not configured to lookup proxies from the system settings. The property ''java.net.useSystemProxies'' was missing at startup time.  Will not use a proxy."); //$NON-NLS-1$
            return Collections.singletonList(Proxy.NO_PROXY);
        }
        // delegate to the former proxy selector
        List<Proxy> ret = delegate.select(uri);
        return ret;
    case NO_PROXY:
        return Collections.singletonList(Proxy.NO_PROXY);
    case USE_HTTP_PROXY:
        if (httpProxySocketAddress == null)
            return Collections.singletonList(Proxy.NO_PROXY);
        proxy = new Proxy(Type.HTTP, httpProxySocketAddress);
        return Collections.singletonList(proxy);
    case USE_SOCKS_PROXY:
        if (socksProxySocketAddress == null)
            return Collections.singletonList(Proxy.NO_PROXY);
        proxy = new Proxy(Type.SOCKS, socksProxySocketAddress);
        return Collections.singletonList(proxy);
    }
    // should not happen
    return null;
}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:28,代码来源:DefaultProxySelector.java

示例12: newClient

public Client newClient(Connection connection) throws TTransportException, IOException {
  String host = connection.getHost();
  int port = connection.getPort();

  TProtocol proto;
  Socket socket;
  int timeout = connection.getTimeout();
  if (SaslHelper.isSaslEnabled(_configuration)) {
    if (connection.isProxy()) {
      throw new IOException("Proxy connections are not allowed when SASL is enabled.");
    }
    TSocket transport = new TSocket(host, port, timeout);
    TTransport tSaslClientTransport = SaslHelper.getTSaslClientTransport(_configuration, transport);
    tSaslClientTransport.open();
    socket = transport.getSocket();
    proto = new TCompactProtocol(tSaslClientTransport);
  } else {
    if (connection.isProxy()) {
      Proxy proxy = new Proxy(Type.SOCKS, new InetSocketAddress(connection.getProxyHost(), connection.getProxyPort()));
      socket = new Socket(proxy);
    } else {
      socket = new Socket();
    }
    socket.setTcpNoDelay(true);
    socket.setSoTimeout(timeout);
    socket.connect(new InetSocketAddress(host, port), timeout);
    TSocket trans = new TSocket(socket);
    proto = new TBinaryProtocol(new TFramedTransport(trans, _maxFrameSize));
  }
  return new WeightedClient(proto, getIdentifer(socket));
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:31,代码来源:ClientPool.java

示例13: toProxy

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;
}
 
开发者ID:3dcitydb,项目名称:importer-exporter,代码行数:13,代码来源:ProxyConfig.java

示例14: toProxy

@Override
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;
}
 
开发者ID:3dcitydb,项目名称:importer-exporter-oracle,代码行数:14,代码来源:ProxyConfigImpl.java

示例15: getProxy

public static Proxy getProxy(ProxyBean proxy) throws UnknownHostException, IOException {
	if (proxy == null)
		return null;
	
	return new Proxy(proxy.getType().equals(ProxyBean.HTTP_PROXY) ? Type.HTTP : Type.SOCKS, proxy.getUrl(), proxy.getPort(), proxy.getUser(), proxy.getPassword());
}
 
开发者ID:michellemulkey,项目名称:aTunes,代码行数:6,代码来源:NetworkUtils.java


注:本文中的java.net.Proxy.Type.SOCKS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。