Ejemplo n.º 1
0
def test_request_transport_integration():
    handler = ReadOnlySchedulerHandler()
    processor = ReadOnlyScheduler.Processor(handler)
    pfactory = TJSONProtocol.TJSONProtocolFactory()
    server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
    server_thread = Thread(target=server.serve)
    server_thread.start()
    _, server_port = server.httpd.socket.getsockname()

    response = None

    try:
        transport = TRequestsTransport('http://localhost:%d' % server_port)
        protocol = TJSONProtocol.TJSONProtocol(transport)
        client = ReadOnlyScheduler.Client(protocol)
        response = client.getRoleSummary()
    finally:
        server.httpd.shutdown()

    assert response is not None
    assert response.responseCode == ResponseCode.OK
    assert response.serverInfo.clusterName == 'west'
    assert response.serverInfo.thriftAPIVersion == 3

    transport.close()
Ejemplo n.º 2
0
def taxon_service():
    handler = TaxonService(services=get_services_dict())
    processor = thrift_service.Processor(handler)
    pfactory = TJSONProtocol.TJSONProtocolFactory()
    server_address = ('127.0.0.1', 9090)

    server = THttpServer.THttpServer(processor, server_address, pfactory)
    return server
Ejemplo n.º 3
0
def run():
    handler = HelloHandler()
    processor = Hello.Processor(handler)
    pfacotry = TBinaryProtocol.TBinaryProtocolFactory()
    server = THttpServer.THttpServer(processor, ('127.0.0.1', 9090), pfacotry)
    print "starting server"
    server.serve()
    print "done"
Ejemplo n.º 4
0
 def __initialize(self):
     pfactory = ThriftServer.__protocol_type[self._protocol]()
     if self._server_type == 'http':
         self._server = THttpServer.THttpServer(\
         self._processor, (self._ip, self._port), pfactory)
         return
     transport = TSocket.TServerSocket(self._ip, self._port)
     if self._transport == 'zlib':
         transport = TZlibTransport.TZlibTransport(transport)
         tfactory = TZlibTransport.TZlibTransportFactory()
     else:
         tfactory = TTransport.TBufferedTransportFactory()
     if self._server_type == 'noblock':
         self._server = TNonblockingServer.TNonblockingServer(\
         self._processor, transport, inputProtocolFactory=pfactory)
     else:
         self._server_type = ThriftServer.__server_type.get(self._server_type, 'TSimpleServer')
         ServerClass = getattr(TServer, self._server_type)
         self._server = ServerClass(self._processor, transport, tfactory, pfactory)
Ejemplo n.º 5
0
def test_requests_transport_session_reuse():
    handler = ReadOnlySchedulerHandler()
    processor = ReadOnlyScheduler.Processor(handler)
    pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()
    server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
    server_thread = Thread(target=server.serve)
    server_thread.start()
    _, server_port = server.httpd.socket.getsockname()

    try:
        transport = TRequestsTransport('http://localhost:%d' % server_port)
        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
        client = ReadOnlyScheduler.Client(protocol)
        client.getRoleSummary()
        old_session = transport._session
        client.getRoleSummary()
    finally:
        server.httpd.shutdown()

    assert old_session == transport._session

    transport.close()
Ejemplo n.º 6
0
import sys
sys.path.append('gen-py')

from hello import HelloSvc
from thrift.protocol import TJSONProtocol
from thrift.server import THttpServer


class HelloSvcHandler:
    def hello_func(self):
        print "Hello Called"
        return "hello from Python"


processor = HelloSvc.Processor(HelloSvcHandler())
protoFactory = TJSONProtocol.TJSONProtocolFactory()
port = 9090
server = THttpServer.THttpServer(processor, ("localhost", port), protoFactory)
print "Python server running on port " + str(port)
server.serve()
import sys, glob, random, threading, time
sys.path.append('gen-py')

from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.protocol import TJSONProtocol
from thrift.server import THttpServer

