IBM App Connect Enterprise (ACE)- Libraries

Photo by Alfons Morales on Unsplash

Introduction

Use case

Implementation

Figure 1 — REST API description
{"A" : 100, "B" : 200}
Figure 2 — REST API canvas
 DECLARE I DECIMAL 1;
DECLARE J DECIMAL 1;
SET I = InputRoot.JSON.Data.A;
SET J = InputRoot.JSON.Data.B;
SET I = I * 0.5;
SET J = J * 0.25;
SET OutputRoot.JSON.Data.procesedA = I;
SET OutputRoot.JSON.Data.procesedB = J;
Figure 3 — Logger library canvas
 SET OutputRoot = InputRoot;
SET OutputLocalEnvironment = InputLocalEnvironment;
SET Environment.MSG_TYPE = '[INPUT]';
SET Environment.REQ_URL = COALESCE('[' || InputLocalEnvironment.Destination.HTTP.RequestURL || ']', '[]');
 IF Environment.UID IS NULL THEN 
SET Environment.UID = UUIDASCHAR;
END IF;

SET OutputRoot = InputRoot;
SET OutputRoot.HTTPInputHeader = NULL;
SET OutputRoot.HTTPResponseHeader = NULL;

DECLARE MSG_STRING CHAR;
CREATE FIRSTCHILD OF Environment DOMAIN 'JSON' Name 'Variables';
SET Environment.Variables.OUT_MSG = OutputRoot;

SET MSG_STRING = CAST(ASBITSTREAM (Environment.Variables.OUT_MSG) as CHAR CCSID 1208);
SET MSG_STRING = OutputRoot.returnCode;

DECLARE v_carriage CHAR;
SET v_carriage =CAST(X'0A' AS CHAR CCSID 1208);
SET Environment.MSG_STRING = REPLACE(MSG_STRING,v_carriage,'');

SET Environment.MSG_SOURCE = '[' || BrokerName || '][' || ExecutionGroupLabel || '][' || MessageFlowLabel|| ']';

SET OutputRoot = InputRoot;
SET OutputLocalEnvironment.Destination.File.Directory = 'C:\temp\log\'; 
DECLARE LOG_DATE CHARACTER CAST(CURRENT_TIMESTAMP AS CHARACTER FORMAT '_yyyy_MM_dd');
SET OutputLocalEnvironment.Destination.File.Name = 'log' || LOG_DATE;

DECLARE v_carriage CHAR;
SET v_carriage = CAST(X'0A' AS CHAR CCSID 1208);
DECLARE NOW CHARACTER;
SET NOW = CAST(CURRENT_TIMESTAMP AS CHARACTER FORMAT 'yyyy-MM-dd HH:mm:ss');

SET OutputRoot.BLOB.BLOB = CAST(NOW ||' — '|| Environment.MSG_SOURCE ||' — '||Environment.UID ||' — '|| Environment.MSG_TYPE ||' — '|| Environment.REQ_URL || '— '|| Environment.MSG_STRING || v_carriage AS BLOB CCSID 1208) ;
Figure 4 — REST API after adding loggers
Figure 5 — Postman sample call
2020–10–13 09:46:47 — [integration_server][wd-ace][gen.M3_LibSample] — 03fc9eff-799c-41e4–8759–7fece3d8c40b — [INPUT] — [] — {“Properties”:{“MessageSet”:””,”MessageType”:””,”MessageFormat”:””,”Encoding”:546,”CodedCharSetId”:1208,”Transactional”:false,”Persistence”:false,”CreationTime”:”2020–10–13 04:16:47.555",”ExpirationTime”:-1,”Priority”:0,”ReplyIdentifier”:”000000000000000000000000000000000000000000000000",”ReplyProtocol”:”SOAP-HTTP”,”Topic”:null,”ContentType”:”application\/json”,”IdentitySourceType”:””,”IdentitySourceToken”:””,”IdentitySourcePassword”:””,”IdentitySourceIssuedBy”:””,”IdentityMappedType”:””,”IdentityMappedToken”:””,”IdentityMappedPassword”:””,”IdentityMappedIssuedBy”:””},”JSON”:{“Data”:{“A”:100,”B”:200}}}
2020–10–13 09:46:47 — [integration_server][wd-ace][gen.M3_LibSample] — 03fc9eff-799c-41e4–8759–7fece3d8c40b — [OUTPUT] — [] — {“Properties”:{“MessageSet”:null,”MessageType”:null,”MessageFormat”:null,”Encoding”:null,”CodedCharSetId”:null,”Transactional”:null,”Persistence”:null,”CreationTime”:null,”ExpirationTime”:null,”Priority”:null,”ReplyIdentifier”:null,”ReplyProtocol”:”SOAP-HTTP”,”Topic”:null,”ContentType”:null,”IdentitySourceType”:null,”IdentitySourceToken”:null,”IdentitySourcePassword”:null,”IdentitySourceIssuedBy”:null,”IdentityMappedType”:null,”IdentityMappedToken”:null,”IdentityMappedPassword”:null,”IdentityMappedIssuedBy”:null},”JSON”:{“Data”:{“procesedA”:50.0,”procesedB”:50.00}}}

Conclusion

References

Integration developer, worked on WSO2, IBM integration stack. Java, Spring, Micro-services aficionado.