-
Notifications
You must be signed in to change notification settings - Fork 144
/
trfc_test.py
98 lines (72 loc) · 2.46 KB
/
trfc_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from time import sleep
from pyrfc import Connection, RCStatus, Server
def stfc_write_to_tcpic(request_context=None, RESTART_QNAME="", TCPICDAT=[]):
context = (
{"error": "No request context"}
if request_context is None
else request_context["server_context"]
)
print("[js] python function: stfc_write_to_tcpic", f"context {context}")
return {"TCPICDAT": TCPICDAT}
def onCheckTransaction(rfcHandle, tid):
print("[js] onCheckTransaction", rfcHandle, tid)
return RCStatus.OK
def onCommitTransaction(rfcHandle, tid):
print("[js] onCommitTransaction", rfcHandle, tid)
return RCStatus.OK
def onConfirmTransaction(rfcHandle, tid):
print("[js] onConfirmTransaction", rfcHandle, tid)
return RCStatus.OK
def onRollbackTransaction(rfcHandle, tid):
print("[js] onRollbackTransaction", rfcHandle, tid)
return RCStatus.OK
def authenticationHandler(function_name, server_context=None):
print(f"[js] authentication for {function_name}, context {server_context}")
return RCStatus.OK
def authorizationHandler(rfcHandle=None, securityAttributes=None):
print(f"[js] authorization for {rfcHandle}, security attr {securityAttributes}")
return RCStatus.OK
# Create server
server = Server(
server_params={"dest": "MME_GATEWAY"},
client_params={"dest": "MME"},
config={
"authentication_check": authenticationHandler,
"authorization_check": authorizationHandler,
"check_date": False,
"check_time": False,
"server_log": True,
},
)
# ABAP function used to send IDocs via tRFC/qRFC
server.add_function("STFC_WRITE_TO_TCPIC", stfc_write_to_tcpic)
# Register the RFC transaction handlers.
server.transaction_rfc_init(
sysId="MME",
transactionHandler={
"check": onCheckTransaction,
"commit": onCommitTransaction,
"rollback": onRollbackTransaction,
"confirm": onConfirmTransaction,
},
)
try:
# Start server
server.start()
# Get server attributes
print(server.get_server_attributes())
# Check transaction handlers
# print(server.transaction_handlers)
# print(server.transaction_handlers_count)
# call RSARFCT0
client = Connection(dest="MME")
ncall = client.call("ZSERVER_TEST_TRFC", NCALL="00001")["EV_NCALL"]
print("queues sent", ncall)
client.close()
# receive queues from abap system
sleep(5)
except Exception as ex:
print(ex)
finally:
# Shutdown server
server.close()