Protocol Adapters

Data processing on Nexacro Platform does not convert data itself. It handles requests and responses by using a basic protocol HTTP. However, encrypted data communications or data conversion might be needed depending on user environments.

A protocol adapter is a tool connecting two different types of data so that they can work together as you want. With a simple setting, you can make a function easy to use.

Protocol Adapter

Protocols, modules and service items can be added by registering default_typedef.xml file which is in the project folder directly or adding relevant items in [Edit TypeDefinition] window by double-clicking Typedefinition item in project explorer window.

Registering Modules

You can register modules by editing the default_typedef.xml file which is in the project folder directly or by adding new items in the [Edit TypeDefinition > Modules] window.

Modules and script files to be registered will reside in the path under the [component] folder subordinate to a path designated for Base Lib Path on Nexacro Studio.

The default value for the Base Lib Path is the nexacro14lib folder under the path where Nexacro Platform is installed.

You can change the Base Lib Path by using [Tools >Options > Environment > Build > Base Lib Path].

Module files will be written in JSON files as follows. Paths for JavaScript designated in the scripts item must have relevant folders and script files under [Base Lib Path > component] folder.

{
"name": "Xecure",
"version": "14.0.0.0",
"description": "nexacro platform XecureAdp Protocol Library",
"license": "",
"scripts": [
"Xecure/Xecure.js", 
]
}
//@ sourceURL=Xecure.json
<Module url="Xecure.json"/>

Registering Protocols

You can register protocols by editing default_typedef.xml file in the project folder directly, or adding relevant items in [Edit TypeDefinition >Objects] window.

<Component type="Protocol" id="Xecure" classname="nexacro.XecureAdp"/>

Interfaces defined in classes registered as protocols will be called at the relevant time. It works in frameworks as follows.

  1. Write nexacro.ProtocolAdp as an inherited class.

    At the initial call of the registered protocol, the ProtocolAdptor object is created. The relevant object will be used at the time of communication until an application terminates.

var _pXecureAdp = nexacro._createPrototype(nexacro.ProtocolAdp);	
nexacro.XecureAdp.prototype = _pXecureAdp;
  1. The initialize function will be called when the object is being created.

_pXecureAdp.initialize = function ()			
{	
	trace("_pXecureAdp.initialize");
};
  1. The finalize function will be called when the object is being deleted.

    It is called when the application terminates.

_pXecureAdp.finalize = function ()			
{			
	trace("_pXecureAdp.finalize");	
};
  1. The version function will be called to provide the information on the version of the protocol adapter. If this function is absent, Nexacro Platform will identify the version as 1.0. However, to utilize getHTTPHeader() function, version() must be called and the adapter version must be 1.1 or higher.

_pXecureHttp.version = function ()
{
      return "1.1";
};
  1. The getHTTPHeader function will be called to provide the information on an HTTP header. _httpheaders is an array object that contains on an HTTP header.

_pXecureHttp.getHTTPHeader = function ()
 {
   return this._httpheaders;
 };
  1. The encrypt function will be called before actual communication is called internally.

    Before the communication, data to be transmitted will be encrypted or converted to a desirable form.

_pXecureAdp.encrypt= function(url, data)
{
        trace("encrypt url=" + url + ";data=" + data);
        return data;
};

The encrypt function is called only when the request method is POST.

When the transaction or load method is called, the request method works as POST unless there is a special setting regarding GlobalVariables.

  1. Decrypt function will be called after the communication terminates internally.

    It decrypts received data or converts the data in a desirable form.

_pXecureAdp.decrypt = function (url, data)
{
        trace("decrypt url=" + url + ";data=" + data);
        return data;
};

The entire code of the class registered as a protocol is as follows. The actual code will be adjusted depending on user environments.

