List of usage examples for org.apache.http.conn HttpInetSocketAddress HttpInetSocketAddress
public HttpInetSocketAddress(final HttpHost httphost, final InetAddress addr, final int port)
From source file:orca.ektorp.client.ContextualSSLSocketFactory.java
/** * @deprecated Use {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)} * @param socket socket/* w w w .j a v a2 s .com*/ * @param host host * @param port port * @param localAddress local address * @param localPort local port * @param params HTTP params * @throws IOException in case of IO error * @throws UnknownHostException in case of unknonwn host * @throws ConnectTimeoutException in case of connect timeout * @return returns the socket */ @Deprecated public Socket connectSocket(final Socket socket, final String host, int port, final InetAddress localAddress, int localPort, final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { InetSocketAddress local = null; if (localAddress != null || localPort > 0) { // we need to bind explicitly if (localPort < 0) { localPort = 0; // indicates "any" } local = new InetSocketAddress(localAddress, localPort); } InetAddress remoteAddress; if (this.nameResolver != null) { remoteAddress = this.nameResolver.resolve(host); } else { remoteAddress = InetAddress.getByName(host); } InetSocketAddress remote = new HttpInetSocketAddress(new HttpHost(host, port), remoteAddress, port); return connectSocket(socket, remote, local, params); }
From source file:org.apache.http.impl.conn.DefaultClientConnectionOperator.java
public void openConnection(final OperatedClientConnection conn, final HttpHost target, final InetAddress local, final HttpContext context, final HttpParams params) throws IOException { Args.notNull(conn, "Connection"); Args.notNull(target, "Target host"); Args.notNull(params, "HTTP parameters"); Asserts.check(!conn.isOpen(), "Connection must not be open"); final SchemeRegistry registry = getSchemeRegistry(context); final Scheme schm = registry.getScheme(target.getSchemeName()); final SchemeSocketFactory sf = schm.getSchemeSocketFactory(); final InetAddress[] addresses = resolveHostname(target.getHostName()); final int port = schm.resolvePort(target.getPort()); for (int i = 0; i < addresses.length; i++) { final InetAddress address = addresses[i]; final boolean last = i == addresses.length - 1; Socket sock = sf.createSocket(params); conn.opening(sock, target);/*from www . ja v a 2 s .com*/ final InetSocketAddress remoteAddress = new HttpInetSocketAddress(target, address, port); InetSocketAddress localAddress = null; if (local != null) { localAddress = new InetSocketAddress(local, 0); } if (this.log.isDebugEnabled()) { this.log.debug("Connecting to " + remoteAddress); } try { final Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params); if (sock != connsock) { sock = connsock; conn.opening(sock, target); } prepareSocket(sock, context, params); conn.openCompleted(sf.isSecure(sock), params); return; } catch (final ConnectException ex) { if (last) { throw ex; } } catch (final ConnectTimeoutException ex) { if (last) { throw ex; } } if (this.log.isDebugEnabled()) { this.log.debug("Connect to " + remoteAddress + " timed out. " + "Connection will be retried using another IP address"); } } }