public static StreamConnection getConnectionForRequest(String url) {
    final ConnectionFactory connectionFactory = new ConnectionFactory();

    // Remove any transports that are not currently available.
    if (isTransportManaged == false) {
      for (int i = 0; i < availableTransportTypes.length; i++) {
        int transport = availableTransportTypes[i];
        if (!TransportInfo.isTransportTypeAvailable(transport)
            || !TransportInfo.hasSufficientCoverage(transport)) {
          Arrays.removeAt(availableTransportTypes, i);
        }
      }
      isTransportManaged = true;
    }

    connectionFactory.setPreferredTransportTypes(availableTransportTypes);

    final ConnectionDescriptor connectionDescriptor = connectionFactory.getConnection(url);
    StreamConnection connection = null;
    if (connectionDescriptor != null) {
      // connection suceeded
      int transportUsed = connectionDescriptor.getTransportDescriptor().getTransportType();
      System.out.println("Transport type used: " + Integer.toString(transportUsed));
      connection = (StreamConnection) connectionDescriptor.getConnection();
    }
    return connection;
  }
  public HTTPConnManager(
      final int type,
      final String http,
      BigVector _postData,
      final int handler,
      final HTTPAnswerListener _listener) {
    listener = _listener;
    postData = _postData;
    // Create a preference-ordered list of transports.
    int[] _intTransports = {
      TransportInfo.TRANSPORT_TCP_WIFI,
      TransportInfo.TRANSPORT_BIS_B,
      TransportInfo.TRANSPORT_MDS,
      TransportInfo.TRANSPORT_WAP2,
      TransportInfo.TRANSPORT_TCP_CELLULAR
    };

    // Remove any transports that are not currently available.
    for (int i = 0; i < _intTransports.length; i++) {
      int transport = _intTransports[i];
      if (!TransportInfo.isTransportTypeAvailable(transport)
          || !TransportInfo.hasSufficientCoverage(transport)) {
        Arrays.removeAt(_intTransports, i);
      }
    }

    // Set ConnectionFactory options.
    if (_intTransports.length > 0) {
      _factory.setPreferredTransportTypes(_intTransports);
    }

    _factory.setAttemptsLimit(5);

    // Open a connection on a new thread.
    Thread t =
        new Thread(
            new Runnable() {
              public void run() {
                DebugStorage.getInstance().Log(0, "HTTPConnManager: open connection to " + http);
                ConnectionDescriptor cd = _factory.getConnection(http);
                if (cd != null) {
                  DebugStorage.getInstance().Log(0, "HTTPConnManager: connection created.");
                  Connection c = cd.getConnection();
                  new HTTPOut(type, postData, c, handler, listener);
                } else {
                  DebugStorage.getInstance()
                      .Log(0, "HTTPConnManager: UNABLE TO CREATE CONNECTION!");
                }
              }
            });
    t.start();
  }