from livetex.authentication_public.ttypes import *
from livetex.authentication_public import AuthenticationPublic

from authentication_public_service import AuthenticationPublicHandler

authPublicHandler = AuthenticationPublicHandler()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
#pfactory = TJSONProtocol.TJSONProtocolFactory()
processor = AuthenticationPublic.Processor(authPublicHandler)

server = THttpServer.THttpServer(processor, ('localhost', 10010), pfactory)
print 'Authentication public 10010 serve...'
server.serve()
stus = {}

security_dict = {'256': secp256k1, '192': secp192k1, '160': secp160k1}


class TestHandler:
    def init(self, initList):
        print(initList)
        params = initHandler(security_dict[initList.L])
        ret = setup.PublicParame(*params)
        return ret

    def issue(self, issueparam):
        handret = issuerHandler(issueparam)
        return setup.RetIssue(*handret)

    def execOne(self, paraOne):
        handret = oneHandler(paraOne)
        return setup.ReturnOne(*handret)

    def execTwo(self, paratwo):
        handret = twoHandler(paratwo)
        return setup.ReturnTwo(*handret)


processor = setup.Processor(TestHandler())
pfactory = TJSONProtocol.TJSONProtocolFactory()
server = THttpServer.THttpServer(processor, ("127.0.0.1", 2333), pfactory)
print("Starting thrift server in python...")
server.serve()
Ejemplo n.º 9
0
    raise AssertionError('Unknown --protocol option: %s' % options.proto)
pfactory = pfactory_cls()

# get the server type (TSimpleServer, TNonblockingServer, etc...)
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
handler = TestHandler()
processor = ThriftTest.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

rel_path = "../keys/server.pem"
abs_key_path = os.path.join(script_dir, rel_path)

host = None
if options.ssl:
    from thrift.transport import TSSLSocket
    transport = TSSLSocket.TSSLServerSocket(host,
                                            options.port,
                                            certfile=abs_key_path)
else:
        print 'getStruct(%d)' % (key)
        return self.log[key]

    def zip(self):
        print 'zip()'


# handler = CalculatorHandler()
# processor = Calculator.Processor(handler)
# transport = TSocket.TServerSocket(port=9090)
# tfactory = TTransport.TBufferedTransportFactory()
# pfactory = TBinaryProtocol.TBinaryProtocolFactory()

handler = CalculatorHandler()
processor = Calculator.Processor(handler)
transport = TSocket.TServerSocket(port=8000)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TJSONProtocolFactory()

# server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
host = '0.0.0.0'
port = 8000
server = THttpServer.THttpServer(processor, (host, port), pfactory)

# You could do one of these for a multithreaded server
# server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
#server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)

print 'Starting the server...'
server.serve()
print 'done.'
Ejemplo n.º 11
0
  def testSet(self, thing):
    return thing

  def testList(self, thing):
    return thing

  def testEnum(self, thing):
    return thing

  def testTypedef(self, thing):
    return thing

pfactory = TBinaryProtocol.TBinaryProtocolFactory()
handler = TestHandler()
processor = ThriftTest.Processor(handler)

if sys.argv[1] == "THttpServer":
  server = THttpServer.THttpServer(processor, ('', 9090), pfactory)
else:
  transport = TSocket.TServerSocket(9090)
  tfactory = TTransport.TBufferedTransportFactory()

  if sys.argv[1] == "TNonblockingServer":
    server = TNonblockingServer.TNonblockingServer(processor, transport)
  else:
    ServerClass = getattr(TServer, sys.argv[1])
    server = ServerClass(processor, transport, tfactory, pfactory)

