Esempio n. 1
0
def start_listening(site, config, logger):
    from twisted.internet import reactor
    from twisted.internet import protocol as protocol_module
    # allow stomp:// URIs to be parsed by urlparse
    urlparse.uses_netloc.append("stomp")
    # allow test server URIs to be parsed by urlparse
    from orbited.servers import test_servers
    for protocol in test_servers:
        urlparse.uses_netloc.append(protocol)

    for addr in config['[listen]']:
        logger.debug(addr)
        if addr.startswith("stomp"):
            stompConfig = ""
            if " " in addr:
                addr, stompConfig = addr.split(" ", 1)
        url = _parse_url(addr)
        logger.debug('hostname: %r', url.hostname)
        logger.debug('port: %r', url.port)
        hostname = url.hostname or ''
        if url.scheme == 'stomp':
            logger.info('Listening stomp@%s' % url.port)
            from morbid import get_stomp_factory
            morbid_instance = get_stomp_factory(stompConfig)
            config['morbid_instance'] = morbid_instance
            reactor.listenTCP(url.port, morbid_instance, interface=hostname)
        elif url.scheme == 'http':
            logger.info('Listening http@%s' % url.port)
            reactor.listenTCP(url.port, site, interface=hostname)
        elif url.scheme == 'https':
            from twisted.internet import ssl
            crt = config['[ssl]']['crt']
            key = config['[ssl]']['key']
            chain = config['[ssl]'].get('chain')
            try:
                ssl_context = ssl.DefaultOpenSSLContextFactory(key, crt)
                if chain:
                    ssl_context._context.use_certificate_chain_file(chain)
            except ImportError:
                raise
            except Exception, e:
                logger.error(
                    "Error opening key, crt or chain file: %s, %s, %s, %s" %
                    (key, crt, chain, e))
                sys.exit(1)
            logger.info('Listening https@%s (%s, %s)' % (url.port, key, crt))
            reactor.listenSSL(url.port, site, ssl_context, interface=hostname)
        elif url.scheme in test_servers:
            test_factory = protocol_module.ServerFactory()
            test_factory.protocol = test_servers[url.scheme]
            logger.info("Listening %s@%s" % (url.scheme, url.port))
            reactor.listenTCP(url.port, test_factory)
            if url.scheme == 'monitor':
                config['globalVars']['monitoring'] = url.port
Esempio n. 2
0
def start_listening(site, config, logger):
    from twisted.internet import reactor
    from twisted.internet import protocol as protocol_module

    # allow stomp:// URIs to be parsed by urlparse
    urlparse.uses_netloc.append("stomp")
    # allow test server URIs to be parsed by urlparse
    from orbited.servers import test_servers

    for protocol in test_servers:
        urlparse.uses_netloc.append(protocol)

    for addr in config["[listen]"]:
        if addr.startswith("stomp"):
            stompConfig = ""
            if " " in addr:
                addr, stompConfig = addr.split(" ", 1)
        url = urlparse.urlparse(addr)
        hostname = url.hostname or ""
        if url.scheme == "stomp":
            logger.info("Listening stomp@%s" % url.port)
            from morbid import get_stomp_factory

            morbid_instance = get_stomp_factory(stompConfig)
            config["morbid_instance"] = morbid_instance
            reactor.listenTCP(url.port, morbid_instance, interface=hostname)
        elif url.scheme == "http":
            logger.info("Listening http@%s" % url.port)
            reactor.listenTCP(url.port, site, interface=hostname)
        elif url.scheme == "https":
            from twisted.internet import ssl

            crt = config["[ssl]"]["crt"]
            key = config["[ssl]"]["key"]
            try:
                ssl_context = ssl.DefaultOpenSSLContextFactory(key, crt)
            except ImportError:
                raise
            except:
                logger.error("Error opening key or crt file: %s, %s" % (key, crt))
                sys.exit(1)
            logger.info("Listening https@%s (%s, %s)" % (url.port, key, crt))
            reactor.listenSSL(url.port, site, ssl_context, interface=hostname)
        elif url.scheme in test_servers:
            test_factory = protocol_module.ServerFactory()
            test_factory.protocol = test_servers[url.scheme]
            logger.info("Listening %s@%s" % (url.scheme, url.port))
            reactor.listenTCP(url.port, test_factory)
            if url.scheme == "monitor":
                config["globalVars"]["monitoring"] = url.port
        else:
            logger.error("Invalid Listen URI: %s" % addr)
            sys.exit(1)
Esempio n. 3
0
def start_listening(site, config, logger):
    from twisted.internet import reactor
    from twisted.internet import protocol as protocol_module
    # allow stomp:// URIs to be parsed by urlparse
    urlparse.uses_netloc.append("stomp")
    # allow test server URIs to be parsed by urlparse
    from orbited.servers import test_servers
    for protocol in test_servers:
        urlparse.uses_netloc.append(protocol)

    for addr in config['[listen]']:
        logger.debug(addr)
        if addr.startswith("stomp"):
            stompConfig = ""
            if " " in addr:
                addr, stompConfig = addr.split(" ",1)
        url = _parse_url(addr)
        logger.debug('hostname: %r', url.hostname)
        logger.debug('port: %r', url.port)
        hostname = url.hostname or ''
        if url.scheme == 'stomp':
            logger.info('Listening stomp@%s' % url.port)
            from morbid import get_stomp_factory
            morbid_instance = get_stomp_factory(stompConfig)
            config['morbid_instance'] = morbid_instance
            reactor.listenTCP(url.port, morbid_instance, interface=hostname)
        elif url.scheme == 'http':
            logger.info('Listening http@%s' % url.port)
            reactor.listenTCP(url.port, site, interface=hostname)
        elif url.scheme == 'https':
            from twisted.internet import ssl
            crt = config['[ssl]']['crt']
            key = config['[ssl]']['key']
            chain = config['[ssl]'].get('chain')
            try:
                ssl_context = ssl.DefaultOpenSSLContextFactory(key, crt)
                if chain:
                    ssl_context._context.use_certificate_chain_file(chain)
            except ImportError:
                raise
            except Exception, e:
                logger.error("Error opening key, crt or chain file: %s, %s, %s, %s" % (key, crt, chain, e))
                sys.exit(1)
            logger.info('Listening https@%s (%s, %s)' % (url.port, key, crt))
            reactor.listenSSL(url.port, site, ssl_context, interface=hostname)
        elif url.scheme in test_servers:
            test_factory = protocol_module.ServerFactory()
            test_factory.protocol = test_servers[url.scheme]
            logger.info("Listening %s@%s"%(url.scheme, url.port))
            reactor.listenTCP(url.port, test_factory)
            if url.scheme == 'monitor':
                config['globalVars']['monitoring'] = url.port