List of usage examples for org.apache.http.conn.scheme SchemeSocketFactory isSecure
boolean isSecure(Socket sock) throws IllegalArgumentException;
From source file:com.subgraph.vega.internal.http.requests.connection.SocksModeClientConnectionOperator.java
@Override public void openConnection(OperatedClientConnection conn, HttpHost target, InetAddress local, HttpContext context, HttpParams params) throws IOException { if (!isSocksMode) { super.openConnection(conn, target, local, context, params); return;/*from w w w . ja v a 2 s. c o m*/ } final Scheme scheme = schemeRegistry.getScheme(target.getSchemeName()); final SchemeSocketFactory sf = scheme.getSchemeSocketFactory(); final int port = scheme.resolvePort(target.getPort()); Socket sock = sf.createSocket(params); conn.opening(sock, target); InetSocketAddress remoteAddress = InetSocketAddress.createUnresolved(target.getHostName(), port); InetSocketAddress localAddress = null; if (local != null) { localAddress = new InetSocketAddress(local, 0); } try { 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 (ConnectException ex) { throw new HttpHostConnectException(target, ex); } }
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);//w ww .ja v a 2s. co m 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"); } } }