A managed file gateway passes files between a company's systems and its partners. Each party uploads files to a mailbox on the gateway and downloads files from it, or has files delivered to a server of its own, over SFTP or IBM® Connect:Direct. To test a system that exchanges files with a gateway, Traffic Parrot can stand in for the gateway, so the test needs neither the gateway nor the partners behind it.
This page works through an example of each flow. The Files guide is the reference for everything the examples use.
| The system under test | Traffic Parrot | See |
|---|---|---|
| Uploads a file to its mailbox on the gateway, over SFTP | Is the SFTP server, and consumes the file | Mailbox upload and download |
| Downloads a file from its mailbox, often the reply to an upload | Writes the reply into the mailbox | Mailbox upload and download |
| Receives a file that the gateway delivers to its own SFTP server | Logs in to that server and writes the file, when a trigger file says so | A file pushed to the system under test |
| Exchanges files with the gateway through its own Connect:Direct node | Reads and writes the directories of a test Connect:Direct node that you run | A test node, with Traffic Parrot behind it |
| Works through a gateway that passes files on to a partner over Connect:Direct | Stands in for the partner, over SFTP | A partner the gateway reaches over Connect:Direct |
The SFTP examples use Traffic Parrot's own SFTP server, which needs a licence that includes file messaging.
In this example the system under test logs in to the gateway as partner-a, uploads a payment file to inbox and downloads an acknowledgement from outbox. Traffic Parrot is the SFTP server it logs in to.
In trafficparrot.properties, set:
trafficparrot.file.sftp.server.enabled=true
Create sftp-server-users.json next to that file:
[
{
"username": "partner-a",
"password": "partner-a-password"
},
{
"username": "sut-server",
"password": "sut-server-password"
}
]
The second user is for the push example, where it plays the system under test's own SFTP server. Restart Traffic Parrot. The log then has a line that starts like this, and goes on to name the root directory, the host key file and the key's fingerprint:
Started the embedded SFTP server on 0.0.0.0:8022 for 2 user(s) under
Traffic Parrot as the SFTP server describes the port, logging in with a key in place of a password, and the host key.
Connections are listed in root-directories.json in the installation directory. With the two this page uses and no others, the file is:
[
{
"connectionId": "gateway",
"connectionName": "Gateway",
"connectionData": {
"driver": "LOCAL_FILE_SYSTEM",
"rootDirectory": "sftp-server-root"
}
},
{
"connectionId": "sut-sftp",
"connectionName": "SUT SFTP server",
"connectionData": {
"driver": "SFTP",
"hostname": "localhost",
"port": 8022,
"username": "sut-server",
"password": "sut-server-password",
"remoteBasePath": "/"
}
}
]
Gateway is a Local File System connection on the SFTP server's root directory, sftp-server-root in the installation directory, so the one connection reaches every user's mailbox. SUT SFTP server is for the push example. Traffic Parrot reads the file each time a replay session starts, so a change needs no restart.
Save this as file-mappings/payment-acknowledgement.json in the installation directory. Traffic Parrot creates file-mappings at its first start.
{
"id": "5d0e7a52-3c1b-4f6e-8a2d-9b4c1e7f3a01",
"request": {
"destination": { "name": "partner-a/inbox", "type": "QUEUE" },
"fileNameMatcher": { "matches": "payment-.*\\.xml" },
"bodyMatcher": { "contains": "<currency>GBP</currency>" }
},
"response": {
"destination": { "name": "partner-a/outbox", "type": "QUEUE" },
"fileName": "ack-{{request.fileName}}",
"text": "<ack><status>ACCEPTED</status></ack>",
"bodyType": "TEXT"
}
}
The mapping answers a file in partner-a/inbox whose name matches payment-.*\.xml and whose content contains <currency>GBP</currency>. The reply goes to partner-a/outbox and is named after the request. Directories are relative to the connection's root, so each starts with the user's home directory, which has the user's name.
Traffic Parrot reads a mapping file as soon as it is saved, with no restart.
Mappings can also be built in the web UI, on
Files > Add/Edit,
and the file message
mapping key reference lists every key. The {{request.fileName}}
in the reply's name needs
trafficparrot.file.handlebars.enabled
to be true, as it is unless you use the
performance profile.
Go to Files > Replay. On the Manual tab, choose Gateway under both Consume requests from and and replay responses to, and click Turn ON.
The session creates partner-a/inbox and partner-a/outbox under the root directory. Until a session has run once they do not exist and an upload to inbox fails, so start the session before the system under test connects. Replay is off again after Traffic Parrot restarts.
The system under test connects to port 8022 as partner-a with the password partner-a-password. It sees its home directory as /. It uploads inbox/payment-1.xml:
<payment><amount>100.00</amount><currency>GBP</currency></payment>
Within a fraction of a second, outbox/ack-payment-1.xml is there to download:
<ack><status>ACCEPTED</status></ack>
payment-1.xml is gone from inbox: Traffic Parrot deletes each file it answers. A file that no mapping matches, a payment in another currency here, stays in inbox and gets no reply. See When a file is not answered.
A gateway also delivers files by logging in to the receiver's SFTP server. Traffic Parrot does the same when the reply side of a replay session is an SFTP connection. The system under test sends nothing to answer here, so your test supplies the request: a trigger file, uploaded at the moment the delivery should happen.
The SUT SFTP server connection
above holds the host,
port, user and password of the system under test's SFTP server, and in
remoteBasePath the directory on it that a mapping's directories are
relative to. To try the example with no such server, leave the entry as it is:
it points at Traffic Parrot's own SFTP server, where the user
sut-server plays the part.
Click Turn OFF on Files > Replay, then save this as file-mappings/statement-push.json:
{
"id": "5d0e7a52-3c1b-4f6e-8a2d-9b4c1e7f3a02",
"request": {
"destination": { "name": "partner-a/triggers", "type": "QUEUE" },
"fileNameMatcher": { "equalTo": "push-statement.trigger" },
"bodyMatcher": { "anything": "anything" }
},
"response": {
"destination": { "name": "incoming", "type": "QUEUE" },
"fileName": "statement.csv",
"text": "account,balance\n12345678,100.00\n",
"bodyType": "TEXT"
}
}
A file named push-statement.trigger in partner-a/triggers, whatever its content, is answered with statement.csv in the directory incoming.
Add this file only now. A Manual session serves every mapping in file-mappings: with the file in place earlier, the session of the previous section would have consumed the trigger too, and written the statement under the Gateway root, where no user sees it. Replay is turned off first because a session watches the request directories of the mappings that were there when it started, and no others.
On Files > Replay, choose the Script tab, paste this and click Turn ON:
RequestRootDirectory:'Gateway' ResponseRootDirectory:'Gateway' RequestSubdirectories:'partner-a/inbox' RequestRootDirectory:'Gateway' ResponseRootDirectory:'SUT SFTP server' RequestSubdirectories:'partner-a/triggers'
Each block is one consume and reply pair, as
Replaying using a script describes.
The first keeps answering payments in the mailbox. The second consumes
partner-a/triggers on Gateway and writes its replies
through SUT SFTP server. The names are the connections'
connectionName values, written exactly, capitals included. With
any other name the start is refused with
Unable to find connection with name and the name. To start the
script without the page, from a CI job say, see
the API call that starts a script.
As partner-a, upload triggers/push-statement.trigger with any content that is not empty. Traffic Parrot consumes it, logs in to the system under test's server and writes incoming/statement.csv there, creating incoming if it is missing:
account,balance 12345678,100.00
In the try-out, log in as sut-server to find it. The first push of a session takes about a second. Three things to know:
A mapping's matchers and a Handlebars template are enough for most replies. When the reply depends on the request in a way they do not express, a Java class can decide it: a file message response transformer. This one rejects a payment of zero and accepts any other:
package com.example.gateway;
import com.github.tomakehurst.wiremock.extension.Parameters;
import com.trafficparrot.sdk.file.FileMessage;
import com.trafficparrot.sdk.file.FileMessageResponse;
import com.trafficparrot.sdk.file.FileMessageResponseTransformer;
import com.trafficparrot.sdk.messaging.Destination;
public class AcknowledgePayment extends FileMessageResponseTransformer {
@Override
protected FileMessageResponse doTransform(Destination requestDestination, FileMessage requestMessage, FileMessageResponse response, Parameters parameters) {
String status = requestMessage.text.contains("<amount>0.00</amount>") ? "REJECTED" : "ACCEPTED";
return new FileMessageResponse(response.destination, response.fileName, "<ack><status>" + status + "</status></ack>");
}
}
Save the class as AcknowledgePayment.java in the installation directory and run these two commands there. They need a JDK, version 17 or later: a Java runtime alone has no compiler.
javac --release 17 -proc:none -cp "lib/trafficparrot/internal/*:lib/trafficparrot/dependencies/*" -d build AcknowledgePayment.java jar cf acknowledge-payment.jar -C build .
The classpath is the two directories that hold Traffic Parrot's SDK and the libraries it uses. On Windows, write ; for the : between them. --release 17 compiles for Java 17, so the class runs on that version and on later ones, and -proc:none stops the compiler running the annotation processors it finds in those jars. For more than one class, the SDK workspace project builds and tests an extension jar with Maven, and the SDK Javadoc describes FileMessageResponseTransformer.
Copy acknowledge-payment.jar to lib/external in the installation directory, where jars are loaded at start. In trafficparrot.properties, add the class to the file message response transformers, so that the mapping editor lists it under Response transformer:
trafficparrot.file.responsetransformers=com.example.gateway.AcknowledgePayment
Restart Traffic Parrot. Write the class name exactly: if Traffic Parrot cannot load a class named in that property, Files > Add/Edit and Files > Replay show an error page, and the log names the class with was not found on the classpath.
Add the class to the response in file-mappings/payment-acknowledgement.json:
"response": {
"destination": { "name": "partner-a/outbox", "type": "QUEUE" },
"fileName": "ack-{{request.fileName}}",
"text": "<ack><status>ACCEPTED</status></ack>",
"bodyType": "TEXT",
"fileMessageResponseTransformerClassName": "com.example.gateway.AcknowledgePayment"
}
Do this once the jar is loaded. A mapping that names a class Traffic Parrot has not loaded answers nothing: the request file stays where it is, and the log has an ERROR that names the file and the class.
Start the replay session again, since the restart turned it off. A payment of <amount>100.00</amount> is answered as before. One of <amount>0.00</amount>, uploaded as inbox/payment-5.xml, gets outbox/ack-payment-5.xml:
<ack><status>REJECTED</status></ack>
text is null. That section also shows a transformer that answers with a file, which Traffic Parrot copies without reading it into memory.Traffic Parrot does not speak the Connect:Direct protocol. Where the system under test sends and receives through its own Connect:Direct node, a real node has to answer it, and Traffic Parrot takes the gateway's place behind that node. Traffic Parrot's side is file replay, as on the rest of this page. The steps on a Connect:Direct node are marked: they need a licensed node, so we have not run them. Take their detail from IBM's documentation.
This is for a system under test that exchanges files with the gateway through its own Connect:Direct node. In the test environment that node talks to a test Connect:Direct node of yours, in place of the gateway's. The test node writes each file it receives into a directory, Traffic Parrot answers the file with a file in a second directory, and the test node sends that one back.
{
"id": "6c2d9a4e-1f3b-4e57-9b0a-2d7e5c8f1a01",
"request": {
"destination": { "name": "inbound", "type": "QUEUE" },
"fileNameMatcher": { "anything": "anything" },
"bodyMatcher": { "contains": "account,amount,currency" }
},
"response": {
"destination": { "name": "outbound", "type": "QUEUE" },
"fileName": "{{request.fileName}}.ack",
"text": "status\nACCEPTED\n",
"bodyType": "TEXT"
}
}
One thing this does not reproduce: the return code of a Connect:Direct Process is the real node's, so Traffic Parrot cannot make a copy fail on purpose. To test the gateway being unreachable, stop the test node.
Where File Agent is not available, a response transformer can submit the copy to the system under test's node itself, through IBM's Connect:Direct Java API, with IBM's jar beside the transformer's in lib/external. We have not built or run this: IBM's jar comes with a Connect:Direct entitlement. Two things follow from how a transformer runs:
This is for a test that includes a gateway of your own, which passes files on to a downstream partner over Connect:Direct while the system under test is not on that leg. It needs no Connect:Direct at all: in the test gateway, set the virtualised partner up as an SFTP partner. The gateway then logs in to Traffic Parrot's SFTP server and delivers there, as the system under test does in Mailbox upload and download. The gateway's own Connect:Direct configuration goes untested, which suits a test of your application and not a test of the gateway.
What you see, then why and what to do:
Missing something? See When the docs do not say for where else to look, or tell us what this page lacks.