示例#1
0
  protected ClientConnectionManager createClientConnectionManager() {
    final SchemeRegistry registry = SchemeRegistryFactory.createDefault();

    ClientConnectionManager connManager = null;
    final HttpParams params = getParams();

    ClientConnectionManagerFactory factory = null;

    final String className =
        (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
    if (className != null) {
      try {
        final Class<?> clazz = Class.forName(className);
        factory = (ClientConnectionManagerFactory) clazz.newInstance();
      } catch (final ClassNotFoundException ex) {
        throw new IllegalStateException("Invalid class name: " + className);
      } catch (final IllegalAccessException ex) {
        throw new IllegalAccessError(ex.getMessage());
      } catch (final InstantiationException ex) {
        throw new InstantiationError(ex.getMessage());
      }
    }
    if (factory != null) {
      connManager = factory.newInstance(params, registry);
    } else {
      connManager = new BasicClientConnectionManager(registry);
    }

    return connManager;
  }
示例#2
0
  private HttpUtility() {

    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(5);

    httpClient = new DecompressingHttpClient(new DefaultHttpClient(connectionManager));
    HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 8000);
    HttpConnectionParams.setSoTimeout(httpClient.getParams(), 8000);
  }