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


Java Proxy.address方法代码示例

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


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

示例1: resetNextInetSocketAddress

import java.net.Proxy; //导入方法依赖的package包/类
/** Resets {@link #nextInetSocketAddress} to the first option. */
private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException {
  socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws!

  String socketHost;
  if (proxy.type() == Proxy.Type.DIRECT) {
    socketHost = uri.getHost();
    socketPort = getEffectivePort(uri);
  } 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 = proxySocketAddress.getHostName();
    socketPort = proxySocketAddress.getPort();
  }

  // Try each address for best behavior in mixed IPv4/IPv6 environments.
  socketAddresses = dns.getAllByName(socketHost);
  nextSocketAddressIndex = 0;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:24,代码来源:RouteSelector.java

示例2: authenticateProxy

import java.net.Proxy; //导入方法依赖的package包/类
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:19,代码来源:HttpAuthenticator.java

示例3: getProxyAddress

import java.net.Proxy; //导入方法依赖的package包/类
public static InetSocketAddress
 getProxyAddress(
InetSocketAddress	target )
 {
  Proxy p = proxy_selector.getSOCKSProxy( DEFAULT_SOCKS_SERVER_ADDRESS, target  );

  	// always use a proxy here as the calling code should know what it is doing...

  if ( p.type() == Proxy.Type.SOCKS ){

	  SocketAddress sa = p.address();

	  if ( sa instanceof InetSocketAddress ){

		  return((InetSocketAddress)sa);
	  }
  }

  return( DEFAULT_SOCKS_SERVER_ADDRESS );
 }
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:21,代码来源:ProxyLoginHandler.java

示例4: 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:RouteSelector.java

示例5: authenticate

import java.net.Proxy; //导入方法依赖的package包/类
@Override public Request authenticate(Route route, Response response) throws IOException {
  List<Challenge> challenges = response.challenges();
  Request request = response.request();
  HttpUrl url = request.url();
  boolean proxyAuthorization = response.code() == 407;
  Proxy proxy = route.proxy();

  for (int i = 0, size = challenges.size(); i < size; i++) {
    Challenge challenge = challenges.get(i);
    if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue;

    PasswordAuthentication auth;
    if (proxyAuthorization) {
      InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
      auth = java.net.Authenticator.requestPasswordAuthentication(
          proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
          url.scheme(), challenge.realm(), challenge.scheme(), url.url(),
          RequestorType.PROXY);
    } else {
      auth = java.net.Authenticator.requestPasswordAuthentication(
          url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(),
          challenge.realm(), challenge.scheme(), url.url(), RequestorType.SERVER);
    }

    if (auth != null) {
      String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword()));
      return request.newBuilder()
          .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential)
          .build();
    }
  }

  return null; // No challenges were satisfied!
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:JavaNetAuthenticator.java

示例6: getParameter

