protected void onResponseComplete() throws IOException {
      super.onResponseComplete();
      if (getResponseStatus() == 200 && _responses != null && _responses.length > 0) {
        try {
          startBatch();

          for (int i = 0; i < _responses.length; i++) {
            Message msg = (Message) _responses[i];

            if (Bayeux.META_CONNECT.equals(msg.get(Bayeux.CHANNEL_FIELD))) {
              Boolean successful = (Boolean) msg.get(Bayeux.SUCCESSFUL_FIELD);
              if (successful != null && successful.booleanValue()) {
                if (!_initialized) {
                  _initialized = true;
                  synchronized (_outQ) {
                    if (_outQ.size() > 0) _push = new Publish();
                  }
                }

                _pull = new Connect();
              } else throw new IOException("Connect failed:" + _responses[0]);
            }

            deliver(null, msg);
          }
        } finally {
          endBatch();
        }

      } else {
        throw new IOException("Connect failed: " + getResponseStatus());
      }
    }
 /* (non-Javadoc)
  * @see dojox.cometd.Client#publish(java.lang.String, java.lang.Object, java.lang.String)
  */
 public void publish(String toChannel, Object data, String msgId) {
   Message msg = new MessageImpl();
   msg.put(Bayeux.CHANNEL_FIELD, toChannel);
   msg.put(Bayeux.DATA_FIELD, data);
   if (msgId != null) msg.put(Bayeux.ID_FIELD, msgId);
   publish(msg);
 }
  /* (non-Javadoc)
   * @see dojox.cometd.Client#remove(boolean)
   */
  public void remove(boolean timeout) {
    Message msg = new MessageImpl();
    msg.put(Bayeux.CHANNEL_FIELD, Bayeux.META_DISCONNECT);

    synchronized (_outQ) {
      _outQ.add(msg);

      _initialized = false;
      _disconnecting = true;

      if (_batch == 0 && _initialized && _push == null) _push = new Publish();
    }
  }
  /* (non-Javadoc)
   * @see dojox.cometd.Client#deliver(dojox.cometd.Client, java.lang.String, java.lang.Object, java.lang.String)
   */
  public void deliver(Client from, String toChannel, Object data, String id) {
    Message message = new MessageImpl();

    message.put(Bayeux.CHANNEL_FIELD, toChannel);
    message.put(Bayeux.DATA_FIELD, data);
    if (id != null) message.put(Bayeux.ID_FIELD, id);

    synchronized (_inQ) {
      if (_mListeners == null) _inQ.add(message);
      else {
        for (MessageListener l : _mListeners) l.deliver(from, this, message);
      }
    }
  }
    protected void setMessages(List<Message> messages) {
      try {
        for (Message msg : messages) {
          msg.put(Bayeux.CLIENT_FIELD, _clientId);
        }
        String json = JSON.toString(messages);

        if (_formEncoded)
          setRequestContent(new ByteArrayBuffer("message=" + URLEncoder.encode(json, "utf-8")));
        else setRequestContent(new ByteArrayBuffer(json, "utf-8"));

      } catch (Exception e) {
        Log.warn(e);
      }
    }
 /* (non-Javadoc)
  * @see dojox.cometd.Client#unsubscribe(java.lang.String)
  */
 public void unsubscribe(String toChannel) {
   Message msg = new MessageImpl();
   msg.put(Bayeux.CHANNEL_FIELD, Bayeux.META_UNSUBSCRIBE);
   msg.put(Bayeux.SUBSCRIPTION_FIELD, toChannel);
   publish(msg);
 }