Different Structure Based on Status Code
Sometimes MF buffers’ structures change by the program scenario. With OpenLegacy, you can define the desired structure with a status code and handle the different structures.
What is the status code?
A status code is an integer that describes a buffer structure with hash, for example, F0
will be presented as 15 and F0F0
as 449.
Example hashes:F0
- 15F0F0
- 449F0F1
- 450F1F0
- 480F1F1
- 481F1
- 1600
- 31
There are no success or error status codes - the customer can select the expected status code.
Status code indicator:
You can indicate the specific success structure by the following application.yml configurations.
ol.cics.project.[orchestrated-key].status-code
Key | Type | Default Value | Description |
---|---|---|---|
default-success-value | Int | 15 | The default value indicates success. Default value represents |
indicators[] | List<StatusCodeIndicator> | Empty list | List of status code indicators |
indicators[].offset | Int | 0 | Offset in the buffer to start read the status code |
indicators[].length | Int | 1 | Number of bytes to read from the offset |
Application.yml for example:
ol:
cics:
project:
bla:
base-url: http://localhost
port: 9090
uri-map: /api/echo
code-page: CP037
user:
password:
status-code:
default-success-value: 15
indicators:
- length: 2
offset: 0
How to handle a different structure?
Currently, we have two cases:
The returned status code matched the
default-success-value
- no exception is thrown.The return status code doesn't match the
default-success-value
- anOperationNotMappedException
will be thrown.
The OperationNotMappedException
contains the full buffer, the status code bytes, and a message with the status code.
We can handle the OperationNotMappedException
with try
and catch
, in case of more than one known status code we can use a switch case
block.
An example use case:
In the following example, we will use a simple echo program that returns the same value as it sent in the response.
For this example I’ll decide that my excepted result is:
{
"echo" : "0"
}
It means that the byte value is F0
and the status code is 15. This value placed at the first byte on the response buffer and its length is 1 byte.
My status code configuration should be:
status-code:
default-success-value: 15
indicators:
- length: 1
offset: 0
If I’ll send “0” in the request I’ll get my excepted response, for every other request I’ll get the following exception:
We can catch this exception and handle the different status codes, for example:
E.g: when echo set to 1, we will get