本文整理汇总了Java中org.apache.http.conn.routing.HttpRoute.isTunnelled方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRoute.isTunnelled方法的具体用法?Java HttpRoute.isTunnelled怎么用?Java HttpRoute.isTunnelled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.conn.routing.HttpRoute
的用法示例。
在下文中一共展示了HttpRoute.isTunnelled方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.http.conn.routing.HttpRoute; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
return;
}
// Obtain the client connection (required)
HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
if (conn == null) {
this.log.debug("HTTP connection not set in the context");
return;
}
HttpRoute route = conn.getRoute();
if (route.getHopCount() == 1 || route.isTunnelled()) {
if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
}
}
if (route.getHopCount() == 2 && !route.isTunnelled()) {
if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
}
}
}
示例2: process
import org.apache.http.conn.routing.HttpRoute; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
return;
}
HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
if (conn == null) {
this.log.debug("HTTP connection not set in the context");
return;
}
HttpRoute route = conn.getRoute();
if (route.isTunnelled()) {
return;
}
// Obtain authentication state
AuthState authState = (AuthState) context.getAttribute(
ClientContext.PROXY_AUTH_STATE);
if (authState == null) {
this.log.debug("Proxy auth state not set in the context");
return;
}
if (this.log.isDebugEnabled()) {
this.log.debug("Proxy auth state: " + authState.getState());
}
process(authState, request, context);
}
示例3: rewriteRequestURI
import org.apache.http.conn.routing.HttpRoute; //导入方法依赖的package包/类
protected void rewriteRequestURI(
final RequestWrapper request,
final HttpRoute route) throws ProtocolException {
try {
URI uri = request.getURI();
if (route.getProxyHost() != null && !route.isTunnelled()) {
// Make sure the request URI is absolute
if (!uri.isAbsolute()) {
HttpHost target = route.getTargetHost();
uri = URIUtils.rewriteURI(uri, target, true);
} else {
uri = URIUtils.rewriteURI(uri);
}
} else {
// Make sure the request URI is relative
if (uri.isAbsolute()) {
uri = URIUtils.rewriteURI(uri, null);
} else {
uri = URIUtils.rewriteURI(uri);
}
}
request.setURI(uri);
} catch (URISyntaxException ex) {
throw new ProtocolException("Invalid URI: " +
request.getRequestLine().getUri(), ex);
}
}
示例4: tryExecute
import org.apache.http.conn.routing.HttpRoute; //导入方法依赖的package包/类
/**
* Execute request and retry in case of a recoverable I/O failure
*/
private HttpResponse tryExecute(
final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
RequestWrapper wrapper = req.getRequest();
HttpRoute route = req.getRoute();
HttpResponse response = null;
Exception retryReason = null;
for (;;) {
// Increment total exec count (with redirects)
execCount++;
// Increment exec count for this particular request
wrapper.incrementExecCount();
if (!wrapper.isRepeatable()) {
this.log.debug("Cannot retry non-repeatable request");
if (retryReason != null) {
throw new NonRepeatableRequestException("Cannot retry request " +
"with a non-repeatable request entity. The cause lists the " +
"reason the original request failed.", retryReason);
} else {
throw new NonRepeatableRequestException("Cannot retry request " +
"with a non-repeatable request entity.");
}
}
try {
if (!managedConn.isOpen()) {
// If we have a direct route to the target host
// just re-open connection and re-try the request
if (!route.isTunnelled()) {
this.log.debug("Reopening the direct connection.");
managedConn.open(route, context, params);
} else {
// otherwise give up
this.log.debug("Proxied connection. Need to start over.");
break;
}
}
if (this.log.isDebugEnabled()) {
this.log.debug("Attempt " + execCount + " to execute request");
}
response = requestExec.execute(wrapper, managedConn, context);
break;
} catch (IOException ex) {
this.log.debug("Closing the connection.");
try {
managedConn.close();
} catch (IOException ignore) {
}
if (retryHandler.retryRequest(ex, wrapper.getExecCount(), context)) {
if (this.log.isInfoEnabled()) {
this.log.info("I/O exception ("+ ex.getClass().getName() +
") caught when processing request: "
+ ex.getMessage());
}
if (this.log.isDebugEnabled()) {
this.log.debug(ex.getMessage(), ex);
}
this.log.info("Retrying request");
retryReason = ex;
} else {
throw ex;
}
}
}
return response;
}