本文整理汇总了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;
}
示例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)))));
}
}
}
示例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;
}
示例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;
}
示例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://");
}
}
示例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;
}
示例7: toType
Type toType(){
switch (this){
case SOCKS: return Type.SOCKS;
case HTTP: return Type.HTTP;
}
return Type.DIRECT;
}
示例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));
}
示例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));
}
示例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));
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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());
}