JSMA web

Overview

The JSMA web alows you to request/send data via HTTP calls from serverside.

What can JSMA file do for me?

With JSMA web you can easily create SOAP or other web based service integrations.

Consider delay from web calls

These calls are done synchronously. So if you use them to render customer pages please consider that the delay will increase your overall page load.


Index

Usage

reading data

Here is an example on how to read data from a JSMA web:

... 
var callData = web.json(result.backendServiceURL, result.callOptions);
result.callData = callData;
...

Methods

The JSMA web provides the following methods:

callresult web.html(string url, [object options])

Calls the given URL from the server side and returns the callresult.

Example 1

... 
var result = web.html(args[0]);
return result.data;
...

Example 2

... 
var url = '...';
var response = web.html(url, { accept: 'image/jpeg', user: 'user', password: 'password', type: 'get', raw: true });
var newFile = files.create({ file: response.data, name, name: response.filename });
...

Parameter string url

The url to retrieve the data from.

Parameter object options (optional)

These options are passed to the restclient gem.

For example:

  • accept: sets the Accept-Header
  • user: sets the username used for basic authentication
  • password: sets the password used for basic authentication
  • type: HTTP Request Method (get, post, patch, put, delete, head)
  • raw: boolean. If enabled the received data will be saved in a tempfile. callresult.data will have a reference to the tempfile. Also callresult.filename will be set from the Content-Disposition Header if available.

All other options will be used as header key/value pairs

Returns callresult

The returned data as callresult.

{
  code: response.code,
  data: response.body,
  cookies: response.cookies,
  headers: response.headers,
  filename: response.filename
}

Error result

If there was an error retrieving the data from the given url, the result contains the return-code and the error-information within the body. Therefore it is recommended to check the response-code bevore handling the data. 

Example:
{ 
  code: 500, 
  body: 'EXCEPTION_INSPECT_OUTPUT' 
}

Please be also aware, that even if the response-code is "200" there is no guarantee that the url has returned all data! Instead check whether the data are correct - example:

var searchedElements = callResult.data.match(...);

if (searchedElements)
{
	var firstElement = searchedElements[0]; 
}

callresult web.json(string url, [object options])

Calls the given URL from the server side, tries to parse the response body assuming it is JSON encoded and returns the resulting object in the callresult. If the received data is not in valid JSON format an exception will be thrown.

Example

... 
var callData = web.json(result.backendServiceURL, result.callOptions);
result.callData = callData;
...

Parameter string url

The url to retrieve the data from.

Parameter object options (optional)

Field payload (Experimental)

Allows to put data directly as string into the call without any conversion and preserving the given header attribute 'content-type'.


Returns callresult

The returned data as callresult.

{
   code: response.code,
   data: data, // => object from parsed JSON-encoded data
   cookies: response.cookies,
   headers: response.headers
}

Error result

If there was an error retrieving the data from the given url, the result contains the return-code and the error-information within the body. Therefore it is recommended to check the response-code bevore handling the data. 

Example:
{ 
  code: 500, 
  body: 'EXCEPTION_INSPECT_OUTPUT' 
}

Please be also aware, that even if the response-code is "200" there is no guarantee that the url has returned all data! Instead check whether the data are correct - example:

var searchedElements = callResult.data.match(...);

if (searchedElements)
{
	var firstElement = searchedElements[0]; 
}