本文整理汇总了Java中java.net.Proxy.type方法的典型用法代码示例。如果您正苦于以下问题:Java Proxy.type方法的具体用法?Java Proxy.type怎么用?Java Proxy.type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Proxy
的用法示例。
在下文中一共展示了Proxy.type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectSocket
import java.net.Proxy; //导入方法依赖的package包/类
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */
private void connectSocket(int connectTimeout, int readTimeout) throws IOException {
Proxy proxy = route.proxy();
Address address = route.address();
rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP
? address.socketFactory().createSocket()
: new Socket(proxy);
rawSocket.setSoTimeout(readTimeout);
try {
Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout);
} catch (ConnectException e) {
ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress());
ce.initCause(e);
throw ce;
}
source = Okio.buffer(Okio.source(rawSocket));
sink = Okio.buffer(Okio.sink(rawSocket));
}
示例2: nextProxy
import java.net.Proxy; //导入方法依赖的package包/类
/** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */
private Proxy nextProxy() {
// If the user specifies a proxy, try that and only that.
if (userSpecifiedProxy != null) {
hasNextProxy = false;
return userSpecifiedProxy;
}
// Try each of the ProxySelector choices until one connection succeeds. If none succeed
// then we'll try a direct connection below.
if (proxySelectorProxies != null) {
while (proxySelectorProxies.hasNext()) {
Proxy candidate = proxySelectorProxies.next();
if (candidate.type() != Proxy.Type.DIRECT) {
return candidate;
}
}
}
// Finally try a direct connection.
hasNextProxy = false;
return Proxy.NO_PROXY;
}
示例3: toString
import java.net.Proxy; //导入方法依赖的package包/类
static String toString(Proxy proxy) {
if (proxy == Proxy.NO_PROXY)
return "DIRECT";
// java.net.Proxy only knows about http and socks proxies.
Proxy.Type type = proxy.type();
switch (type) {
case HTTP:
return "PROXY " + proxy.address().toString();
case SOCKS:
return "SOCKS5 " + proxy.address().toString();
case DIRECT:
return "DIRECT";
default:
// If a new proxy type is supported in future, add a case to match it.
fail("Unknown proxy type" + type);
return "unknown://";
}
}
示例4: chooseProxy
import java.net.Proxy; //导入方法依赖的package包/类
private Proxy chooseProxy(final List<Proxy> proxies) {
Proxy result = null;
// check the list for one we can use
for (int i=0; (result == null) && (i < proxies.size()); i++) {
final Proxy p = proxies.get(i);
switch (p.type()) {
case DIRECT:
case HTTP:
result = p;
break;
case SOCKS:
// SOCKS hosts are not handled on the route level.
// The socket may make use of the SOCKS host though.
break;
}
}
if (result == null) {
//@@@ log as warning or info that only a socks proxy is available?
// result can only be null if all proxies are socks proxies
// socks proxies are not handled on the route planning level
result = Proxy.NO_PROXY;
}
return result;
}
示例5: resetNextInetSocketAddress
import java.net.Proxy; //导入方法依赖的package包/类
/** Prepares the socket addresses to attempt for the current proxy or host. */
private void resetNextInetSocketAddress(Proxy proxy) throws IOException {
// Clear the addresses. Necessary if getAllByName() below throws!
inetSocketAddresses = new ArrayList<>();
String socketHost;
int socketPort;
if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) {
socketHost = address.url().host();
socketPort = address.url().port();
} else {
SocketAddress proxyAddress = proxy.address();
if (!(proxyAddress instanceof InetSocketAddress)) {
throw new IllegalArgumentException(
"Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass());
}
InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
socketHost = getHostString(proxySocketAddress);
socketPort = proxySocketAddress.getPort();
}
if (socketPort < 1 || socketPort > 65535) {
throw new SocketException("No route to " + socketHost + ":" + socketPort
+ "; port is out of range");
}
if (proxy.type() == Proxy.Type.SOCKS) {
inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost, socketPort));
} else {
// Try each address for best behavior in mixed IPv4/IPv6 environments.
List<InetAddress> addresses = address.dns().lookup(socketHost);
for (int i = 0, size = addresses.size(); i < size; i++) {
InetAddress inetAddress = addresses.get(i);
inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort));
}
}
nextInetSocketAddressIndex = 0;
}
示例6: createSession
import java.net.Proxy; //导入方法依赖的package包/类
@Override
protected Session createSession (Host hc, String user, String host, int port, FS fs) throws JSchException {
Session session = super.createSession(hc, user, host, port, fs);
try {
List<Proxy> proxies = ProxySelector.getDefault().select(new URI("socket",
null,
host,
port == -1 ? 22 : port,
null, null, null));
if (proxies.size() > 0) {
Proxy p = proxies.iterator().next();
if (p.type() == Proxy.Type.DIRECT) {
session.setProxy(null);
} else {
SocketAddress addr = p.address();
if (addr instanceof InetSocketAddress) {
InetSocketAddress inetAddr = (InetSocketAddress) addr;
String proxyHost = inetAddr.getHostName();
int proxyPort = inetAddr.getPort();
session.setProxy(createProxy(proxyHost, proxyPort));
}
}
}
} catch (URISyntaxException ex) {
Logger.getLogger(JGitSshSessionFactory.class.getName()).log(Level.INFO, "Invalid URI: " + host + ":" + port, ex);
}
return session;
}
示例7: openConnection
import java.net.Proxy; //导入方法依赖的package包/类
@Override
public URLConnection openConnection(URL url, Proxy proxy) {
if (proxy.type() != Proxy.Type.DIRECT) {
throw new UnsupportedOperationException();
}
String protocol = url.getProtocol();
if ("http".equals(protocol) || "https".equals(protocol)) {
return new CronetHttpURLConnection(url, this);
}
throw new UnsupportedOperationException("Unexpected protocol:" + protocol);
}
示例8: chooseProxy
import java.net.Proxy; //导入方法依赖的package包/类
/**
* Chooses a proxy from a list of available proxies.
* The default implementation just picks the first non-SOCKS proxy
* from the list. If there are only SOCKS proxies,
* {@link Proxy#NO_PROXY Proxy.NO_PROXY} is returned.
* Derived classes may implement more advanced strategies,
* such as proxy rotation if there are multiple options.
*
* @param proxies the list of proxies to choose from,
* never <code>null</code> or empty
* @param target the planned target, never <code>null</code>
* @param request the request to be sent, never <code>null</code>
* @param context the context, or <code>null</code>
*
* @return a proxy type
*/
protected Proxy chooseProxy(final List<Proxy> proxies,
final HttpHost target,
final HttpRequest request,
final HttpContext context) {
Args.notEmpty(proxies, "List of proxies");
Proxy result = null;
// check the list for one we can use
for (int i=0; (result == null) && (i < proxies.size()); i++) {
final Proxy p = proxies.get(i);
switch (p.type()) {
case DIRECT:
case HTTP:
result = p;
break;
case SOCKS:
// SOCKS hosts are not handled on the route level.
// The socket may make use of the SOCKS host though.
break;
}
}
if (result == null) {
//@@@ log as warning or info that only a socks proxy is available?
// result can only be null if all proxies are socks proxies
// socks proxies are not handled on the route planning level
result = Proxy.NO_PROXY;
}
return result;
}
示例9: resetNextInetSocketAddress
import java.net.Proxy; //导入方法依赖的package包/类
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;
}
示例10: usingProxy
import java.net.Proxy; //导入方法依赖的package包/类
public final boolean usingProxy() {
Proxy proxy;
if (this.route != null) {
proxy = this.route.getProxy();
} else {
proxy = this.client.getProxy();
}
return (proxy == null || proxy.type() == Type.DIRECT) ? false : true;
}
示例11: getConnectToInetAddress
import java.net.Proxy; //导入方法依赖的package包/类
private InetAddress getConnectToInetAddress(Proxy proxy, HttpUrl url) throws IOException {
return (proxy != null && proxy.type() != Proxy.Type.DIRECT)
? ((InetSocketAddress) proxy.address()).getAddress()
: InetAddress.getByName(url.host());
}
示例12: getConnectToInetAddress
import java.net.Proxy; //导入方法依赖的package包/类
private InetAddress getConnectToInetAddress(Proxy proxy, URL url) throws IOException {
return (proxy != null && proxy.type() != Proxy.Type.DIRECT)
? ((InetSocketAddress) proxy.address()).getAddress()
: InetAddress.getByName(url.getHost());
}
示例13: HttpProxyAwareSocket
import java.net.Proxy; //导入方法依赖的package包/类
public HttpProxyAwareSocket(final Proxy proxy) {
super(proxy.type() == Proxy.Type.HTTP ? Proxy.NO_PROXY : proxy);
this.proxy = proxy;
}
示例14: ApplicationProxy
import java.net.Proxy; //导入方法依赖的package包/类
private ApplicationProxy(Proxy proxy) {
super(proxy.type(), proxy.address());
}
示例15: getConnectToInetAddress
import java.net.Proxy; //导入方法依赖的package包/类
private InetAddress getConnectToInetAddress(Proxy proxy, HttpUrl url) throws IOException {
if (proxy == null || proxy.type() == Type.DIRECT) {
return InetAddress.getByName(url.host());
}
return ((InetSocketAddress) proxy.address()).getAddress();
}