Package java.net

Examples of java.net.Proxy


    System.setProperty("socksProxyPort", String.valueOf(SOCKS_PROXY_PORT));

    List proxyList1 = selector.select(httpUri);
    assertNotNull(proxyList1);
    assertEquals(1, proxyList1.size());
    Proxy proxy1 = (Proxy) proxyList1.get(0);
    selector
        .connectFailed(httpUri, proxy1.address(), new SocketException());

    List proxyList2 = selector.select(httpUri);
    assertNotNull(proxyList2);
    assertEquals(1, proxyList2.size());
    Proxy proxy2 = (Proxy) proxyList2.get(0);
    // Default implemention doesn't change the proxy list
    assertEquals(proxy1, proxy2);
  }
View Full Code Here


   * "host","port".
   */
  private void assertProxyEquals(List selectedProxyList, Proxy.Type type,
      String host, int port) {
    SocketAddress sa = InetSocketAddress.createUnresolved(host, port);
    Proxy proxy = new Proxy(type, sa);
    assertProxyEquals(selectedProxyList, proxy);
  }
View Full Code Here

    /**
     * @tests java.net.Socket#bind(java.net.SocketAddress)
     */
    public void test_bindLjava_net_SocketAddress_Proxy() throws IOException {
        //The Proxy will not impact on the bind operation.It can be assigned with any address.
        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 0));
        Socket socket = new Socket(proxy);

        try {
            InetAddress address = InetAddress.getByName("localhost");
            int port = 0;
View Full Code Here

    SocketAddress addr1 = InetSocketAddress.createUnresolved("127.0.0.1",
        80);
    SocketAddress addr2 = new InetSocketAddress("localhost", 80);

    Proxy proxy1 = new Proxy(Proxy.Type.HTTP, addr1);
    // IllegalArgumentException test
    try {
      new Socket(proxy1);
      fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // expected
    }

    Proxy proxy2 = new Proxy(Proxy.Type.SOCKS, addr1);
    // should not throw any exception
    new Socket(proxy2);
    new Socket(Proxy.NO_PROXY);

    // SecurityException test
    SecurityManager originalSecurityManager = System.getSecurityManager();
    try {
      System.setSecurityManager(new MockSecurityManager());
    } catch (SecurityException e) {
      System.err
          .println("No permission to setSecurityManager, security related test in test_ConstructorLjava_net_Proxy_Security is ignored");
      return;
    }

    Proxy proxy3 = new Proxy(Proxy.Type.SOCKS, addr1);
    Proxy proxy4 = new Proxy(Proxy.Type.SOCKS, addr2);
    try {
      try {
        new Socket(proxy3);
        fail("should throw SecurityException");
      } catch (SecurityException e) {
View Full Code Here

    if (strs.length != 2)
      throw new RuntimeException("Bad SOCKS proxy parameter: " + proxyStr);
    String host = strs[0];
    int port = Integer.parseInt(strs[1]);
    this.proxy =
        new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved(host,
            port));
  }
View Full Code Here

     * Client Side Policy.
     *
     * @return The proxy server or null, if not set.
     */
    private Proxy getProxy(HTTPClientPolicy policy) {
        Proxy proxy = null;
        if (policy != null
            && policy.isSetProxyServer()
            && !StringUtils.isEmpty(policy.getProxyServer())) {
            proxy = new Proxy(
                    Proxy.Type.valueOf(policy.getProxyServerType().toString()),
                    new InetSocketAddress(policy.getProxyServer(),
                                          policy.getProxyServerPort()));
        }
        return proxy;
View Full Code Here

            throw new HttpException
                ("Cannot convert host to URI: " + target, usx);
        }
        List<Proxy> proxies = psel.select(targetURI);

        Proxy p = chooseProxy(proxies, target, request, context);

        HttpHost result = null;
        if (p.type() == Proxy.Type.HTTP) {
            // convert the socket address to an HttpHost
            if (!(p.address() instanceof InetSocketAddress)) {
                throw new HttpException
                    ("Unable to handle non-Inet proxy address: "+p.address());
            }
            final InetSocketAddress isa = (InetSocketAddress) p.address();
            // assume default scheme (http)
            result = new HttpHost(getHost(isa), isa.getPort());
        }

        return result;
View Full Code Here

        if ((proxies == null) || proxies.isEmpty()) {
            throw new IllegalArgumentException
                ("Proxy list must not be empty.");
        }

        Proxy result = null;

        // check the list for one we can use
        for (int i=0; (result == null) && (i < proxies.size()); i++) {

            Proxy p = proxies.get(i);
            switch (p.type()) {

            case DIRECT:
            case HTTP:
                result = p;
                break;
View Full Code Here

        });
        InetSocketAddress isa1 = new InetSocketAddress(ia, 11111);
        InetSocketAddress isa2 = new InetSocketAddress(ia, 22222);

        List<Proxy> proxies = new ArrayList<Proxy>(2);
        proxies.add(new Proxy(Proxy.Type.HTTP, isa1));
        proxies.add(new Proxy(Proxy.Type.HTTP, isa2));

        HttpRoutePlanner hrp =
            new ProxySelectorRoutePlanner(createSchemeRegistry(),
                                          new ProxySelectorMockup(proxies));
View Full Code Here

            throw new HttpException
                ("Cannot convert host to URI: " + target, usx);
        }
        List<Proxy> proxies = psel.select(targetURI);

        Proxy p = chooseProxy(proxies, target, request, context);

        HttpHost result = null;
        if (p.type() == Proxy.Type.HTTP) {
            // convert the socket address to an HttpHost
            if (!(p.address() instanceof InetSocketAddress)) {
                throw new HttpException
                    ("Unable to handle non-Inet proxy address: "+p.address());
            }
            final InetSocketAddress isa = (InetSocketAddress) p.address();
            // assume default scheme (http)
            result = new HttpHost(getHost(isa), isa.getPort());
        }

        return result;
View Full Code Here

TOP

Related Classes of java.net.Proxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.