What’s New in EPC 141070

by | Oct 24, 2017

EPC 141070 for SP1 contains a couple of new features and bug fixes for LANSA RDMLX Extended Library.

New Features

XPRIM_Binary to Represent Binary Data

Use XPRIM_Binary to represent binary data (such as a byte array or a file), and use the built-in methods to convert or create binary data to/from Base64-encoded string, hex string. Also encode/decode strings using UTF-8 encoding into bytes.

Define_Com Class(#XPRIM_Binary) Name(#BinaryData)
* Set #BinaryData to file '/tmp/test.pdf
#BinaryData.FromFile Path('/tmp/test.pdf')
* Get Base-64 representation of the file
#Base64EncodedString := #BinaryData.AsBase64String

See this section in the LANSA Technical Reference for more details.

Cryptographic Hash Functions

If you maintain your own list of users and passwords for your website, you would need to compute the hashes of your user’s passwords. This release comes with a new XPRIM_Crypto_Hash component that lets you compute the hash of any data, including passwords. It currently supports MD5, SHA-256, SCrypt, and PBKDF2 algorithms.

Define_Com Class(#XPRIM_Binary) Name(#PasswordBytes)
Define_Com Class(#XPRIM_Binary) Name(#HashBytes)
Define_Com Class(#XPRIM_Crypto_Hash) Name(#GenerateHash)
* Convert password to bytes using UTF-8 encoding
#Bin.FromStringUsingUTF8 String(#Password)
* Compute MD5 hash of the password
#GenerateHash.Compute Input(#PasswordBytes) Result(#HashBytes)
* Convert hash bytes into base-64 encoded string
#Hash := #HashBytes.AsBase64String
* Store #Hash in the password field of the user database table 
. . .

There is a also a support for generating authentication code of a message, using HMAC-SHA256 algorithm. This is provided by the XPRIM_Crypto_HMAC component. Some web services such as Microsoft DocumentDB uses HMAC to authenticate every request.

See this section in the LANSA Technical Reference for more details.

XPRIM_File for Basic File Operations

  • Read all text from a file
  • Write all text to a file
  • Delete a file
  • Check if a file exists
  • Get the length of a file
  • Create all required directories in the path to a file
Define_Com Class(#XPRIM_File) Name(#MyFile)
Define_Com Class(#PRIM_DC.UnicodeString) Name(#MyString)

#MyFile := '/tmp/test.txt'
#MyString := #MyFile.ReadAllText

New JSON reader and writer components for faster reading and writing of big JSON data

XPRIM_JsonObject and XPRIM_JsonArray are perfect to hold an in-memory representation of your JSON data that you can pass around between methods, but may not perform so well when you use them to parse or serialize large amount of JSON data.

See this section in the LANSA Web Services Guide for more details.

New Methods to Read/Write JSON to Files

Debugging is made easier with some new methods to easily parse or write JSON to/from files on the file system.

Define_Com Class(#XPRIM_JsonObject) Name(#JsonObject)
#JsonObject.ParseFile Path('/tmp/MyJson1.json')
#JsonObject.SerializeToFile Path('/tmp/MyJson2.json')

Less Need to Declare Your XPRIM_JsonObject (or XPRIM_JsonArray) as *DYNAMIC

Constructing your JSON data for your HTTP request used to be such a chore with lots of *DYNAMIC references required. You won’t need to do so much of that anymore for 2 reasons:

  • You should opt for using XPRIM_JsonWriter when constructing your JSON data.
  • If you still want to use XPRIM_JsonObject/XPRIM_JsonArray, you can now directly insert an existing element using the InsertElement method, instead of having to use InsertObject and InsertArray.
Define_Com Class(#XPRIM_JsonObject) Name(#RootObject)
Define_Com Class(#XPRIM_JsonObject) Name(#ChildObject)
* Insert child object into root object using 'InsertElement' method
#RootObject.InsertElement Element(#ChildObject)

Bug Fixes

  • Explicit Content-Type header set using AddHeader should override any derived values.
  • The Content-Type for JSON data should be application/json instead of application/json; charset=utf-8.
  • File names and item names specified as parameters in the Content-Disposition header should be automatically quoted.