-
Notifications
You must be signed in to change notification settings - Fork 144
/
server_app_thread.py
68 lines (49 loc) · 1.64 KB
/
server_app_thread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
from threading import Thread
from pyrfc import Server
def my_stfc_connection(request_context=None, REQUTEXT=""):
"""Server function my_stfc_connection with the signature
of ABAP function module STFC_CONNECTION."""
print("stfc connection 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=None):
"""Server authorization check."""
if request_context is None:
request_context = {}
print(f"authorization check for '{func_name}'")
print("request_context", request_context)
return 0
def launch_server():
"""Start server."""
# create server for ABAP system ABC
server = Server(
server_params={"dest": "gateway"},
client_params={"dest": "MME"},
config={
"check_date": False,
"check_time": False,
"port": 8081,
"server_log": False,
},
)
print(server.get_server_attributes())
# expose python function my_stfc_connection as ABAP function STFC_CONNECTION,
# to be called by ABAP system
server.add_function("STFC_CONNECTION", my_stfc_connection)
# start server
server.serve()
# get server attributes
print(server.get_server_attributes())
server_thread = Thread(target=launch_server)
server_thread.start()
input("Press Enter to stop server...")
# stop server
server_thread.join()
print("Server stoped")