server.serve()
Ejemplo n.º 12
0
        pfactory = THeaderProtocol.THeaderProtocolFactory(True,
                [THeaderTransport.HEADERS_CLIENT_TYPE,
                 THeaderTransport.FRAMED_DEPRECATED,
                 THeaderTransport.UNFRAMED_DEPRECATED,
                 THeaderTransport.HTTP_CLIENT_TYPE])
    else:
        pfactory = TBinaryProtocol.TBinaryProtocolFactory()

    if options.context:
        handler = ThriftTest.ContextProcessor(TestContextHandler(options.port))
    else:
        handler = TestHandler()

    if args[0] == "THttpServer":
        try:
            server = THttpServer.THttpServer(
                    handler, ('', options.port), pfactory)
        except:
            print("Could not load THttpServer")
            raise
    else:
        if options.ssl:
            cert_path = 'thrift/test/py/test_cert.pem'
            transport = TSSLSocket.TSSLServerSocket(options.port,
                    certfile=cert_path)
        else:
            transport = TSocket.TServerSocket(options.port)
        tfactory = TTransport.TBufferedTransportFactory()

        server_class_name = args[0]

        if args[0] == "TNonblockingServer":
Ejemplo n.º 13
0
#!/usr/bin/env python
import sys
import time
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.protocol import TBinaryProtocol
from thrift.server import THttpServer
from aggr import Aggr


class AggrHandler(Aggr.Iface):
    def __init__(self):
        self.values = []

    def addValue(self, value):
        self.values.append(value)

    def getValues(self, ):
        time.sleep(1)
        return self.values


processor = Aggr.Processor(AggrHandler())
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
THttpServer.THttpServer(processor, ('', int(sys.argv[1])), pfactory).serve()
Ejemplo n.º 14
0
from thrift.protocol import TJSONProtocol
from thrift.server import TServer, THttpServer
from example import MtExampleService, ttypes


class ExampleSimpleServer(MtExampleService.Iface):
    def SetUserProfile(self, oProfile):
        #TODO
        return 0

    def GetUserProfile(self, userId):
        #TODO
        oProfile = ttypes.UserProfile()
        return oProfile


handler = ExampleSimpleServer()

processor = MtExampleService.Processor(handler)

pfactory = TJSONProtocol.TJSONProtocolFactory()

server = THttpServer.THttpServer(processor, ('0.0.0.0', 8080), pfactory)

print "Starting python server..."

server.serve()

print "done!"    

Ejemplo n.º 15
0
from module import setup
from tag_util import initHandler, execEncHandler, execDecHandler

from thrift.protocol import TJSONProtocol
from thrift.server import THttpServer


class TestHandler:
    def init(self, initParame):
        handret = initHandler(initParame.L)
        return setup.GetKeypairs(*handret)

    def execEnc(self, encParame):
        handret = execEncHandler(encParame)
        return setup.RetEnc(*handret)

    def execDec(self, decParame):
        handret = execDecHandler(decParame)
        return setup.RetDec(handret)


processor = setup.Processor(TestHandler())
pfactory = TJSONProtocol.TJSONProtocolFactory()
server = THttpServer.THttpServer(processor, ("0.0.0.0", 2333), pfactory)
print("Starting thrift server in python...")
server.serve()
Ejemplo n.º 16
0

class LineHandler:
    def __init__(self):
        self.log = {}

    def loginWithIdentityCredentialForCertificate(self, str1, str2, rsakey1,
                                                  rsacipher, b5, ip, comname,
                                                  i8, str9):
        print "loginWithIdentityCredentialForCertificate() - ", str1, str2, rsakey1, rsacipher, b5, ip, comname, i8, str9

        result = loginWithIdentityCredentialForCertificateResult(
            key64=None,
            code=3,
            line_access=None,
            verifier='VERIFIERzzzzzzzzzzzzzzzzzzzzzzzz',
            auth_digit='8190')
        return result


handler = LineHandler()
processor = Line.Processor(handler)
#transport = TSocket.TServerSocket(port=30303)
#tfactory = TTransport.TBufferedTransportFactory()
pfactory = TCompactProtocol.TCompactProtocolFactory()

server = THttpServer.THttpServer(processor, ('', 30303), pfactory)
print "Starting python server..."
server.serve()
print "done!"