EMI-RPC with JSONP Access

September 8th, 2009 Leave a comment Go to comments

One of the key functionalities of the EMI Server is to provide the management interface to the device while the front-end of the management application is located elsewhere. It could be a web server or computer that is connected to the device by some means supporting TCP/IP connectivity.

Since EMI Server API is based on JSON (JavaScript Object Notation) format one of the most natural choices for the front-end implementation would be a web-interface to be run from the web browser. However, many currently deployed browsers are restricted by the “same origin” rule that generally prohibits separating front-end and back-end of the web application into two different domains. Hence it will be impossible to use standard HTML and DHTML functionality to exchange information between the front-end and EMI Server. This section describes the JSONP approach that allows bypass of the current limitations.

Essentially the only part of the HTML document that is allowed to be fetched from the external source is the Javascript script itself. Hence it is possible to send a GET request to the external service by dynamically inserting the script into the document. In the following example the url parameter may contain the standard URI for GET request, where parameters are appended in the form of http://host:port/path/file?param1=x&time=y.

function insertScript( url ){
   var script = document.createElement("script");
   script.setAttribute("src",url);
   script.setAttribute("type","text/javascript");
   document.body.appendChild(script);
}

EMI Server accepts two parameters (and ignores anything else):

  • callback – name of the function to wrapper
  • request – EMI-RPC request as JSON object (same as in POST request)

So, assuming that the callback parameter was set to be “call_me” in order to receive the reply from the EMI Server in the front-end script it should implement the following function:

function call_me( vReturnValue ){
   ...
}

When the EMI Server returns the result, this method will be automatically executed with vReturnValue containing the returned JSON object.

While designing the front-end using JSONP access to the EMI Server, it is important to keep in mind that different entities in the network may impose limitations on the GET request itself. For example some versions of the Internet Explorer do limit the length of the GET request to around 4k. It is expected that a newer browsers with HTML5 support will provide a proper handling for secure cross-domain communication eliminating the need of using JSONP access. Refer to the “HTTP GET Considerations” for more information.

  1. No comments yet.
  1. No trackbacks yet.