Need help in recording the request and responses for TCP protocol

292 views
Skip to first unread message

sunnyran...@gmail.com

unread,
Feb 27, 2019, 2:14:35 PM2/27/19
to mountebank-discuss
We have XML request (kind of RPC requests) and to run the xml request we hit the http/https URL but the data comes from different backend and which called through TCP protocol. So for ever scenario when we have run these XML request we need to set the IP and Port to set up the environment and this IP and port is nothing but calling the backend over TCP. I tried all the ways to record TCP request and response but didn't get the success.

Imposter:

{
"port": 4545,
"protocol": "tcp",
"name": "DAPI_DEMO",
"mode": "binary",
"recordRequests": "true",
"stubs": [
{
"responses": [
{
"proxy": {
"to": "tcp://tcpserverip:tcpport",
"mode": "proxyAlways",
"addWaitBehavior": "true"
}
}
]
}
],
"endOfRequestResolver": {
"inject": "function (requestData, logger) { var messageLength = requestData.readInt32BE(0); logger.info('Message length: ' + messageLength + ', so far: ' + requestData.length); return requestData.length === messageLength; }"
},
"_links": {
"self": {
"href": "http://localhost:2525/imposters/4545"
}
}
}

In XML request defining below
<SO_SITE_SI_SERVER_IP>my system IPV4 or default gateway i tried both</SO_SITE_SI_SERVER_IP><SO_SITE_SI_SERVER_PORT>4545</SO_SITE_SI_SERVER_PORT>

Can you please help how can i resolve the issue ?

Brandon Byars

unread,
Mar 1, 2019, 9:37:20 PM3/1/19
to sunnyran...@gmail.com, mountebank-discuss
Hi there,
I would start by removing the endOfRequestResolver. The function you have looks to be lifted from the example for the Mule connector on the tcp page and probably isn't right in your context. Verify that your proxy works without the resolver for small responses.

If it does, and some of the responses are bigger than a packet (if you're lucky, none of them are), then you'll need to understand how the TCP protocol defines the end of the request.
-Brandon

--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sunny Rana

unread,
Jun 15, 2021, 9:53:35 AM6/15/21
to mountebank-discuss
Hello,

Sorry its been long for this conversation as i was not able to contribute on this further in my project but definitely needed help from you now. I tried recording the TCP calls without "endOfRequestResolver" but i see below error.

Imposter:

{
        "port":8085,
        "protocol":"tcp",
        "mode""binary",
        "recordRequests""true",
        "stubs": [{
                 "responses": [{
                        "proxy": {
                                "to""tcp://{live host}:{live port}",
                                "predicateGenerators": [{
                                        "matches": { 
                                                "path"true,
                                                "method"true,
                                                "query"true
                                        }
                                }],
                                "mode""proxyAlways"
                        }
                }]
        }]
   }

Error:
info: [mb:2525] mountebank v2.3.3 now taking orders - point your browser to http://localhost:2525/ for help
info: [mb:2525] POST /imposters
info: [tcp:8085] Open for business...
info: [tcp:8085] ::ffff:{some ip}:59580 => VEMBAAAAAB0AAAAAVV4A...
info: [tcp:8085] ::ffff:{some ip}:59581 => VEMBAAAAAB0AAAAAVV4A...
info: [tcp:8085] ::ffff:{some ip}:59580 => VEMBAAAAACAAAAAAVWMA...
info: [tcp:8085] ::ffff:{some ip}:59581 => VEMBAAAAACAAAAAAVWMA...
info: [tcp:8085] ::ffff:{some ip}:59580 => VEMBAAAABwwAAAbwVL8A...
info: [tcp:8085] ::ffff:{some ip}:59581 => VEMBAAAABwwAAAbwVL8A...
info: [tcp:8085] ::ffff:{some ip}:59580 => YXRpb24+PGRpc3BsYXlP...
error: [tcp:8085] Proxy {live host}:{live port} transmission error X=> {"errno":"ECONNRESET","code":"ECONNRESET","syscall":"read"}
error: [tcp:8085] ::ffff:{some ip}:59580 X=> {"errno":"ECONNRESET","code":"ECONNRESET","syscall":"read","message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n    at TCP.onStreamRead (internal/stream_base_commons.js:205:27)"}

info: [tcp:8085] ::ffff:{some ip}:59594 => VEMBAAAAAB0AAAAAVV4A...
info: [tcp:8085] ::ffff:{some ip}:59594 => VEMBAAAAACAAAAAAVWMA...
info: [tcp:8085] ::ffff:{some ip}:59594 => VEMBAAAABD0AAAQhVV8A...
info: [tcp:8085] ::ffff:{some ip}:59594 => VEMBAAAAACAAAAAAVWMA...
info: [tcp:8085] ::ffff:{some ip}:59594 => VEMBAAAABwwAAAbwVL8A...

Can you please help me on this and guide how I can fix the issue (Highlighted issue repeated multiple times in between of the recording as you see above) ?

Thanks,
Sunny Kumar

Brandon Byars

unread,
Jul 1, 2021, 12:35:12 PM7/1/21
to Sunny Rana, mountebank-discuss
Hi Sunny,
It appears you're expecting some templating to fire. Your proxy is tcp://{live host}:{live port}, which obviously isn't a real socket. The logs show it's trying to go to that socket as well, and hitting an unknown host on an invalid port is guaranteed to cause a connection error. Can you replace that with the actual downstream service host and port? Are you expecting the templating to fire before POSTing the imposter to mountebank?
-Brandon


Reply all
Reply to author
Forward
0 new messages