protected BOSHClient createSession(final BOSHClientConfig cfg) {
        BOSHClient result = BOSHClient.create(cfg);
        result.addBOSHClientRequestListener(new BOSHClientRequestListener() {
            public void requestSent(final BOSHMessageEvent event) {
                LOG.fine("Sending request: " + event.getBody().toXML());

                // A bug somewhere deep in xsocket library causes its HTTP server to drop
                // requests if they're sent more quickly than they're accepted.  That code
                // is unmaintainable and unmaintained; it should be replaced.  For now,
                // slow down to mask the bug; it's not used by anything but the tests.
                try {
                    Thread.sleep(50);
                } catch(InterruptedException e) { /* ignore */ }
            }
        });
        result.addBOSHClientRequestListener(reqValidator);
        result.addBOSHClientResponseListener(reqValidator);
        result.addBOSHClientResponseListener(new BOSHClientResponseListener() {
            public void responseReceived(final BOSHMessageEvent event) {
                LOG.fine("Received response: " + event.getBody().toXML());
            }
        });
        result.addBOSHClientConnListener(new BOSHClientConnListener() {
            public void connectionEvent(
                    final BOSHClientConnEvent connEvent) {
                if (connEvent.isConnected()) {
                    LOG.info("Connection established");
                } else {
                    Throwable cause = connEvent.getCause();
                    if (cause == null) {
                        LOG.info("Connection closed");
                    } else {
                        if (cleaningUp.get()) {
                            LOG.fine("Connection closed on error: "
                                    + cause.getClass().getName()
                                    + " - " + cause.getMessage());
                        } else {
                            LOG.log(Level.INFO,
                                    "Connection closed on error", cause);
                        }
                    }
                }
            }
        });
        connValidator.setBOSHClient(result);
        return result;
    }