Overview
Many systems of record — core banking, insurance policy administration, telecoms billing, logistics and government registries — are still reached through fixed-length messages over IBM MQ. A fixed header. A body laid out byte by byte. Amounts in the lowest currency unit. Field names abbreviated to six or eight characters. Result codes in two parts. Bodies in EBCDIC or ASCII depending on the sender.
When every consumer calls these messages directly, every consumer learns the format on its own. Each one re-implements the same layouts and meets the same specification defects. The knowledge concentrates in a few people, and every test cycle queues for a shared core test environment.
The pattern in this article has three parts:
- A machine-readable catalogue of every request and response layout, checked against its own arithmetic.
- A code generator that combines the catalogue with a reviewed design layer and emits OpenAPI 3.1 contracts, business flows, internal field mappings and DFDL models. A thin adapter on IBM ACE runs them.
- A wire-protocol simulator on the same runtime that answers every transaction code in the real format, plus a deterministic generator of data-driven contract tests.
Parsing one layout is the easy part. This article is about the step above: treating the whole message estate as data, and generating everything else from it. The running example is an account-to-account transfer, because it exercises amounts, holds and reversals; the method does not depend on the domain. Every code, field name and count below is invented for illustration.
The Message Catalogue
Everything starts with one decision: layouts are data, not documents. Interface specifications usually describe each message as a table. A parser reads the tables and writes one JSON catalogue. Each entry holds the transaction code, title, direction, every field with its type and length, and the declared total.
Repeating groups, shared structures and the common header become references, not copies. A layout is accepted only when its computed length matches the declared length. Anything else needs a recorded decision.
{
"code": "TX1001",
"title": "Account-to-account transfer",
"domain": "payments",
"request": {
"declaredBody": 128,
"fields": [
{ "name": "DBTACC", "type": "n", "len": 13 },
{ "name": "CRDACC", "type": "n", "len": 13 },
{ "name": "TXNAMT", "type": "ns", "len": 15, "signByte": true },
{ "name": "TXNCCY", "type": "a", "len": 3 },
{ "name": "CHNREF", "type": "an", "len": 32 },
{ "name": "FILLER", "type": "an", "len": 51, "reserved": true }
],
"computedBody": 128,
"status": "length-validated"
}
}
The status field matters most. Every layout ends up length-validated, a hand-verified override, or a documented spec error. Nothing stays unresolved. A useful rule: if the field list is internally consistent and the declared total is wrong, the field list wins and the defect is recorded.
What compiling the specifications typically finds
Specification tables are rarely checked against their own arithmetic. A compiler does it on the first run. Expect findings like these:
| Finding | Effect on a consumer built from the document |
|---|---|
| Wrong declared totals | Fields were added or widened and the total row never updated. A buffer sized from the total truncates or pads. |
| Undocumented sign bytes | A signed numeric field of N digits occupies N + 1 bytes, and the table does not say so. Every field after it shifts by one. |
| Reply longer than declared | A consumer reading by declared offsets reads the wrong bytes. |
| Wrong codes in headings | A table labelled with the code of a different message. |
| Draft or duplicated content | Duplicated fields or impossible structures that need a hand correction. |
Each consumer meets them separately and patches around them, and the patches do not always agree. That is the hidden cost of undocumented direct access: the same bug, fixed differently, in many places. A defect register sent to the core owner, plus overrides recorded with their reasoning, turns tribal knowledge into one reviewed source. Keep every override open until the core owner confirms the reading.
Options Compared
With a full catalogue in hand, there are four realistic ways to expose the core.
| A. Direct calls | B. Generic pass-through | C. Generated domain APIs, thin adapter | D. Full domain services | |
|---|---|---|---|---|
| Consumer effort | High, repeated | Medium — still core semantics | Low | Low |
| Contract quality | None | Core field names leak into every consumer | Business language, ISO formats, one outcome model | Best |
| Replaceability | None | None — the contract is the core | High — the contract is independent | High |
| Build effort | — | Low | Medium — generator plus review | Very high |
| Where logic lives | Consumers | Consumers | Core, unchanged | New services — duplicates the core |
For most estates, option C is the right trade. One API per business domain. The adapter maps names and formats, builds the header, does request–reply over MQ, maps outcomes and keeps an idempotency store. Balances, limits, eligibility and pricing stay in the core. The adapter adds no rules.
That buys replaceability without duplicating logic. The contract never names a core field, code or format, so any system that can answer the same operations can sit behind the same APIs.
The Design Layer
A catalogue alone produces mechanical APIs. POST /tx1001 with a body of abbreviations helps nobody. The design layer is the small, reviewed set of decisions a person has to make:
- Operation per code — name, HTTP method, resource path, audience (public or internal), or exclusion with a written reason.
- Vocabulary — abbreviation fragments to plain words, with per-field overrides where the mechanical result reads badly.
- Flows — which operations chain into a business flow, such as verify → post → reverse.
{
"TX1001": {
"operationId": "createAccountTransfer",
"method": "POST",
"path": "/account-transfers",
"audience": "public",
"timeoutMs": 20000
},
"TX9001": { "exclude": "technical heartbeat, no business meaning" }
}
{
"fragments": { "DBT": "debit", "CRD": "credit", "ACC": "account",
"TXN": "transaction", "AMT": "amount", "CCY": "currency" },
"overrides": { "CHNREF": "channelReference",
"DBTACC": "debitAccountNumber" }
}
Every code gets exactly one decision: public operation, internal operation, or excluded with a reason. Technical codes — heartbeats, sign-on, batch control — are typical exclusions. The design files are the governed source, reviewed per domain like any other architecture artefact, ideally with the consuming teams in the room.
The Generator
The generator must be deterministic: same inputs, same bytes out. From the catalogue plus the design layer it produces four artefact families:
| Artefact | Audience | Content |
|---|---|---|
| OpenAPI 3.1 contracts | Consumers | One per domain: operations, schemas, examples, headers and the outcome envelope. Validated on every run. |
| Business flows | Consumers | Sequence diagrams of chained operations; a few may also be published as single-call composite operations. |
| Field mappings | Internal low-level design only | Business field ↔ core field, type, length and conversion, per operation. Readable and machine-loadable. |
| DFDL models | Adapter and simulator | One static library per business domain plus a shared library for the header, so a flow references only what it uses. |
The last step of every run is a leak check. Public contracts must carry no core field names, no transaction codes and no specification references. The build fails if any appear.
def build_property(field, vocab):
# Reserved and filler fields are never exposed.
if field.get("reserved"):
return None
name = vocab["overrides"].get(field["name"]) or camel(
[vocab["fragments"][f] for f in split_fragments(field["name"])])
schema = FORMAT_RULES[field["type"]](field) # amount -> decimal string, date -> ISO
return name, schema
def leak_check(spec_text, catalogue):
forbidden = catalogue.all_field_names() | catalogue.all_codes()
hits = [t for t in forbidden if re.search(rf"\b{re.escape(t)}\b", spec_text)]
if hits:
raise SystemExit(f"core names leaked into public contract: {sorted(hits)[:10]}")
for domain in DOMAINS:
spec = render_openapi(domain, catalogue, design, vocab)
leak_check(spec, catalogue)
validate_openapi(spec) # fail fast on invalid 3.1
write(f"api-specs/{domain}.yaml", spec)
write(f"lld/mapping/{domain}.json", render_mapping(domain)) # internal only
write_dfdl_library(domain, catalogue)
The day someone fixes a contract by hand, the generator and the contract disagree. The next run silently reverts the fix, or people stop running the generator. Both end the same way: contracts drifting apart. Make the rule mechanical. A pipeline step regenerates and diffs; any difference fails the build. If a contract is wrong, fix the catalogue, an override or the design layer.
Contract & Outcome Model
Keep the conventions few and strict. Base path /{domain}/v1. Plural kebab-case resources. Commands take an idempotency key. Amounts are decimal strings with the number of decimals set by the ISO 4217 currency. Dates are ISO dates. Y/N flags become booleans. A count plus a repeating group becomes a JSON array.
The rule that needs the most agreement is the outcome model. A core that answers “insufficient funds” has worked correctly. That is a business outcome, not an error. So:
- Business declines are HTTP 2xx with
status: FAILEDand afailureDetailscategory. - RFC 9457 problem details (formerly RFC 7807) are only for protocol failures — validation (400), auth (401/403), conflicts (409), throttling (429) and upstream trouble (502/503/504).
HTTP/1.1 201 Created
Content-Type: application/json
{
"status": "FAILED",
"failureDetails": {
"category": "INSUFFICIENT_FUNDS",
"message": "Available balance is lower than the transfer amount.",
"retryable": false
},
"data": { "accountTransferId": "5b0e…" },
"meta": { "coreReference": "…" }
}
HTTP/1.1 504 Gateway Timeout
Content-Type: application/problem+json
{
"type": "https://api.example.test/problems/backend-timeout",
"title": "No reply from the core within the operation timeout",
"status": 504,
"detail": "Retry with the same X-Idempotency-Key."
}
Generate the mapping from core result codes to outcomes from the documented codes, into a versioned table. A partial success maps to COMPLETED with warnings. Any undocumented code falls to a generic decline and is logged for review. A 504 means the outcome is unknown: the caller retries with the same key, and if the core supports a possible-duplicate flag, the adapter sets it on the resend so the core replays rather than re-posts.
If a decline is a 4xx, every gateway, retry policy and dashboard treats it as a fault. Circuit breakers open on a run of insufficient-funds replies. Error-rate alerts fire on the busiest day of the month. Keep the transport signal and the business signal apart. Breakers count timeouts and unreadable replies, never FAILED outcomes.
The Wire-Protocol Simulator
Contracts are half the story. Testing them needs the core, and most organisations have one or two shared core test environments. Projects queue for them, overwrite each other’s data, and lose days to a missing seed account.
A simulator removes the queue. Build it on the same runtime as the adapter — here IBM ACE, from the generated DFDL models and ESQL. It listens on MQ (and HTTP if useful) and answers every catalogued code in the real wire format. The adapter should not be able to tell the difference; that is the point.
Encoding from the bytes
When some senders use EBCDIC and others ASCII, do not trust headers or configuration. If the transaction code is numeric, one byte decides: digits are X'F0'–X'F9' in EBCDIC and X'30'–X'39' in ASCII. Reply in the same code page and set the MQ descriptor to match.
CREATE FUNCTION DetectCcsid(IN frame BLOB) RETURNS INTEGER
BEGIN
-- Digits are X'F0'..X'F9' in EBCDIC and X'30'..X'39' in ASCII.
DECLARE b BLOB SUBSTRING(frame FROM CODE_OFFSET FOR 1);
IF b >= X'F0' AND b <= X'F9' THEN
RETURN EBCDIC_CCSID; -- e.g. 37 or 500
END IF;
RETURN ASCII_CCSID; -- the estate's ASCII code page
END;
Generic reply construction
Writing a handler per code does not scale past a few dozen. Build every reply the same way instead. Serialise an empty reply from the DFDL model, parse it back so every field exists with a default, then fill each field by a fixed precedence:
- Echo — if the request has a field with the same name, copy it.
- Naming convention — for the customer, account or posting the request refers to, take the value the field name implies: available balance, currency, IBAN, name.
- Default — today’s date or timestamp, otherwise blank or zero.
Repeating groups expand from the matching entity list — a customer’s accounts, an account’s postings. The result is a well-formed, ledger-consistent reply for every code with no per-code logic.
CREATE PROCEDURE FillField(IN rsp REFERENCE, IN req REFERENCE,
IN acct REFERENCE, IN fld CHARACTER)
BEGIN
-- 1. echo a request field with the same name
IF FIELDTYPE(req.{fld}) IS NOT NULL THEN
SET rsp.{fld} = req.{fld}; RETURN;
END IF;
-- 2. naming convention: the suffix says what the field holds
CASE SUBSTRING(fld FROM LENGTH(fld) - 2)
WHEN 'BAL' THEN SET rsp.{fld} = AvailableBalance(acct);
WHEN 'CCY' THEN SET rsp.{fld} = acct.currency;
WHEN 'IBN' THEN SET rsp.{fld} = acct.iban;
WHEN 'DAT' THEN SET rsp.{fld} = TodayYmd();
ELSE -- 3. leave the model default (blank or zero)
END CASE;
END;
A ledger, not canned replies
Canned replies pass a happy-path test and nothing else. Give the simulator a small stateful ledger, seeded with fictitious customers and accounts in every interesting state — active, blocked, dormant, closed, debit-frozen, low balance, overdrawn. For a non-banking core the same idea applies to its own entities: policies in force, lapsed and under claim; subscribers active, suspended and in arrears.
| Behaviour | What the simulator does |
|---|---|
| Verify | Checks status and available balance, places a hold for the amount. |
| Post | Releases the hold and posts principal, charge and tax legs. |
| Reverse | Finds the original by reference and posts the opposite entries. Rejects if not found or already reversed. |
| Repeat request | Idempotency key = code + channel reference. A plain repeat is rejected as a duplicate. |
| Possible-duplicate flag | The original reply is replayed byte for byte. Nothing is posted twice. |
| Maintenance | Add, modify and delete answer OK and are stored for inspection. |
| Fault rules | Timeouts, delays, forced rejections and field overrides, matched on code and field value. |
Some situations have no documented result code — hold not found, already reversed, duplicate reference. Answer these from a reserved range that appears in no specification. Map that range in the adapter to “pending core confirmation”, and put each item on a review list for the core owner. Inventing plausible codes bakes guesses into every consumer.
Be clear about the limit. The simulator is consistent with its own ledger; it does not reproduce every business rule of the real core. It replaces the core for integration and contract testing. It does not replace acceptance testing on the real core before release.
Data-Driven Contract Tests
Hand-written tests do not scale to hundreds of operations. Generate the cases deterministically from three inputs: the contracts, the internal mappings and the simulator seed. A request filler builds a valid body for any operation from a profile — a customer with accounts, a card, a loan, a beneficiary, or the equivalent entities of whatever core sits behind the APIs.
| Case type | What it proves |
|---|---|
| Happy | A valid request reaches the core and maps back to a schema-valid response. |
| Negative | Unknown account, inactive account, insufficient funds — the right FAILED category. |
| Protocol | Missing headers, invalid body, wrong types — 400 problem details, nothing sent to the core. |
| Flow | Verify → post → reverse, with balances checked before and after. |
| Idempotency | Same key and body replays; same key with a different body is 409. |
| Outcome | A stored outcome is retrievable later by its id. |
| Localisation | A second Accept-Language returns translated text, correctly encoded. |
| Timeout & forced reject | Simulator fault rules: 504 with unknown outcome; a forced decline mapped correctly. |
{
"id": "payments.createAccountTransfer.negative.insufficient-funds",
"phase": "main",
"tags": ["negative"],
"request": {
"method": "POST", "path": "/payments/v1/account-transfers",
"profile": "retail-low-balance",
"bodyFrom": "filler", "set": { "amount": "999999.00" }
},
"expect": { "http": 201, "status": "FAILED",
"category": "INSUFFICIENT_FUNDS", "schema": true }
}
Run in three phases. Main runs in parallel. Serial runs the balance-checked flows one at a time, because they assert exact balances. Scenario runs last: timeouts and forced rejections through simulator fault rules, each on a distinct code so it cannot disturb another case.
Report schema mismatches as findings, not failures. A mismatch usually means the catalogue, an override or the core disagree. That needs a decision, not a red build people learn to ignore.
Finally, call every catalogued code raw on the simulator and join the results into a coverage matrix: reached through a business API, reached raw only, or not covered.
Coverage Codes
Via business API (>=1 case reached core) 290
Via raw simulator call only 30 # the excluded technical codes
Not covered 0
Total 320
Production Traffic as Test Data
Seed data proves the mappings. Real traffic proves the edge cases nobody wrote down. A small masking tool can turn exported logs that contain raw core messages into test data — run inside the production security zone only.
- Split each message into fields using its catalogue layout. Classify each field by name and description.
- Replace values deterministically under a key, keeping length and format. The same customer maps to the same test customer everywhere, so linked flows stay linked.
- Move card numbers to a test range with valid check digits. Keep the structure and check digit of identity numbers. Keep names in their original script.
- Mask anything the layout does not cover as free text. Deny by default.
- Fail the run if any original value survives, or if anything looks like a live card number. Report counts and locations, never values.
The leak check proves the classified values are gone. It cannot prove the classification is complete, so a security sample review of the output belongs in the procedure.
Pitfalls
Most fixed-length integration bugs start with a buffer sized from a total row. Compute lengths from the field list, compare with every declared figure, and refuse to generate anything until each difference has a recorded decision.
One abbreviation in a public schema becomes a dependency for every consumer, and it survives any core change. The leak check is cheap; run it on every build, including descriptions and examples.
A thin adapter becomes a fat one, one “small rule” at a time. Then two places decide eligibility. Composite operations may sequence steps and stop at the first failure. They may not decide anything the core decides.
A green run against the simulator proves the integration and the contract. It does not prove the core’s business rules. Keep a short acceptance pass on the real core for each release, and feed every disagreement back into the catalogue or the simulator.
Steps to Adopt
-
Compile the specifications into a catalogue
Parse every message table into one JSON catalogue. Check every layout against its declared lengths. Record overrides and spec errors with their reasoning, and send the defect register to the core owner.
-
Split codes into business domains
Assign each code to a domain by code range, then by title keywords. One domain becomes one API, one DFDL library and one adapter application — also a natural bulkhead.
-
Write and review the design layer
Operation per code, resource paths, audience, exclusions with reasons, vocabulary and flows. Review it per domain, with consumers in the room.
-
Build the generator with a leak check and a drift check
Emit contracts, flows, internal mappings and DFDL models. Validate every contract. Fail on any core name in public output, and on any difference between committed and regenerated files.
-
Fix the outcome model before the first consumer
Declines as 2xx with
status: FAILED. Problem details only for protocol failures. Idempotency keys on every command. Generate the result-code mapping from the documented codes. -
Build the simulator on the adapter’s runtime
Same DFDL models, real wire format, encoding detected from bytes, generic reply construction, a stateful ledger, idempotency, fault rules and a reserved range for undocumented outcomes. Sweep every code with a default request.
-
Generate the contract tests and publish coverage
Deterministic cases from contracts, mappings and seed. Parallel, serial and scenario phases. Schema mismatches as findings. A coverage matrix across every code, refreshed on every run.
-
Feed real traffic back in, safely
Mask production exports inside the production zone, leak-check them, and turn them into seed data and replay cases. Every surprise becomes a catalogue fix or a new case.