Ejemplo n.º 1
0
config = ConfigParser()
config.read('sapnwrfc.cfg')


# Callback function
def my_stfc_connection(request_context, REQUTEXT=""):
    return {
        'ECHOTEXT':
        REQUTEXT,
        'RESPTEXT':
        u"Python server here. Connection attributes are: "
        u"User '{user}' from system '{sysId}', client '{client}', "
        u"host '{partnerHost}'".format(
            **request_context['connection_attributes'])
    }


# Open a connection for retrieving the metadata of 'STFC_CONNECTION'
params_connection = config._sections['connection']
conn = Connection(**params_connection)
func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")

# Instantiate server with gateway information for registering, and
# install a function.
params_gateway = config._sections['gateway']
server = Server(**params_gateway)
server.install_function(func_desc_stfc_connection, my_stfc_connection)
print "--- Server registration and serving ---"
server.serve(20)
Ejemplo n.º 2
0
import os
from pyrfc import Server, set_ini_file_directory


def my_stfc_connection(request_context=None, REQUTEXT=""):
    print("stfc invoked")
    print("request_context", request_context)
    print(f"REQUTEXT: {REQUTEXT}")

    return {"ECHOTEXT": REQUTEXT, "RESPTEXT": "Python server here"}


def my_auth_check(func_name=False, request_context={}):
    print(f"authorization check for '{func_name}'")
    print("request_context", request_context)
    return 0


dir_path = os.path.dirname(os.path.realpath(__file__))
set_ini_file_directory(dir_path)

server = Server({"dest": "gateway"}, {"dest": "MME"}, {
    "port": 8081,
    "server_log": False
})
# server = Server({"dest": "gateway"}, {"dest": "MME"}, {"auth_check": my_auth_check, "server_log": True})

server.add_function("STFC_CONNECTION", my_stfc_connection)

server.serve()
Ejemplo n.º 3
0
        'ECHOTEXT':
        REQUTEXT,
        'RESPTEXT':
        u"Local (raise error) server here. Use the following values"
        u"for REQUTEXT: EXCEPTION, EXCEPTION_MESSAGE, MESSAGE, or"
        u"FAILURE."
    }


func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")
server.install_function(func_desc_stfc_connection, my_raise_error)

#func_desc_serv = conn.test_get_srv_func_desc("STFC_CONNECTION")
#
#print "Function description (retrieved from SAP):"
#print func_desc_stfc_connection.to_string()
#
#print "Function description (retrieved from server):"
#print func_desc_serv.to_string()
#
#print "--- Server test invocation ---"
#
#result = conn.test_invoke_srv_function("STFC_CONNECTION", REQUTEXT="Hola mundo!")
#print "Result is: \n{}".format(result)

if __name__ == '__main__':
    duration = 20
    print("--- Server registration and serving (for {} seconds)---".format(
        duration))
    server.serve(duration)
Ejemplo n.º 4
0
    elif ERRTYPE == 'INVALID':
        raise RFCError("This is an invalid exception.")
    elif ERRTYPE == 'INVALID2':
        raise RFCLibError("This is an invalid exception.", 23, "INV_EXC")
    return {
        'ECHOTEXT': REQUTEXT,
        'RESPTEXT': u"Local (raise error) server here. Use the following values"
                    u"for REQUTEXT: EXCEPTION, EXCEPTION_MESSAGE, MESSAGE, or"
                    u"FAILURE."
    }
func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")
server.install_function(func_desc_stfc_connection, my_raise_error)

#func_desc_serv = conn.test_get_srv_func_desc("STFC_CONNECTION")
#
#print "Function description (retrieved from SAP):"
#print func_desc_stfc_connection.to_string()
#
#print "Function description (retrieved from server):"
#print func_desc_serv.to_string()
#
#print "--- Server test invocation ---"
#
#result = conn.test_invoke_srv_function("STFC_CONNECTION", REQUTEXT="Hola mundo!")
#print "Result is: \n{}".format(result)

if __name__ == '__main__':
    duration = 20
    print "--- Server registration and serving (for {} seconds)---".format(duration)
    server.serve(duration)
Ejemplo n.º 5
0
import signal
import sys

config = ConfigParser()
config.read('sapnwrfc.cfg')

# Callback function
def my_stfc_connection(request_context, REQUTEXT=""):
    REQUTEXT = 'wusj'
    return {
        'ECHOTEXT': REQUTEXT,
        'RESPTEXT': u"Python server here. Connection attributes are: "
                    u"User '{user}' from system '{sysId}', client '{client}', "
                    u"host '{partnerHost}'".format(**request_context['connection_attributes'])
    }

# Open a connection for retrieving the metadata of 'STFC_CONNECTION'
params_connection = config._sections['connection']
conn = Connection(**params_connection)
func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")

# Instantiate server with gateway information for registering, and
# install a function.
params_gateway = config._sections['gateway']
server = Server(**params_gateway)
server.install_function(func_desc_stfc_connection, my_stfc_connection)
print("--- Server registration and serving ---")

server.serve()# Serves for a given timeout. Note: internally this function installs a generic server function and registers the server at the gateway (if required). :param timeout: Number of seconds to serve or None (default) for no timeout. :raises: :exc:~pyrfc.RFCError or a subclass
Ejemplo n.º 6
0
import signal
import sys



config = ConfigParser()
config.read('sapnwrfc.cfg')

# Callback function
def my_stfc_connection(request_context, REQUTEXT=""):
    return {
        'ECHOTEXT': REQUTEXT,
        'RESPTEXT': u"Python server here. Connection attributes are: "
                    u"User '{user}' from system '{sysId}', client '{client}', "
                    u"host '{partnerHost}'".format(**request_context['connection_attributes'])
    }

# Open a connection for retrieving the metadata of 'STFC_CONNECTION'
params_connection = config._sections['connection']
conn = Connection(**params_connection)
func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")

# Instantiate server with gateway information for registering, and
# install a function.
params_gateway = config._sections['gateway']
server = Server(**params_gateway)
server.install_function(func_desc_stfc_connection, my_stfc_connection)
print "--- Server registration and serving ---"
server.serve(20)