Example #1
0
 def __init__(self, services, tns, name=None, _with_partnerlink=False, \
              log=None):
     '''
     @param A ServiceBase subclass that defines the exposed services.
     '''
     Application.__init__(self, services, tns)
     # add object logging
     self.log = log
Example #2
0
        cur.execute("select * from  user where name = '{}'".format(
            user))  #checking user credentials with entries in database
        for row in cur.fetchall():
            if password == row[1]:
                return "ok"
        return "fail"

    """
       Makes an xmlrpc call to the get_events of the server running on port no 8000 to get the list of all events
    """

    @rpc(_returns=String)
    def getEvents(self):
        client = xmlrpclib.ServerProxy(
            "http://localhost:8000/")  #making an xmlrpc using xmlrpclib
        result = client.get_events()

        header = "<h1> Available Events </h1>"
        return "<html><body>" + header + str(result) + "</body></html>"


if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        server = make_server('localhost', 7785,
                             Application([WeatherService], 'tns'))
        server.serve_forever()
    except ImportError:
        print "Error: example server code requires Python >= 2.5"
Example #3
0
    @rpc(SOAPRequest, _returns=Integer)
    def get_integers_count(self, req):
        return self.max

    @rpc(_returns=String)
    def name(self):
        return self.__class__.__name__

    @rpc(NestedObject, _returns=NestedObject)
    def get_nested(self, complex):
        retval = NestedObject()
        retval.date_time = datetime.now()

        retval.ro = ReturnObject()
        i = 5
        retval.ro.byone = i
        retval.ro.bytwo = i * 2
        retval.ro.bythree = i * 3
        retval.ro.byfour = i * 4
        retval.ro.byfive = i * 5
        retval.arr = ['asd097n09a', 'askdj0n3t']

        return retval


apps = [(Application([HelloWorldService],
                     'HelloWorldService.HelloWorldService'), 'svc')]

if __name__ == '__main__':
    sys.exit(run_twisted(apps, 7789))
Example #4
0
This is a simple HelloWorld example to show the basics of writing
a webservice using soaplib, starting a server, and creating a service
client.
'''


class HelloWorldService(DefinitionBase):
    @rpc(String, Integer, _returns=Array(String))
    def say_hello(self, name, times):
        '''
        Docstrings for service methods appear as documentation in the wsdl
        <b>what fun</b>
        @param name the name to say hello to
        @param the number of times to say hello
        @return the completed array
        '''
        results = []
        for i in range(0, times):
            results.append('Hello, %s' % name)
        return results


if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        server = make_server('localhost', 7789,
                             Application([HelloWorldService], 'tns'))
        server.serve_forever()
    except ImportError:
        print "Error: example server code requires Python >= 2.5"
Example #5
0
        cur.execute("insert into event values (?,?)", [name, d])

        conn.commit()

        cb_client = Client(
            self.soap_in_header.ReplyTo
        )  # using ReplyTo address in WSAddr header to call the callback

        result = cb_client.service.getEvents()
        return str(result)
        """
        cur.execute("select * from event order by date")

        dic={}
        html = "<ul>"
        for row in cur.fetchall():
                html +="<li>"+row[0]+"scheduled on " + row[1] + "</li>"
        html +="</ul>"

        return html"""


if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        server = make_server('localhost', 7786,
                             Application([EventService], 'tns'))
        server.serve_forever()
    except ImportError:
        print "Error: example server code requires Python >= 2.5"
        usage(1)

    use_encryption = CRYPTO_AVAILABLE
    port = cereconf.SAPINTEGRATION_SERVICE_PORT
    logfile = cereconf.SAPINTEGRATION_SERVICE_LOGFILE

    for opt, val in opts:
        if opt in ('-l', '--logfile'):
            logfile = val
        elif opt in ('-p', '--port'):
            port = int(val)
        elif opt in ('--unencrypted', ):
            use_encryption = False

    ## TBD: Use Cerebrum logger instead?
    # Init twisted logger
    log_observer = startLogging(file(logfile, 'w'))
    # Run service
    service = Application([SAPIntegrationServer], 'tns')
    resource = WSGIResource(reactor, reactor.getThreadPool(), service)
    root = Resource()
    root.putChild('SOAP', resource)
    if use_encryption:
        # TODO: we need to set up SSL properly
        sslcontext = ssl.DefaultOpenSSLContextFactory(
            cereconf.SSL_PRIVATE_KEY_FILE, cereconf.SSL_CERTIFICATE_FILE)
        reactor.listenSSL(int(port), Site(root), contextFactory=sslcontext)
    else:
        reactor.listenTCP(int(port), Site(root))
    reactor.run()
Example #7
0
from soaplib.service import rpc
from soaplib.service import DefinitionBase
from soaplib.serializers.primitive import String, Integer, Float
from soaplib.wsgi import Application
from soaplib.serializers.clazz import Array
import soaplib
from flask import Flask
app = Flask(__name__)


class Toplama(DefinitionBase):
    @rpc(Integer, Integer, _returns=Integer)
    def say_top(self, a, b):
        sonuc = a + b
        return str(sonuc)


if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        server = make_server('localhost', 7789, Application([Toplama], 'tns'))
        print server
        server.serve_forever()
        app.run(host='localhost')
    except ImportError:
        print "Error: example server code requires Python >= 2.5"