import java.net.Proxy; //导入方法依赖的package包/类
@Override public Object getParameter(String name) {
  if (name.equals(ConnRouteParams.DEFAULT_PROXY)) {
    Proxy proxy = client.proxy();
    if (proxy == null) {
      return null;
    }
    InetSocketAddress address = (InetSocketAddress) proxy.address();
    return new HttpHost(address.getHostName(), address.getPort());
  }
  throw new IllegalArgumentException(name);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:OkApacheClient.java

示例7: authenticate

import java.net.Proxy; //导入方法依赖的package包/类
@Override public Request authenticate(Route route, Response response) throws IOException {
  List<Challenge> challenges = response.challenges();
  Request request = response.request();
  HttpUrl url = request.url();
  boolean proxyAuthorization = response.code() == 407;
  Proxy proxy = route.proxy();

  for (int i = 0, size = challenges.size(); i < size; i++) {
    Challenge challenge = challenges.get(i);
    if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue;

    PasswordAuthentication auth;
    if (proxyAuthorization) {
      InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
      auth = java.net.Authenticator.requestPasswordAuthentication(
          proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
          url.scheme(), challenge.realm(), challenge.scheme(), url.url(),
          RequestorType.PROXY);
    } else {
      auth = java.net.Authenticator.requestPasswordAuthentication(
          url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(),
          challenge.realm(), challenge.scheme(), url.url(), RequestorType.SERVER);
    }

    if (auth != null) {
      String credential = Credentials.basic(
          auth.getUserName(), new String(auth.getPassword()), challenge.charset());
      return request.newBuilder()
          .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential)
          .build();
    }
  }

  return null; // No challenges were satisfied!
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:JavaNetAuthenticator.java

示例8: MyProxy

import java.net.Proxy; //导入方法依赖的package包/类
public MyProxy(Proxy proxy) {
    type = type2Type.get(proxy.type());
    
    final InetSocketAddress address = (InetSocketAddress) proxy.address();
    if (address != null) {
        host = address.getHostName();
        port = address.getPort();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:MyProxy.java

示例9: 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:JGitSshSessionFactory.java

示例10: getFirstProxy

import java.net.Proxy; //导入方法依赖的package包/类
static Proxy getFirstProxy(URL url) throws URISyntaxException {
    System.setProperty("java.net.useSystemProxies", "true");
    List<Proxy> proxylist = ProxySelector.getDefault().select(url.toURI());
    if (proxylist != null) {
        for (Proxy proxy : proxylist) {
            SocketAddress addr = proxy.address();
            if (addr != null) {
                return proxy;
            }
        }
    }
    return null;
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:14,代码来源:ProxyDetection.java

示例11: 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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:36,代码来源:RouteSelector.java

示例12: authenticateProxy

import java.net.Proxy; //导入方法依赖的package包/类
public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
    List<Challenge> challenges = response.challenges();
    Request request = response.request();
    HttpUrl url = request.httpUrl();
    int size = challenges.size();
    for (int i = 0; i < size; i++) {
        Challenge challenge = (Challenge) challenges.get(i);
        if ("Basic".equalsIgnoreCase(challenge.getScheme())) {
            InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
            PasswordAuthentication auth = java.net.Authenticator
                    .requestPasswordAuthentication(proxyAddress.getHostName(),
                            getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url
                                    .scheme(), challenge.getRealm(), challenge.getScheme(),
                            url.url(), RequestorType.PROXY);
            if (auth != null) {
                return request.newBuilder().header("Proxy-Authorization", Credentials.basic
                        (auth.getUserName(), new String(auth.getPassword()))).build();
            }
        }
    }
    return null;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:AuthenticatorAdapter.java

示例13: readHTTPImage

import java.net.Proxy; //导入方法依赖的package包/类
private static BufferedImage readHTTPImage(URI uri,
		HostConfiguration hostConfiguration, HttpClient client,
		ConnectionWrapper wrapper) {
	List<Proxy> list = ProxySelector.getDefault().select(uri);
	for (Proxy p : list)
	{
		InetSocketAddress addr = (InetSocketAddress) p.address();
		
		if (addr == null)
			hostConfiguration.setProxyHost(null);
		else
			hostConfiguration.setProxy(addr.getHostName(), addr.getPort());
		
		try {
			HttpMethod method = new GetMethod(uri.toString());
			synchronized (wrapper) {
				wrapper.connection = method;
			}
			
			int sc = client.executeMethod(hostConfiguration, method);
			
			if (sc != HttpStatus.SC_OK) {
				continue;
			}
			
			// Check Content Type
			Header h = method.getResponseHeader("Content-Type");
			if (h == null || !h.getValue().contains("image")) 
				continue;
			
			return ImageIO.read( method.getResponseBodyAsStream() );
		} catch (IOException ex) {
			continue;
		}
	}
	return null;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:38,代码来源:Tile512Overlay.java

示例14: 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 {
    eventListener.dnsStart(call, socketHost);

    // Try each address for best behavior in mixed IPv4/IPv6 environments.
    List<InetAddress> addresses = address.dns().lookup(socketHost);
    if (addresses.isEmpty()) {
      throw new UnknownHostException(address.dns() + " returned no addresses for " + socketHost);
    }

    eventListener.dnsEnd(call, socketHost, addresses);

    for (int i = 0, size = addresses.size(); i < size; i++) {
      InetAddress inetAddress = addresses.get(i);
      inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort));
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:46,代码来源:RouteSelector.java

示例15: ApplicationProxy

import java.net.Proxy; //导入方法依赖的package包/类
private ApplicationProxy(Proxy proxy) {
    super(proxy.type(), proxy.address());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:ApplicationProxy.java


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