Ejemplo n.º 1
0
def main(argv):
    observer = log.PythonLoggingObserver('twisted')
    log.startLoggingWithObserver(observer.emit, setStdout=False)

    wsgi_application = WsgiApplication(soap_application)

    return run_twisted([(wsgi_application, url)], port)
Ejemplo n.º 2
0
    def setup_services(self, applications):
        """Setting up the service that should be run by twisted. This is here
        an rpclib service in the standard WSGI format."""
        if type(applications) not in (list, tuple, dict):
            applications = [applications]

        self.service = rpclib.application.Application(
            applications,
            tns=self.namespace,
            interface=Wsdl11(),
            in_protocol=Soap11(validator='lxml'),
            out_protocol=Soap11())
        self.wsgi_application = WsgiApplication(self.service)
Ejemplo n.º 3
0
def wsgi_soap11_application(services,
                            tns='rpclib.simple.soap',
                            validator=None):
    """Wraps `services` argument inside a WsgiApplication that uses Wsdl 1.1 as
    interface document and Soap 1.1 and both input and output protocols.
    """

    application = Application(services,
                              tns,
                              interface=Wsdl11(),
                              in_protocol=Soap11(validator=validator),
                              out_protocol=Soap11())

    return WsgiApplication(application)
Ejemplo n.º 4
0
    def setup_services(self, applications):
        """Setting up the service that should be run by twisted. This is here
        an rpclib service in the standard WSGI format."""
        if type(applications) not in (list, tuple, dict):
            applications = [applications]

        # Set the encoding for SOAP data, converting it from unicode to some
        # str encoding. We could instead use the Unicode classes, but Cerebrum
        # doesn't support unicode natively quite yet.
        String.Attributes.encoding = 'latin1'

        # Ignore unencodable characters
        # The following function does the same as String.from_string, except
        # that it supplies 'ignore' as an argument to encode()
        from rpclib.model import nillable_string

        @classmethod
        @nillable_string
        def from_string(cls, value):
            retval = value
            if isinstance(value, unicode):
                if cls.Attributes.encoding is None:
                    raise Exception("You need to define an encoding to "
                                    "convert the incoming unicode values to.")
                else:
                    retval = value.encode(cls.Attributes.encoding, 'ignore')
            return retval

        String.from_string = from_string

        self.service = rpclib.application.Application(
            applications,
            tns=self.namespace,
            interface=Wsdl11(),
            in_protocol=Soap11(validator='lxml'),
            out_protocol=Soap11())
        self.wsgi_application = WsgiApplication(self.service)
Ejemplo n.º 5
0
    def send_location(clientid):
        print "Asking the RMI Server about ", clientid
        push_property = Pyro4.Proxy("PYRONAME:property.id")
        a = push_property.scanProplist(clientid)
        yield str(a)


if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
    except ImportError:
        print "Error: server requires Python >= 2.5"

    logging.basicConfig(level=logging.INFO)
    logging.getLogger('rpclib.protocol.xml').setLevel(logging.DEBUG)

    application = Application([MessageService],
                              'org.temporary.soap',
                              interface=Wsdl11(),
                              in_protocol=Soap11(),
                              out_protocol=Soap11())

    port = int(os.environ.get('PORT', 5007))

    server = make_server('0.0.0.0', port, WsgiApplication(application))

    print "listening to http://0.0.0.0:%s" % port
    print "wsdl is at: http://0.0.0.0:%s/?wsdl" % port

    server.serve_forever()
Ejemplo n.º 6
0
            raise Fault("Client.FileName", "File '%s' not found" % file_path)

        document = open(file_path, 'rb').read()

        # the service automatically loads the data from the file.
        # alternatively, The data could be manually loaded into memory
        # and loaded into the Attachment like:
        #   document = Attachment(data=data_from_file)
        return [document]


if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
    except ImportError:
        print("Error: example server code requires Python >= 2.5")

    application = Application([DocumentArchiver],
                              'rpclib.examples.binary',
                              interface=Wsdl11(),
                              in_protocol=HttpRpc(),
                              out_protocol=HttpRpc())

    logging.basicConfig(level=logging.DEBUG)

    server = make_server('127.0.0.1', 7789, WsgiApplication(application))
    print("listening to http://127.0.0.1:7789")
    print("wsdl is at: http://localhost:7789/?wsdl")

    server.serve_forever()
