當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。