Showing posts with label esql. Show all posts
Showing posts with label esql. Show all posts

Thursday, 16 January 2025

Sending file as multi-part MIME over http in ACE - esql

 

How to send a file over http as a multipart mime?


Below are the steps to do that -


1. Make sure you have the data encryption in place for data security, which is important when transferring data through network protocol.


2. Now copy the output data as blob in a variable to use it later in below section-

SET OutputRoot = InputRoot;

DECLARE Content BLOB CAST(Environment.TGCSARC.FILEDATA AS BLOB);


3. Set the required authentication/authorization headers for backend -

SET OutputRoot.HTTPRequestHeader."Authorization" = 'Basic '|| Base64-encoded (ID:PASS);

SET OutputRoot.HTTPRequestHeader."Date" = CAST(CURRENT_TIMESTAMP AS CHARACTER FORMAT 'yyyyMMddHHmmss');

SET OutputRoot.HTTPRequestHeader."Host" = Backend-HOST;


Note : ID:PASS should be encoded in base 64 


4. Set Headers for content type -

SET OutputRoot.Properties.ContentType = 'multipart/form-data; boundary=' || UUIDASCHAR;

SET OutputRoot.HTTPRequestHeader.Accept = '*/*';


5. Now create output message domain as MIME and add data like below -


CREATE LASTCHILD OF OutputRoot DOMAIN('MIME');

CREATE LASTCHILD OF OutputRoot.MIME TYPE Name NAME 'Parts';

CREATE LASTCHILD OF OutputRoot.MIME.Parts TYPE Name NAME 'Part';

DECLARE P1 REFERENCE TO OutputRoot.MIME.Parts.Part;

CREATE FIELD P1."Content-Type" TYPE NameValue VALUE 'text/plain';

CREATE FIELD P1."Content-Disposition" TYPE NameValue VALUE 'form-data; name="file"; filename="' || Environment.Variables.InputFileName || '"';

CREATE LASTCHILD OF P1 TYPE Name NAME 'Data';

CREATE LASTCHILD OF P1.Data DOMAIN('BLOB') PARSE(Content);


6. Now set the target URL and method to post and propagate to out terminal -

    SET OutputLocalEnvironment.Destination.HTTP.RequestURL  = Target-Endpont;

     SET OutputLocalEnvironment.Destination.HTTP.RequestLine.Method = 'POST';

     PROPAGATE TO TERMINAL 'out';



Wednesday, 13 December 2023

Overriding UDP - External Variable Properties in IBM IIB OR ACE

 

As we all know we have different types of variables available in ESQL which we can define, use and modify during flow processing.


But there are certain challenges with UDP - user defined properties that we also know as External Variables.


These variables holds static values and we have very limited options to modify them once the flow is deployed.

So lets explore those options -


1. First and foremost option to override them before you deploy the flow using toolkit BAR builder or using mqsiapplybaroverride command

2. if in case you have deployed the flow/bar and you do not wish to update the property and redeploy the flow, then you can use WebUI to update the UDP value - 





But you will face another challenge with this as it will not persist the updated UDP value permanently.

The update value would only be available until you redeploy the flow, or application is restarted or the integration server is restarted.


So how can we persist the updated value? 

we have to update settings/configuration for the integration server by modifying the UserVariables section in the server.conf.yaml file


UserVariables: udp-persist-global-overrides: true






Wednesday, 13 September 2023

Handling BLOB message(xml data as blob) in Esql



                                 Parsing XML data from a blob message




/** input of this sample is a XML message 
                 ** <XmlCollection>
                 **<Collection>3c546573743e48656c6c6f20507269796573683c2f546573743e</Collection>
                 **</XmlCollection>

Collection is a XML data in hexadecimal (BLOB) representation
Create an element of type parser

**/

CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNSC' NAME 'XMLNSC';
-- Create the root tag element of your output XML
CREATE LASTCHILD OF OutputRoot.XMLNSC NAME 'RootTag';

IF EXISTS(InputRoot.BLOB[]) THEN
------<Test>Hello Priyesh</Test>---
CREATE LASTCHILD OF OutputRoot.XMLNSC.RootTag.RecSec PARSE(CAST(InputRoot.BLOB.BLOB AS BLOB) OPTIONS FolderBitStream CCSID 1208 FORMAT 'XMLNSC');

ELSE



DECLARE ptrCollection REFERENCE TO InputRoot.XMLNSC.XmlCollection.Collection;
WHILE LASTMOVE(ptrCollection) DO
--Parse the BLOB into XML using the PARSE function
CREATE LASTCHILD OF OutputRoot.XMLNSC.RootTag.RecSec PARSE(CAST(ptrCollection AS BLOB) OPTIONS FolderBitStream CCSID 1208 FORMAT 'XMLNSC');
MOVE ptrCollection NEXTSIBLING;
END WHILE;

END IF;




 Parsing XML data into blob message



/***
****  Sample input to convert into BLOB
--------------------------
<Orders>
<Order>
<OrderDetails>
<OrderID>1234</OrderID>
<NumOfItems>2</NumOfItems>
<TotalAmount>3000</TotalAmount>
<OrderDate>07/13/2017</OrderDate>
</OrderDetails>
</Order>
<Order>
<OrderDetails>
<OrderID>1235</OrderID>
<NumOfItems>4</NumOfItems>
<TotalAmount>6000</TotalAmount>
<OrderDate>07/13/2017</OrderDate>
</OrderDetails>
</Order>
</Orders>
------------------------
****/

--- creating blob message domain

CREATE LASTCHILD OF OutputRoot DOMAIN 'BLOB' NAME 'BLOB';

--creating blob root for the message

CREATE LASTCHILD OF OutputRoot.BLOB NAME 'BLOB';

-- creating a reference to the blob message root.

DECLARE refBlob REFERENCE TO OutputRoot.BLOB.BLOB;

-- assigning message data by converting it into blob using ASBITSTREAM function-

SET refBlob = ASBITSTREAM(InputRoot.XMLNSC.*[>] OPTIONS FolderBitStream CCSID 1208);


--- Creating Environment variable to get the xml data back for verification whether previous conversion was successful
----and contains data properly.

CREATE LASTCHILD OF Environment DOMAIN 'XMLNSC' NAME 'XMLNSC';

CREATE LASTCHILD OF Environment.XMLNSC  PARSE(CAST(OutputRoot.BLOB.BLOB AS BLOB) OPTIONS FolderBitStream CCSID 1208 FORMAT 'XMLNSC');



Output :










Sending file as multi-part MIME over http in ACE - esql

  How to send a file over http as a multipart mime? Below are the steps to do that - 1. Make sure you have the data encryption in place for ...