use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.
the class DefaultRequestDirector method establishRoute.
/**
* Establishes the target route.
*
* @param route the route to establish
* @param context the context for the request execution
*
* @throws HttpException in case of a problem
* @throws IOException in case of an IO problem
*/
protected void establishRoute(HttpRoute route, HttpContext context) throws HttpException, IOException {
//@@@ how to handle CONNECT requests for tunnelling?
//@@@ refuse to send external CONNECT via director? special handling?
//@@@ should the request parameters already be used below?
//@@@ probably yes, but they're not linked yet
//@@@ will linking above cause problems with linking in reqExec?
//@@@ probably not, because the parent is replaced
//@@@ just make sure we don't link parameters to themselves
HttpRouteDirector rowdy = new BasicRouteDirector();
int step;
do {
HttpRoute fact = managedConn.getRoute();
step = rowdy.nextStep(route, fact);
switch(step) {
case HttpRouteDirector.CONNECT_TARGET:
case HttpRouteDirector.CONNECT_PROXY:
managedConn.open(route, context, this.params);
break;
case HttpRouteDirector.TUNNEL_TARGET:
{
boolean secure = createTunnelToTarget(route, context);
this.log.debug("Tunnel to target created.");
managedConn.tunnelTarget(secure, this.params);
}
break;
case HttpRouteDirector.TUNNEL_PROXY:
{
// The most simple example for this case is a proxy chain
// of two proxies, where P1 must be tunnelled to P2.
// route: Source -> P1 -> P2 -> Target (3 hops)
// fact: Source -> P1 -> Target (2 hops)
// the hop to establish
final int hop = fact.getHopCount() - 1;
boolean secure = createTunnelToProxy(route, hop, context);
this.log.debug("Tunnel to proxy created.");
managedConn.tunnelProxy(route.getHopTarget(hop), secure, this.params);
}
break;
case HttpRouteDirector.LAYER_PROTOCOL:
managedConn.layerProtocol(context, this.params);
break;
case HttpRouteDirector.UNREACHABLE:
throw new IllegalStateException("Unable to establish route." + "\nplanned = " + route + "\ncurrent = " + fact);
case HttpRouteDirector.COMPLETE:
// do nothing
break;
default:
throw new IllegalStateException("Unknown step indicator " + step + " from RouteDirector.");
}
// switch
} while (step > HttpRouteDirector.COMPLETE);
}
use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.
the class AbstractConnPool method handleReference.
// non-javadoc, see interface RefQueueHandler
// BEGIN android-changed
public void handleReference(Reference ref) {
// END android-changed
poolLock.lock();
try {
if (ref instanceof BasicPoolEntryRef) {
// check if the GCed pool entry was still in use
//@@@ find a way to detect this without lookup
//@@@ flag in the BasicPoolEntryRef, to be reset when freed?
final boolean lost = issuedConnections.remove(ref);
if (lost) {
final HttpRoute route = ((BasicPoolEntryRef) ref).getRoute();
if (log.isDebugEnabled()) {
log.debug("Connection garbage collected. " + route);
}
handleLostEntry(route);
}
}
} finally {
poolLock.unlock();
}
}
use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.
the class ConnPoolByRoute method freeEntry.
// getEntry
// non-javadoc, see base class AbstractConnPool
@Override
public void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit) {
HttpRoute route = entry.getPlannedRoute();
if (log.isDebugEnabled()) {
log.debug("Freeing connection" + " [" + route + "][" + entry.getState() + "]");
}
poolLock.lock();
try {
if (isShutDown) {
// the pool is shut down, release the
// connection's resources and get out of here
closeConnection(entry.getConnection());
return;
}
// no longer issued, we keep a hard reference now
issuedConnections.remove(entry.getWeakRef());
RouteSpecificPool rospl = getRoutePool(route, true);
if (reusable) {
rospl.freeEntry(entry);
freeConnections.add(entry);
idleConnHandler.add(entry.getConnection(), validDuration, timeUnit);
} else {
rospl.dropEntry();
numConnections--;
}
notifyWaitingThread(rospl);
} finally {
poolLock.unlock();
}
}
use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.
the class ConnPoolByRoute method deleteEntry.
/**
* Deletes a given pool entry.
* This closes the pooled connection and removes all references,
* so that it can be GCed.
*
* <p><b>Note:</b> Does not remove the entry from the freeConnections list.
* It is assumed that the caller has already handled this step.</p>
* <!-- @@@ is that a good idea? or rather fix it? -->
*
* @param entry the pool entry for the connection to delete
*/
protected void deleteEntry(BasicPoolEntry entry) {
HttpRoute route = entry.getPlannedRoute();
if (log.isDebugEnabled()) {
log.debug("Deleting connection" + " [" + route + "][" + entry.getState() + "]");
}
poolLock.lock();
try {
closeConnection(entry.getConnection());
RouteSpecificPool rospl = getRoutePool(route, true);
rospl.deleteEntry(entry);
numConnections--;
if (rospl.isUnused()) {
routeToPool.remove(route);
}
// not idle, but dead
idleConnHandler.remove(entry.getConnection());
} finally {
poolLock.unlock();
}
}
use of org.apache.http.conn.routing.HttpRoute in project pinpoint by naver.
the class HttpClientConnectionManagerConnectMethodInterceptor method doInBeforeTrace.
@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
if (args != null && args.length >= 2 && args[1] != null && args[1] instanceof HttpRoute) {
final HttpRoute route = (HttpRoute) args[1];
final StringBuilder sb = new StringBuilder();
if (route.getProxyHost() != null) {
sb.append(route.getProxyHost().getHostName());
if (route.getProxyHost().getPort() > 0) {
sb.append(":").append(route.getProxyHost().getPort());
}
} else {
if (route.getTargetHost() != null) {
sb.append(route.getTargetHost().getHostName());
if (route.getTargetHost().getPort() > 0) {
sb.append(":").append(route.getTargetHost().getPort());
}
}
}
recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString());
}
recorder.recordApi(methodDescriptor);
recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4_INTERNAL);
}
Aggregations