I've started work in the sandbox on improving the JSON-RPC binding so that
it supports server components invoking functions on the client browser by
using externalService definitions.

I'm wondering what to do with this now, should it replace the old JSON-RPC
binding, should i move it from the sandbox to to the main branch to keep
developing it, is anyone else at all interested in this type of function in
Tuscany?

The binding and a chat sample are at:
http://svn.apache.org/repos/asf/incubator/tuscany/sandbox/ant/ajax

The very basic chat sample lets multiple people viewing an HTML page to chat
to each other - what anyone types is sent to everyone else viewing the page.


The sample HTML page shows how its done, and is at:
http://svn.apache.org/repos/asf/incubator/tuscany/sandbox/ant/ajax/ajaxchat/src/main/webapp/AJAXChat.html

and the associated sca.module file is:
http://svn.apache.org/repos/asf/incubator/tuscany/sandbox/ant/ajax/ajaxchat/src/main/resources/sca.module

In the client HTML all you do is include a script definition for the Tuscany
AJAX scritp:

  <script type="text/javascript" src="SCA/sca.js"></script>

and that makes available to the HTML page scripts all entryPoints and
externalServices with ajax bindings in the web app. EntryPoints enable the
the browser client to invoke SCA components on the server, externalServices
enable server SCA components to invoke methods on the browser client.

Scripts invoke entryPoints just like any JavaScript function, in the chat
sample there's one entryPoint called "ChatService",
and its used in the sendChat function with the statement:

         ChatService.chat(msg);

ExternalServices are slightly different. The HTML page scripts need to
define functions for each operation on the externalService
interface. In the chat sample there's a single externalService defined named
"ChatBroadcastService", and that has a single method
called "chat", so in the HTML script a function is defined for that:

      ChatBroadcastService.chat = function(msg) {
         var chatLog = document.getElementById('chatLog');
         chatLog.innerHTML = msg + '<br>' + chatLog.innerHTML;
      }

To receive the externalService method calls the HTML script needs to open a
connection to the sever, thats done with the SCA.open call which in the chat
sample is done in the onLoad method:

 <body onLoad="SCA.open()">

There's also a corresponding SCA.close function which can be called
explicitly, or the connection is closed when the browser closes the page.

This is slightly different to the way the existing JSON-RPC binding (which
only supports entryPoints) works. In the JSON-RPC binding the entryPoints
are bound to an SCA object, so for example with the JSON-RPC binding the
ChatService entryPoint would be invoked with the SCA. prefix:

SCA.ChatService.chat(msg);

Can easily also do this for entryPoints and externalSevrices in the the AJAX
binding, perhaps including the SCA. prefix makes things clearer, does anyone
have a preference?

Any comments?

  ...ant

Reply via email to