List of usage examples for org.apache.http.conn HttpHostConnectException HttpHostConnectException
@Deprecated public HttpHostConnectException(final HttpHost host, final ConnectException cause)
From source file:bad.robot.http.apache.ApacheExceptionWrappingExecutorTest.java
@Test public void wrapsConnectException() { exception.expect(HttpConnectionRefusedException.class); exception.expect(new ThrowableCauseMatcher(HttpHostConnectException.class)); wrapper.submit(// ww w .ja va2 s.c o m throwsException(new HttpHostConnectException(new HttpHost("localhost"), new ConnectException()))); }
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 ww . j a va2s.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:com.qiniu.android.http.ClientConnectionOperator.java
public void openConnection(final OperatedClientConnection conn, final HttpHost target, final InetAddress local, final HttpContext context, final HttpParams params) throws IOException { if (conn == null) { throw new IllegalArgumentException("Connection must not be null."); }/* w w w . j ava 2 s.c om*/ if (target == null) { throw new IllegalArgumentException("Target host must not be null."); } // local address may be null //@@@ is context allowed to be null? if (params == null) { throw new IllegalArgumentException("Parameters must not be null."); } if (conn.isOpen()) { throw new IllegalArgumentException("Connection must not be open."); } final Scheme schm = schemeRegistry.getScheme(target.getSchemeName()); final SocketFactory sf = schm.getSocketFactory(); String host = target.getHostName(); String[] ips; if (validIP(host)) { ips = new String[] { host }; } else { ips = systemResolv(host); if (ips == null || ips.length == 0) { throw new UnknownHostException("no ip for " + host); } } final int port = schm.resolvePort(target.getPort()); for (int i = 0; i < ips.length; i++) { final String ip = ips[i]; final boolean last = i == ips.length - 1; Socket sock = sf.createSocket(); conn.opening(sock, target); try { Socket connsock = sf.connectSocket(sock, ip, port, local, 0, params); if (sock != connsock) { sock = connsock; conn.opening(sock, target); } prepareSocket(sock, context, params); conn.openCompleted(sf.isSecure(sock), params); AsyncHttpClientMod.ip.set(ip); return; } catch (ConnectException ex) { if (last) { throw new HttpHostConnectException(target, ex); } } } }
From source file:com.android.mms.service.http.NetworkAwareClientConnectionOperator.java
/** * This method is mostly copied from the overridden one in parent. The only change * is how we resolve host name.//from w ww . j a va 2s. c o m */ @Override public void openConnection(OperatedClientConnection conn, HttpHost target, InetAddress local, HttpContext context, HttpParams params) throws IOException { if (conn == null) { throw new IllegalArgumentException("Connection must not be null."); } if (target == null) { throw new IllegalArgumentException("Target host must not be null."); } // local address may be null //@@@ is context allowed to be null? if (params == null) { throw new IllegalArgumentException("Parameters must not be null."); } if (conn.isOpen()) { throw new IllegalArgumentException("Connection must not be open."); } final Scheme schm = schemeRegistry.getScheme(target.getSchemeName()); final SocketFactory sf = schm.getSocketFactory(); final SocketFactory plain_sf; final LayeredSocketFactory layered_sf; if (sf instanceof LayeredSocketFactory) { plain_sf = staticPlainSocketFactory; layered_sf = (LayeredSocketFactory) sf; } else { plain_sf = sf; layered_sf = null; } // CHANGE FOR MmsService ArrayList<InetAddress> addresses = resolveHostName(target.getHostName()); for (int i = 0; i < addresses.size(); ++i) { Log.d(TAG, "NetworkAwareClientConnectionOperator: connecting " + addresses.get(i)); Socket sock = plain_sf.createSocket(); conn.opening(sock, target); try { Socket connsock = plain_sf.connectSocket(sock, addresses.get(i).getHostAddress(), schm.resolvePort(target.getPort()), local, 0, params); if (sock != connsock) { sock = connsock; conn.opening(sock, target); } /* * prepareSocket is called on the just connected * socket before the creation of the layered socket to * ensure that desired socket options such as * TCP_NODELAY, SO_RCVTIMEO, SO_LINGER will be set * before any I/O is performed on the socket. This * happens in the common case as * SSLSocketFactory.createSocket performs hostname * verification which requires that SSL handshaking be * performed. */ prepareSocket(sock, context, params); if (layered_sf != null) { Socket layeredsock = layered_sf.createSocket(sock, target.getHostName(), schm.resolvePort(target.getPort()), true); if (layeredsock != sock) { conn.opening(layeredsock, target); } conn.openCompleted(sf.isSecure(layeredsock), params); } else { conn.openCompleted(sf.isSecure(sock), params); } break; // BEGIN android-changed // catch SocketException to cover any kind of connect failure } catch (SocketException ex) { if (i == addresses.size() - 1) { ConnectException cause = ex instanceof ConnectException ? (ConnectException) ex : (ConnectException) new ConnectException(ex.getMessage()).initCause(ex); throw new HttpHostConnectException(target, cause); } // END android-changed } catch (ConnectTimeoutException ex) { if (i == addresses.size() - 1) { throw ex; } } } }
From source file:com.qiniu.android.http.ClientConnectionOperator.java
public void updateSecureConnection(OperatedClientConnection conn, HttpHost target, HttpContext context, HttpParams params) throws IOException { if (conn == null) { throw new IllegalArgumentException("Connection must not be null."); }//from w ww . j a va2 s.c om if (target == null) { throw new IllegalArgumentException("Target host must not be null."); } if (params == null) { throw new IllegalArgumentException("Parameters must not be null."); } if (!conn.isOpen()) { throw new IllegalArgumentException("Connection must be open."); } final Scheme schm = schemeRegistry.getScheme(target.getSchemeName()); if (!(schm.getSocketFactory() instanceof LayeredSocketFactory)) { throw new IllegalArgumentException( "Target scheme (" + schm.getName() + ") must have layered socket factory."); } final LayeredSocketFactory lsf = (LayeredSocketFactory) schm.getSocketFactory(); final Socket sock; try { sock = lsf.createSocket(conn.getSocket(), target.getHostName(), target.getPort(), true); } catch (ConnectException ex) { throw new HttpHostConnectException(target, ex); } prepareSocket(sock, context, params); conn.update(sock, target, lsf.isSecure(sock), params); }