if (!nexacro.XecureAdp)
{
    nexacro.XecureAdp  = function ()
    {
        
    };
        
    var _pXecureAdp = nexacro._createPrototype(nexacro.ProtocolAdp);
    nexacro.XecureAdp.prototype = _pXecureAdp;

    _pXecureAdp._type = "nexacroXecureAdp";
    _pXecureAdp._type_name = "XecureAdp";
    _pXecureHttp._httpheaders = [];
    _pXecureHttp._httpheaders.push({ id: "X-Requested-With", value: "XMLHttpRequest"});
    _pXecureHttp._httpheaders.push({ id: "Accept", value: "application/json, text/json, */*"});
    _pXecureHttp._httpheaders.push({ id: "Content-Type", value: "application/json"});


    _pXecureHttp.version = function ()
    {
        return "1.1";
    };

    _pXecureHttp.getHTTPHeader = function ()
    {
      return this._httpheaders;
    };

    _pXecureAdp.encrypt= function(url, data)
    {
        trace("encrypt url=" + url + ";data=" + data);
        return data;
    };

    _pXecureAdp.decrypt = function (url, data)
    {
        trace("decrypt url=" + url + ";data=" + data);
        return data;
    };

    _pXecureAdp.initialize = function ()
    {
        
       trace("_pXecureAdp.initialize");
    };

    _pXecureAdp.finalize = function ()
    {
	 trace("_pXecureAdp.finalize");
    };

    delete _pXecureAdp;
}

Registering Services

You can register services by editing the default_typedef.xml in the project folder directly, or adding relevant items in the [Edit TypeDefinition > Services] window.

<Service prefixid="xecuredata" type="js" url="Xecure://localhost/" version="0" communicationversion="0"/>

You can call a form registered as a service group through a protocol adapter by registering an URL as follows when registering the service group.

<Service prefixid="Base" type="form" url="Xecure://localhost/Base" version="0" communicationversion="0"/>
this.Div00.set_url('Base:test.xfdl');

Calling Data

When you call a registered service, communication will start through a relevant protocol.

application.transaction("MyService01", "xecuredata::test.js", "dsIn=dsIn:A","dsOut=dsIn","a=b","fnCallback");

Data is processed as follows.

  1. To call data using a relevant protocol

    Application.transaction(), Dataset.load(), Div.set_url();

  2. To initialize the protocol

    initialize

  3. To convert transmitted data

    encrypt

  4. To call the server

    To transmit the converted data to the designated server

  5. To receive a response from the server

  6. To convert the received data

    decrypt

  7. To process the callback function or data

    To process the data depending on call types.

PluginElement

When processing data, you need to set an extension plugin instead of script processing in case an additional security method such as encryption is needed. You can apply an extension plugin by using PluginElement.

An extension plugin might require additional code according to rules provided by the relevant solution. The description below guides you to use PluginElement in general.

The description lets you know how to apply XecureWeb for web section encryption.

As it is written as an example for reference, some contents might be missing.

Please refer to the following link (Korean) for the details about the product.

http://www.softforum.co.kr/02product/pro_sub01_02.asp

For the Runtime version, you are recommended to install an extension plugin by calling the installation web page at the initial execution of the application.

By doing so, you can identify which is the cause of a problem—whether the web browser or Nexacro Platform—if the problem occurs in the installation process.

Protocol Class Code

When using PluginElement, you can use it in the same way of protocol adaptors. Only the class code registered as protocols will be partially changed.

  1. The initialize function will be called when an object is being created.

    nexacro.PluginElement can be used as an internal plugin

    It is created without Parent_element and added to the hidden area of the framework. For that reason, it is not displayed on the screen.

_pXecureAdp.initialize = function ()	
{	
	trace("_pXecureAdp.initialize");
	var parent_elem = null;
	this.xecure = new nexacro.PluginElement();
	this.xecure.setElementClassId("{7E9FDB80-5316-11D4-B02C-00C04F0CD404}");
	this.xecure.create();  
};
  1. The finalize function will be called when the object is being deleted.

    It is called when the application terminates.

_pXecureAdp.finalize = function ()			
{			
	this.xecure.destroy();			
	delete this.xecure;			
};
  1. The encrypt function will be called before actual communication is called internally.

    Before the communication, data to be transmitted will be encrypted.

_pXecureAdp.encrypt= function(url, data)			
{			
	return data;			
};
  1. The decrypt function will be called after the communication terminates internally.

    It decrypts the received data.

_pXecureAdp.decrypt = function (url, data)			
{			
	return data;			
};
  1. A protocol to be used for the communication will be returned from the getUsingProtocol function.

    The default protocol is HTTP.

_pXecureAdp.getUsingProtocol = function (url)			
{			
	return "http"; 
};
  1. Additional information to be included in the cookie during the communication will be returned from the getCommunicationHeaders function.

_pXecureAdp.getCommunicationHeaders = function (url)			
{			
	var headers = [];		
	headers.push({id:"test", value:"test1"});		
	return headers;		
};