Calling CICS services
You can use the invoke function from the ibm-cics-api
module to call a CICS service. Node.js has two popular mechanisms for asynchronous activities, callback functions and promises. Either technique can be used.
const cics = require('ibm-cics-api');
let uri = "http://winmvs2c.hursley.ibm.com/exampleApp/json_inquireCatalogWrapper";
let requestData =
{
"inquireCatalogRequest":
{
"startItemRef": 10,
"itemCount": 774
}
};
//Version using callback
cics.invoke(uri,requestData,function(err, data)
{
if (err)
{
... do something with error ....
}
else
{
.... do something with response data
}
});
//Version using promises
cics.invoke(uri,data).then
(
function(response)
{
... do something with response ...
},
function(err)
{
console.log(err);
}
);
- A URI (string) - this identifies the target service. It's used to match a URIMAP in CICS, which then maps to the WEBSERVICE, PIPELINE and eventually target PROGRAM.
- Request data (JavaScript object or string) - the data that is sent to the CICS service as the request body. This data must be in the JSON format expected by the target service in CICS.
- A callback function - this function is called by CICS when a response is ready to processed by the Node.js application. This function is not applied if you are using promises.
- An error object. This is null if the request succeeds. If it fails, this is a JavaScript Error object that describes the error.
- A response object. This is a JavaScript object which represents the response from CICS.
Error handling
httpCode
represents the error with an equivalent HTTP status.
The following example is of an error when printed to
stderr
:{ Error: CICS error: internal server error
at Error (native)
code: 'ERR_CICS_INTERNAL_ERROR',
httpCode: 500,
response: '{"Fault":{"faultstring":"Failure interacting
with CICS","detail":{"CICSFault": "DFHPI1007 08\\/21\\/2018 09:06:17
IYK2ZKE1 CNJW 00121 JSON to data transformation failed because
of incorrect input (UNDEFINED_ELEMENT foo) for WEBSERVICE
json_inquireCatalogWrapper."}}}' }
Code | Message | httpCode | Description |
---|---|---|---|
ERR_CICS_BAD_REQUEST | CICS error: bad request | 400 | An error in the data passed to CICS from the application. Typical errors include a malformed or invalid URI. |
ERR_CICS_FORBIDDEN | CICS error: forbidden | 403 | An authorisation error. Typically the userid associated with the URIMAP isn't authorized to attach the target TRANSACTION. |
ERR_CICS_NOT_FOUND | CICS error: resource not found | 404 | A configuration error. One of the CICS resources involved in the processing cannot be found; the missing resource may be the URIMAP, TRANSACTION, or PIPELINE resource. The most common problem involves use of a URI that is not known to CICS. |
ERR_CICS_INTERNAL_ERROR | CICS error: internal server error | 500 | A problem occurred within CICS. Typical problems include the target Service having abended, or a data transformation error having occurred. Diagnostics are issued by CICS to describe the problem, and an explanatory message might be available in the 'response' attribute of the error object. The most common problem involves a mismatch between the JSON request data, and the JSON format that is expected within CICS. |
ERR_CICS_UNAVAILABLE | CICS error: unavailable | 503 | A resource in CICS has been disabled. Either the URIMAP, TRANSACTION or PIPELINE resource is currently unavailable. |
Unit testing
The invoke function supports local and remote CICS invocations. When the Node.js application is run in CICS the request is optimized into a cross-memory system call that does not use the network. When the Node.js application is run outside of CICS the request is sent to CICS using HTTP or HTTPS based on the URI. This remote capability is intended for unit testing purposes only.
When using the ibm-cics-api
module to connect to CICS over HTTP, it is not possible to set HTTP headers such as basic authentication, or send client certificates. If you need to do this, use other Node.js modules instead.