def rest_invoke(self, *args, **kwargs):
        if self.username:
            headers = kwargs.get('headers', {})
            headers['Authorization'] = 'WSSE profile="UsernameToken"'
            headers['X-WSSE'] = wsse_header(self.username, self.password)

            kwargs['headers'] = headers
        kwargs['params'] = dict((key, dumps(value)) for key, value in kwargs['params'].items())                
        try:
            return rest_invoke(*args, **kwargs)
        except socket.error, e:
            raise ServerError("Couldn't connect to server", e)
    def test_login(self):
        """Tests whether the given username and password work with the
        given server.  If the server is down, returns False even
        though queued messages with this username/password might
        eventually be accepted."""

        headers = {}        
        if self.username:
            headers['Authorization'] = 'WSSE profile="UsernameToken"'
            headers['X-WSSE'] = wsse_header(self.username, self.password)        
        result, body = rest_invoke(self.server_url + "/event", method="GET", headers = headers, resp=True)
        return result['status'] == '200'
    def send_one(self):
        return 

        if not len(self.messages):
            return

        try:
            self.lock.acquire()
            message = self.messages[0]
        finally:
            self.lock.release()        
        url, message, id = message.url, message.message, message.id
        
        if not url:
            return url #failure

        log.debug("sending a message")

        params = loads(message)
        headers = {}
        if params.has_key("__extra"):
            extra = params['__extra']
            del params['__extra']
            username = extra['username']
            password = extra['password']
            headers['Authorization'] = 'WSSE profile="UsernameToken"'
            headers['X-WSSE'] = wsse_header(username, password)

        params = dict((key, dumps(value)) for key, value in params.items())        
        
        #try to send it to the server
        result = rest_invoke(url, method="POST", params=params, headers = headers)
        try:
            result = loads(result)
        except ValueError:
            log.warning("Unparsable result from Cabochon: %s" % result)
            return False
        
        if result.get('status', None) != 'accepted':
            return #failure

        self.messages[0].destroySelf()            
        try:
            self.lock.acquire()
            self.messages = self.messages[1:]
        finally:
            self.lock.release()
        return True