Package org.apache.http

Examples of org.apache.http.HttpHost


    }
    return PageFetchStatus.UnknownError;
  }

  public static void setProxy(String proxyHost, int proxyPort) {
    HttpHost proxy = new HttpHost(proxyHost, proxyPort);
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
  }
View Full Code Here


        }
       

        if (proxyProperties != null)
        {
            HttpHost proxy = new HttpHost(
                    proxyProperties.getProxyHostName(),
                    proxyProperties.getProxyPort());

          client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
View Full Code Here

     *
     * @return the HttpHost to be used as proxy
     */
    public static HttpHost getProxyHost() {
      if (!use) return null;
      return new HttpHost(host, port);
    }
View Full Code Here

    // for statistics same value should also be set here
    ConnectionInfo.setMaxcount(maxcon);
    // connections per host (2 default)
    clientConnectionManager.setDefaultMaxPerRoute(2);
    // Increase max connections for localhost
    final HttpHost localhost = new HttpHost("localhost");
    clientConnectionManager.setMaxForRoute(new HttpRoute(localhost), maxcon);
    /**
     * HTTP protocol settings
     */
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
View Full Code Here

     * this method sets a host on which more than the default of 2 router per host are allowed
     *
     * @param the host to be raised in 'route per host'
     */
    public static void setMaxRouteHost(final String host) {
      final HttpHost mHost = new HttpHost(host);
      ((ThreadSafeClientConnManager) httpClient.getConnectionManager()).setMaxForRoute(new HttpRoute(mHost), 50);
    }
View Full Code Here

    if (userPreferences.isProxyEnabled()) {
      // set up HTTP proxy
      final String proxyHostname = userPreferences.getProxyHostname();
      final int proxyPort = userPreferences.getProxyPort();

      final HttpHost proxy = new HttpHost(proxyHostname, proxyPort);
      httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

      if (userPreferences.isProxyAuthenticationEnabled()) {
        final AuthScope authScope = new AuthScope(proxyHostname, proxyPort);
        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
View Full Code Here

                Integer.valueOf((int) csPolicy.getReceiveTimeout()));
       
        Proxy p = proxyFactory.createProxy(csPolicy , uri);
        if (p != null) {
            InetSocketAddress isa = (InetSocketAddress)p.address();
            HttpHost proxy = new HttpHost(isa.getHostName(), isa.getPort());
            ConnRouteParams.setDefaultProxy(e.getParams(), proxy);
        }
        message.put(CXFHttpRequest.class, e);
    }
View Full Code Here

        }
    }

    public static void release(NHttpClientConnection conn) {

        HttpHost host = (HttpHost) conn.getContext().getAttribute(
            ExecutionContext.HTTP_TARGET_HOST);
        String key = host.getHostName() + ":" + Integer.toString(host.getPort());

        List connections = (List) connMap.get(key);
        if (connections == null) {
            synchronized(connMap) {
                // use double locking to make sure
                connections = (List) connMap.get(key);
                if (connections == null) {
                    connections = Collections.synchronizedList(new LinkedList());
                    connMap.put(key, connections);
                }
            }
        }

        cleanConnectionReferences(conn);
        connections.add(conn);

        if (log.isDebugEnabled()) {
            log.debug("Released a connection to host: " + host.getHostName() + " on port : " +
                    host.getPort() + " to the connection pool of current size : " + connections.size());
        }
    }
View Full Code Here

        conn.resetOutput();
    }

    public static void forget(NHttpClientConnection conn) {

        HttpHost host = (HttpHost) conn.getContext().getAttribute(
            ExecutionContext.HTTP_TARGET_HOST);
        String key = host.getHostName() + ":" + Integer.toString(host.getPort());

        List connections = (List) connMap.get(key);
        if (connections != null) {
            synchronized(connections) {
                connections.remove(conn);
View Full Code Here

        HttpRoute  route   = new HttpRoute(TARGET1, null, proxies, true,
                                           TunnelType.PLAIN, LayerType.PLAIN);
        assertEquals("A: hop count", 1, route.getHopCount());
        assertEquals("A: hop 0", TARGET1, route.getHopTarget(0));
        try {
            HttpHost beyond = route.getHopTarget(1);
            fail("A: hop 1 is " + beyond);
        } catch (IllegalArgumentException iax) {
            // expected
        }
        try {
            HttpHost before = route.getHopTarget(-1);
            fail("A: hop -1 is " + before);
        } catch (IllegalArgumentException iax) {
            // expected
        }


        proxies = new HttpHost[]{ PROXY3 };
        route   = new HttpRoute(TARGET1, LOCAL62, proxies, false,
                                TunnelType.TUNNELLED, LayerType.PLAIN);
        assertEquals("B: hop count", 2, route.getHopCount());
        assertEquals("B: hop 0", PROXY3, route.getHopTarget(0));
        assertEquals("B: hop 1", TARGET1, route.getHopTarget(1));
        try {
            HttpHost beyond = route.getHopTarget(2);
            fail("B: hop 2 is " + beyond);
        } catch (IllegalArgumentException iax) {
            // expected
        }
        try {
            HttpHost before = route.getHopTarget(-2);
            fail("B: hop -2 is " + before);
        } catch (IllegalArgumentException iax) {
            // expected
        }


        proxies = new HttpHost[]{ PROXY3, PROXY1, PROXY2 };
        route   = new HttpRoute(TARGET1, LOCAL42, proxies, false,
                                TunnelType.PLAIN, LayerType.LAYERED);
        assertEquals("C: hop count", 4, route.getHopCount());
        assertEquals("C: hop 0", PROXY3 , route.getHopTarget(0));
        assertEquals("C: hop 1", PROXY1 , route.getHopTarget(1));
        assertEquals("C: hop 2", PROXY2 , route.getHopTarget(2));
        assertEquals("C: hop 3", TARGET1, route.getHopTarget(3));
        try {
            HttpHost beyond = route.getHopTarget(4);
            fail("C: hop 4 is " + beyond);
        } catch (IllegalArgumentException iax) {
            // expected
        }
        try {
            HttpHost before = route.getHopTarget(Integer.MIN_VALUE);
            fail("C: hop -<min> is " + before);
        } catch (IllegalArgumentException iax) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.HttpHost

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.