Exemplo n.º 1
0
    def setUp(self):
        if self.ssl:
            self.socket = TSSLSocket.TSSLSocket("localhost", self._port)
        else:
            self.socket = TSocket.TSocket("localhost", self._port)

        if self.server_type in FRAMED_TYPES \
                and not isinstance(self, HeaderTest):
            self.transport = TTransport.TFramedTransport(self.socket)
        else:
            self.transport = TTransport.TBufferedTransport(self.socket)

        self.protocol = self.protocol_factory.getProtocol(self.transport)
        if isinstance(self, HeaderAcceleratedCompactTest):
            self.protocol.trans.set_protocol_id(
                THeaderProtocol.THeaderProtocol.T_COMPACT_PROTOCOL)
            self.protocol.reset_protocol()
        self.transport.open()
        self.client = ThriftTest.Client(self.protocol)
        if self.multiple:
            p = TMultiplexedProtocol.TMultiplexedProtocol(
                self.protocol, "ThriftTest")
            self.client = ThriftTest.Client(p)
            p = TMultiplexedProtocol.TMultiplexedProtocol(
                self.protocol, "SecondService")
            self.client2 = SecondService.Client(p)
        else:
            self.client = ThriftTest.Client(self.protocol)
            self.client2 = None
Exemplo n.º 2
0
 def setUp(self):
     if options.http_path:
         self.transport = THttpClient.THttpClient(options.host,
                                                  port=options.port,
                                                  path=options.http_path)
     else:
         if options.ssl:
             from thrift.transport import TSSLSocket
             socket = TSSLSocket.TSSLSocket(options.host,
                                            options.port,
                                            validate=False)
         else:
             socket = TSocket.TSocket(options.host, options.port)
         # frame or buffer depending upon args
         if options.framed:
             self.transport = TTransport.TFramedTransport(socket)
         else:
             self.transport = TTransport.TBufferedTransport(socket)
         if options.zlib:
             self.transport = TZlibTransport.TZlibTransport(
                 self.transport, 9)
     self.transport.open()
     protocol = self.protocol_factory.getProtocol(self.transport)
     if options.multiple:
         p = TMultiplexedProtocol.TMultiplexedProtocol(
             protocol, "ThriftTest")
         self.client = ThriftTest.Client(p)
         p = TMultiplexedProtocol.TMultiplexedProtocol(
             protocol, "SecondService")
         self.client2 = SecondService.Client(p)
     else:
         self.client = ThriftTest.Client(protocol)
         self.client2 = None
Exemplo n.º 3
0
    def setUp(self):
        if options.http_path:
            self.transport = THttpClient.THttpClient(
                options.host, options.port, options.http_path)
        else:
            socket = TSocket.TSocket(options.host, options.port)

            # frame or buffer depending upon args
            if options.framed:
                self.transport = TTransport.TFramedTransport(socket)
            else:
                self.transport = TTransport.TBufferedTransport(socket)

        protocol = self.protocol_factory.getProtocol(self.transport)
        if options.header:
            protocol = THeaderProtocol.THeaderProtocol(socket)
            self.transport = protocol.trans
            protocol.trans.add_transform(protocol.trans.ZLIB_TRANSFORM)

        self.transport.open()
        self.client = ThriftTest.Client(protocol)
        if options.multiple:
            p = TMultiplexedProtocol.TMultiplexedProtocol(protocol,
                    "ThriftTest")
            self.client = ThriftTest.Client(p)
            p = TMultiplexedProtocol.TMultiplexedProtocol(protocol,
                    "SecondService")
            self.client2 = SecondService.Client(p)
        else:
            self.client = ThriftTest.Client(protocol)
            self.client2 = None
Exemplo n.º 4
0
    if options.context:
        processor = ThriftTest.ContextProcessor(
            TestContextHandler(options.port))
    else:
        processor = ThriftTest.Processor(TestHandler())

    if options.multiple:
        processor = TMultiplexedProcessor.TMultiplexedProcessor()
        if options.context:
            processor.registerProcessor(
                "ThriftTest",
                ThriftTest.ContextProcessor(TestContextHandler(options.port)))
            processor.registerProcessor(
                "SecondService",
                SecondService.ContextProcessor(SecondContextHandler()))
        else:
            processor.registerProcessor("ThriftTest",
                                        ThriftTest.Processor(TestHandler()))
            processor.registerProcessor(
                "SecondService", SecondService.Processor(SecondHandler()))

    server = TCppServer.TCppServer(processor)
    server.setPort(options.port)

    if options.header:
        server.processor.setEventHandler(HeaderEventHandler())
    elif options.context:
        server.processor.setEventHandler(ContextEventHandler())
    server.setServerEventHandler(event_handler)
Exemplo n.º 5
0
if len(args) > 1:
    raise AssertionError(
        'Only one server type may be specified, not multiple types.')
server_type = args[0]

# Set up the handler and processor objects
if not options.multiple:
    handler = TestHandler()
    processor = ThriftTest.Processor(handler)
else:
    processor = TMultiplexedProcessor.TMultiplexedProcessor()
    handler = TestHandler()
    processor.registerProcessor("ThriftTest", ThriftTest.Processor(handler))
    handler = SecondHandler()
    processor.registerProcessor("SecondService",
                                SecondService.Processor(handler))

# Handle THttpServer as a special case
if server_type == 'THttpServer':
    server = THttpServer.THttpServer(processor, ('', options.port), pfactory)
    server.serve()
    sys.exit(0)

# set up server transport and transport factory
host = None
if options.ssl:
    from thrift.transport import TSSLSocket
    transport = TSSLSocket.TSSLServerSocket(host,
                                            options.port,
                                            certfile='../keys/server.pem')
else: