当前位置: 首页>>代码示例>>Java>>正文


Java HttpConnectionParams类代码示例

本文整理汇总了Java中ch.boye.httpclientandroidlib.params.HttpConnectionParams的典型用法代码示例。如果您正苦于以下问题:Java HttpConnectionParams类的具体用法?Java HttpConnectionParams怎么用?Java HttpConnectionParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpConnectionParams类属于ch.boye.httpclientandroidlib.params包,在下文中一共展示了HttpConnectionParams类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDefaultHttpParams

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * Creates default params setting the user agent.
 * 
 * @return Basic HTTP parameters with a custom user agent
 */
protected HttpParams createDefaultHttpParams() {
	HttpParams params = new BasicHttpParams();
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
	String version = Version.getSpecification();
	if (version == null) {
		version = VersionInfo.UNAVAILABLE;
	}
	HttpProtocolParams.setUserAgent(params, "Sardine/" + version);
	// Only selectively enable this for PUT but not all entity enclosing
	// methods
	HttpProtocolParams.setUseExpectContinue(params, false);
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
	HttpProtocolParams.setContentCharset(params,
			HTTP.DEFAULT_CONTENT_CHARSET);

	HttpConnectionParams.setTcpNoDelay(params, true);
	HttpConnectionParams.setSocketBufferSize(params, 8192);
	return params;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:25,代码来源:SardineImpl.java

示例2: connectSocket

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * @since 4.1
 */
public Socket connectSocket(
        final Socket socket,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    Args.notNull(remoteAddress, "Remote address");
    Args.notNull(params, "HTTP parameters");
    final HttpHost host;
    if (remoteAddress instanceof HttpInetSocketAddress) {
        host = ((HttpInetSocketAddress) remoteAddress).getHttpHost();
    } else {
        host = new HttpHost(remoteAddress.getHostName(), remoteAddress.getPort(), "https");
    }
    final int socketTimeout = HttpConnectionParams.getSoTimeout(params);
    final int connectTimeout = HttpConnectionParams.getConnectionTimeout(params);
    socket.setSoTimeout(socketTimeout);
    return connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, null);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:22,代码来源:SSLSocketFactory.java

示例3: prepareSocket

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * Performs standard initializations on a newly created socket.
 *
 * @param sock      the socket to prepare
 * @param context   the context for the connection
 * @param params    the parameters from which to prepare the socket
 *
 * @throws IOException      in case of an IO problem
 */
protected void prepareSocket(
        final Socket sock,
        final HttpContext context,
        final HttpParams params) throws IOException {
    sock.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    sock.setSoTimeout(HttpConnectionParams.getSoTimeout(params));

    final int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        sock.setSoLinger(linger > 0, linger);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:22,代码来源:DefaultClientConnectionOperator.java

示例4: connectSocket

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * @since 4.1
 */
public Socket connectSocket(
        final Socket socket,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpParams params) throws IOException, ConnectTimeoutException {
    Args.notNull(remoteAddress, "Remote address");
    Args.notNull(params, "HTTP parameters");
    Socket sock = socket;
    if (sock == null) {
        sock = createSocket();
    }
    if (localAddress != null) {
        sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
        sock.bind(localAddress);
    }
    final int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    final int soTimeout = HttpConnectionParams.getSoTimeout(params);

    try {
        sock.setSoTimeout(soTimeout);
        sock.connect(remoteAddress, connTimeout);
    } catch (final SocketTimeoutException ex) {
        throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
    }
    return sock;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:30,代码来源:PlainSocketFactory.java

示例5: prepareClient

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * Invoke this after delegate and request have been set.
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 */
protected void prepareClient() throws KeyManagementException, NoSuchAlgorithmException, GeneralSecurityException {
  context = new BasicHttpContext();

  // We could reuse these client instances, except that we mess around
  // with their parameters… so we'd need a pool of some kind.
  client = new DefaultHttpClient(getConnectionManager());

  // TODO: Eventually we should use Apache HttpAsyncClient. It's not out of alpha yet.
  // Until then, we synchronously make the request, then invoke our delegate's callback.
  AuthHeaderProvider authHeaderProvider = delegate.getAuthHeaderProvider();
  if (authHeaderProvider != null) {
    Header authHeader = authHeaderProvider.getAuthHeader(request, context, client);
    if (authHeader != null) {
      request.addHeader(authHeader);
      Logger.debug(LOG_TAG, "Added auth header.");
    }
  }

  addAuthCacheToContext(request, context);

  HttpParams params = client.getParams();
  HttpConnectionParams.setConnectionTimeout(params, delegate.connectionTimeout());
  HttpConnectionParams.setSoTimeout(params, delegate.socketTimeout());
  HttpConnectionParams.setStaleCheckingEnabled(params, false);
  HttpProtocolParams.setContentCharset(params, charset);
  HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
  final String userAgent = delegate.getUserAgent();
  if (userAgent != null) {
    HttpProtocolParams.setUserAgent(params, userAgent);
  }
  delegate.addHeaders(request, client);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:38,代码来源:BaseResource.java

示例6: tryConnect

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * Establish connection either directly or through a tunnel and retry in case of
 * a recoverable I/O failure
 */
private void tryConnect(
        final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
    final HttpRoute route = req.getRoute();
    final HttpRequest wrapper = req.getRequest();

    int connectCount = 0;
    for (;;) {
        context.setAttribute(ExecutionContext.HTTP_REQUEST, wrapper);
        // Increment connect count
        connectCount++;
        try {
            if (!managedConn.isOpen()) {
                managedConn.open(route, context, params);
            } else {
                managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
            }
            establishRoute(route, context);
            break;
        } catch (final IOException ex) {
            try {
                managedConn.close();
            } catch (final IOException ignore) {
            }
            if (retryHandler.retryRequest(ex, connectCount, context)) {
                if (this.log.isInfoEnabled()) {
                    this.log.info("I/O exception ("+ ex.getClass().getName() +
                            ") caught when connecting to "
                            + route +
                            ": "
                            + ex.getMessage());
                    if (this.log.isDebugEnabled()) {
                        this.log.debug(ex.getMessage(), ex);
                    }
                    this.log.info("Retrying connect to " + route);
                }
            } else {
                throw ex;
            }
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:46,代码来源:DefaultRequestDirector.java

示例7: getConnectionManagerTimeout

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * Get the connectiion manager timeout value.
 * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}.
 * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT}
 * which defaults to 0 if not defined.
 *
 * @since 4.2
 * @return the timeout value
 */
public static long getConnectionManagerTimeout(final HttpParams params) {
    Args.notNull(params, "HTTP parameters");
    final Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT);
    if (timeout != null) {
        return timeout.longValue();
    }
    return HttpConnectionParams.getConnectionTimeout(params);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:HttpClientParams.java

示例8: setDefaultHttpParams

import ch.boye.httpclientandroidlib.params.HttpConnectionParams; //导入依赖的package包/类
/**
 * Saves the default set of HttpParams in the provided parameter.
 * These are:
 * <ul>
 * <li>{@link ch.boye.httpclientandroidlib.params.CoreProtocolPNames#PROTOCOL_VERSION}:
 *   1.1</li>
 * <li>{@link ch.boye.httpclientandroidlib.params.CoreProtocolPNames#HTTP_CONTENT_CHARSET}:
 *   ISO-8859-1</li>
 * <li>{@link ch.boye.httpclientandroidlib.params.CoreConnectionPNames#TCP_NODELAY}:
 *   true</li>
 * <li>{@link ch.boye.httpclientandroidlib.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}:
 *   8192</li>
 * <li>{@link ch.boye.httpclientandroidlib.params.CoreProtocolPNames#USER_AGENT}:
 *   Apache-HttpClient/<release> (java 1.5)</li>
 * </ul>
 */
public static void setDefaultHttpParams(final HttpParams params) {
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpProtocolParams.setUserAgent(params, HttpClientBuilder.DEFAULT_USER_AGENT);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:24,代码来源:DefaultHttpClient.java


注:本文中的ch.boye.httpclientandroidlib.params.HttpConnectionParams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。