Skip to main content
Skip table of contents

Custom adapter

There is a specific type of adapter called a Custom Adapter which can be used to configure adapters that may be specific to an installation, such as a call to an in-house logging API or to an in-house database connection API. A custom adapter should extend the base class "be.securit.trustbuilder.adapter.kernel.Adapter".

Configuration

AdapterUniqueID

Unique name assigned to this adapter; the name is used to reference the adapter in the workflow. The ID has following requirements:

  • START with a letter or _ (underscore)

  • FOLLOWED by a combination of following characters: Letter, Number, '.' (dot), '-' (dash), '_' (underscore)

Workflow Settings

A request for the adapter is prepared by specifying the following properties/scripts in the adapter activity:

  • Input Property: the variable containing the instructions the adapter have to execute

  • Output Property: the variable the adapter will store the response in after execution

  • Before Adapter Script: script that will be executed before calling the adapter

  • After Adapter Script: script that will be executed after the adapter fulfilled its task

Request - API

In order to generate a request in the scripts it is considered best practise to create a function like this:

CODE
var createMyCustomAdapterRequest = function(payload){
     return new Packages.my.tld.package.RequestClass(payload);
}

Response - API

Common Properties The response API can be applied to the variable specified in the "output property" (see "Workflow Settings"): to verify whether the action performed by the adapter was successful, to query for the data returned by the adapter.

All responses have four properties in common:

  • status Status flag indicating whether the response is ok (0) or not (1).

  • substatus Response specific number indicating what the problem was, eg. http status code

  • message Response specific message in case there was a problem (can be null)

  • rc Return Code, a human readable code based on the substatus

The status flag indicates whether a request was valid yes or no; consequently, the message or return code (rc) can be used to give the end-user a reasonable explanation or send the information to the underlying logging system.

Extending the response api If you want your custom adapter responses to behave like real javascript object you can register a converter. This is a function that converts your java response class into a javascript object.

CODE
tbres.converters['MyCustomAdapterResponseClass'] = function(responseInstance){
     // convert to js object 
     return {
        myProperty: String(responseInstance.getMyProperty()) // cast to javascript string
     };
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.