Skip to content

Commit 2be9a46

Browse files
Merge pull request #4 from laurentiu-rocketgate/RGOPS-5517-EmbeddedField
Implemented the functionality to enable the usage of the Embedded Fields Token
2 parents d8c09ac + ce63fec commit 2be9a46

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

RocketGate.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import random
2727
import errno
2828
import socket
29-
import ssl
29+
import ssl
30+
from urllib.parse import urlsplit
3031

3132
class GatewayRequest:
3233

@@ -86,6 +87,8 @@ class GatewayRequest:
8687

8788
GATEWAY_CONNECT_TIMEOUT = "gatewayConnectTimeout"
8889
GATEWAY_SERVER = "gatewayServer"
90+
GATEWAY_SERVLET = "gatewayServlet"
91+
GATEWAY_PORTNO = "gatewayPortNo"
8992
GATEWAY_READ_TIMEOUT = "gatewayReadTimeout"
9093
GENERATE_POSTBACK = "generatePostback"
9194

@@ -618,8 +621,8 @@ def SendTransaction(self, serverName, request, response):
618621
#
619622
# Gather overrides for transaction.
620623
#
621-
urlServlet = request.Get("gatewayServlet")
622-
urlPortNo = request.Get("portNo")
624+
urlServlet = request.Get(GatewayRequest.GATEWAY_SERVLET)
625+
urlPortNo = request.Get(GatewayRequest.GATEWAY_PORTNO)
623626

624627
#
625628
# Determine the final servlet name.
@@ -776,11 +779,29 @@ def SendTransaction(self, serverName, request, response):
776779
#
777780
def PerformTransaction(self, request, response):
778781

782+
#
783+
# If EMBEDDED_FIELDS_TOKEN is provided, send the request to the corresponding endpoint
784+
#
785+
fullUrl = request.Get(GatewayRequest.EMBEDDED_FIELDS_TOKEN)
786+
if fullUrl is not None:
787+
try:
788+
parsedUrl = urlsplit(fullUrl)
789+
request.Set(GatewayRequest.GATEWAY_SERVER, parsedUrl.hostname)
790+
request.Set(GatewayRequest.GATEWAY_SERVLET,
791+
parsedUrl.path + ("?" + parsedUrl.query if parsedUrl.query is not None else ""))
792+
if parsedUrl.port is not None:
793+
request.Set(GatewayRequest.GATEWAY_PORTNO, parsedUrl.port)
794+
except Exception as ex:
795+
response.Set(GatewayResponse.EXCEPTION, str(ex))
796+
response.Set(GatewayResponse.RESPONSE_CODE, 4)
797+
response.Set(GatewayResponse.REASON_CODE, 401)
798+
return 4 # Validation error: Invalid URL
799+
779800
#
780801
# If the request specifies a server name, use it.
781802
# Otherwise, use the default.
782803
#
783-
serverName = request.Get("gatewayServer")
804+
serverName = request.Get(GatewayRequest.GATEWAY_SERVER)
784805
if serverName != None: # Override?
785806
serverList = [ serverName ] # Use this name
786807
else:

0 commit comments

Comments
 (0)