Ejemplo n.º 7
0
#

import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('rpclib.protocol.xml').setLevel(logging.DEBUG)
logger = logging.getLogger('rpclib.test.interop.server.soap_http_basic')

from rpclib.server.wsgi import WsgiApplication
from rpclib.test.interop.server._service import services
from rpclib.application import Application
from rpclib.protocol.soap import Soap11
from rpclib.interface.wsdl import Wsdl11

soap_application = Application(services, 'rpclib.test.interop.server',
                               Wsdl11(), Soap11(validator='lxml'), Soap11())

if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        from wsgiref.validate import validator

        wsgi_application = WsgiApplication(soap_application)
        server = make_server('0.0.0.0', 9753, validator(wsgi_application))

        logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', 9753))
        logger.info('WSDL is at: /?wsdl')
        server.serve_forever()

    except ImportError:
        print("Error: example server code requires Python >= 2.5")
Ejemplo n.º 8
0

class HelloWorldService(ServiceBase):
    @srpc(String, Integer, _returns=Array(String))
    def say_hello(name, times):
        '''Docstrings for service methods appear as documentation in the wsdl.

        @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__':
    application = Application([HelloWorldService],
                              'rpclib.examples.hello.twisted',
                              interface=Wsdl11(),
                              in_protocol=Soap11(),
                              out_protocol=Soap11())
    wsgi_app = WsgiApplication(application)

    print('listening on 0.0.0.0:7789')
    print('wsdl is at: http://0.0.0.0:7789/app/?wsdl')

    run_twisted(((wsgi_app, "app"), ), 7789)
Ejemplo n.º 9
0
    if "session-id" not in cookie:
        raise UnauthenticatedError()
    session_cookie = cookie["session-id"].value
    session_id = tuple(base64.urlsafe_b64decode(session_cookie).split("\0", 1))
    if not session_id in session_db:
        raise AuthenticationError(session_id[0])
    ctx.udc = session_id[0]     # user name
    

UserService.event_manager.add_listener('method_call', _on_method_call)

if __name__=='__main__':
    from rpclib.util.wsgi_wrapper import run_twisted

    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('rpclib.protocol.xml').setLevel(logging.DEBUG)
    logging.getLogger('twisted').setLevel(logging.DEBUG)

    application = Application([UserService],
        tns='rpclib.examples.authentication',
        interface=Wsdl11(),
        in_protocol=Soap11(validator='lxml'),
        out_protocol=Soap11()
    )

    twisted_apps = [
        (WsgiApplication(application), 'app'),
    ]

    sys.exit(run_twisted(twisted_apps, 7789))
Ejemplo n.º 10
0
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('rpclib.protocol.xml')
logger.setLevel(logging.DEBUG)

from rpclib.application import Application
from rpclib.test.interop.server._service import services
from rpclib.protocol.soap import Soap11
from rpclib.protocol.http import HttpRpc
from rpclib.interface.wsdl import Wsdl11

httprpc_soap_application = Application(services,
    'rpclib.test.interop.server.httprpc.soap', Wsdl11(), HttpRpc(), Soap11())

from rpclib.server.wsgi import WsgiApplication

if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        from wsgiref.validate import validator

        wsgi_application = WsgiApplication(httprpc_soap_application)
        server = make_server('0.0.0.0', 9756, validator(wsgi_application))

        logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', 9756))
        logger.info('WSDL is at: /?wsdl')
        server.serve_forever()

    except ImportError:
        print("Error: example server code requires Python >= 2.5")
Ejemplo n.º 11
0
            freebusy = []
            for fb_request in fb_requests:
                calendar_folder = fb_request["folder"]
                if calendar_folder is None:
                    log.warn("no calendar folder found for '%s'" % user_email)
                    fb_response \
                        = ExchangeService._freebusy_lookup_error_response()
                else:
                    fb_response \
                        = ExchangeService._freebusy_response(calendar_folder,
                                                             timezone,
                                                             freebusy_view_options)
                freebusy.append(fb_response)
        else:
            freebusy = None

        if suggestions_view_options is not None:
            suggestions \
                = ExchangeService._suggestions_response(timezone,
                                                        suggestions_view_options)
        else:
            suggestions = None
        
        return (freebusy, suggestions)

EwsApp = Application([ExchangeService], EWS_M_NS,
                     name="ExchangeApplication",
                     interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11())

AsController = WsgiApplication(EwsApp)
Ejemplo n.º 12
0
Archivo: events.py Proyecto: rch/rpclib
    except ImportError:
        print("Error: example server code requires Python >= 2.5")

    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('rpclib.protocol.xml').setLevel(logging.DEBUG)

    application = Application([HelloWorldService],
                              'rpclib.examples.events',
                              interface=Wsdl11(),
                              in_protocol=Soap11(),
                              out_protocol=Soap11())

    application.event_manager.add_listener('method_call', _on_method_call)
    application.event_manager.add_listener('method_return_object',
                                           _on_method_return_object)
    application.event_manager.add_listener('method_context_constructed',
                                           _on_method_context_constructed)
    application.event_manager.add_listener('method_context_destroyed',
                                           _on_method_context_destroyed)

    wsgi_wrapper = WsgiApplication(application)
    wsgi_wrapper.event_manager.add_listener('wsgi_call', _on_wsgi_call)
    wsgi_wrapper.event_manager.add_listener('wsgi_return', _on_wsgi_return)

    server = make_server('127.0.0.1', 7789, wsgi_wrapper)

    print("listening to http://127.0.0.1:7789")
    print("wsdl is at: http://localhost:7789/?wsdl")

    server.serve_forever()
Ejemplo n.º 13
0
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('rpclib.protocol.xml')
logger.setLevel(logging.DEBUG)

from rpclib.application import Application
from rpclib.test.interop.server._service import services
from rpclib.protocol.csv import OutCsv
from rpclib.protocol.http import HttpRpc
from rpclib.interface.wsdl import Wsdl11

httprpc_csv_application = Application(
    services, 'rpclib.test.interop.server.httprpc.csv', Wsdl11(), HttpRpc(),
    OutCsv())
from rpclib.server.wsgi import WsgiApplication

if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        from wsgiref.validate import validator

        wsgi_application = WsgiApplication(httprpc_csv_application)
        server = make_server('0.0.0.0', 9755, validator(wsgi_application))

        logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', 9755))
        logger.info('WSDL is at: /?wsdl')
        server.serve_forever()

    except ImportError:
        print("Error: example server code requires Python >= 2.5")
Ejemplo n.º 14
0
# We are going to use the ubiquitious Http protocol as a transport, using a Wsgi-compliant http server.
# This example uses Python’s stock simple wsgi web server. Rpclib has been tested with several other web servers.
# Any WSGI-compliant server should work.

# This is the required import:
if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
    except ImportError:
        print "Error: example server code requires Python >= 2.5"

    # Here, we configure the python logger to show debugging output. We have to specifically enable the debug output from the soap handler.
    # That’s because the xml formatting code is run only when explicitly enabled for performance reasons
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('rpclib.protocol.xml').setLevel(logging.DEBUG)

    # We glue the service definition, interface document and input and output protocols under the targetNamespace ‘opinionAnalysys.api.analyseOpinion.soap’:
    application = Application([opinionAnalisys_Service],
                              'opinionAnalysys.api.analyseOpinion.soap',
                              interface=Wsdl11(),
                              in_protocol=Soap11(),
                              out_protocol=Soap11())

    server = make_server(
        '127.0.0.1', 7789, WsgiApplication(application)
    )  # We then wrap the rpclib application with its wsgi wrapper:

    print "listening to http://127.0.0.1:7789. wsdl is at: http://localhost:7789/?wsdl"

    server.serve_forever()
Ejemplo n.º 15
0
        for tz in tz_matches:
            time_tz = timezone(tz)
            print(tz, ': ', str(datetime.now(time_tz)))
            string = string + tz + str(datetime.now(time_tz)) + '\n'
        return string


if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
    except ImportError:
        print "Error: server requires Python >= 2.5"

    logging.basicConfig(level=logging.INFO)
    logging.getLogger('rpclib.protocol.xml').setLevel(logging.DEBUG)

    application = Application(
        [tz],
        'org.temporary.soap',
        #               interface=Wsdl11(),
        in_protocol=Soap11(),
        out_protocol=Soap11())

    #   port = int(os.environ.get('PORT', 5000))
    port = 8000
    server = make_server('127.0.0.1', port, WsgiApplication(application))

    print "listening to http://127.0.0.1:%s" % port
    print "wsdl is at: http://127.0.0.1:%s/?wsdl" % port

    server.serve_forever()