You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by co...@apache.org on 2007/07/23 15:33:00 UTC

[CONF] Apache Tuscany: SCA Java binding.ajax (page edited)

SCA Java binding.ajax (TUSCANY) edited by ant
      Page: http://cwiki.apache.org/confluence/display/TUSCANY/SCA+Java+binding.ajax
   Changes: http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=56001&originalVersion=15&revisedVersion=16






Content:
---------------------------------------------------------------------

{section:border=false}
{column:width=15%}
{include: SCA Java Subproject Menu}
{include: Java SCA Menu New}
{column}
{column:width=85%}

h3. <binding.ajax>

Tuscany supports web browser clients using [AJAX|http://en.wikipedia.org/wiki/Ajax_(programming)] to communicate with with SCA components by using the <binding.ajax> SCDL extension. This enables remote web browser clients to easily make RPC style calls to server-side SCA components and for server-side SCA components to easily make [COMET|http://en.wikipedia.org/wiki/Comet_(programming)] / [Reverse Ajax|http://en.wikipedia.org/wiki/Reverse_Ajax] style requests to web browser clients.

This binding has no attributes or elements so to include it on a SCA service or reference simply requires the following SCDL:

{code}
   <binding.ajax/>
{code}

Also see [<binding.jsonrpc|SCA Java binding.jsonrpc] which provides some similar function.

In order for a web browser client to interact with SCA services and references which use <binding.ajax> it needs to included a Tuscany runtime scaDomain.js script which will initialize the SCA enviroment and provides control functions. This script is dynamically generated to include  

A web browser client needs to include a Tuscany runtime system script in its HTML page before it can interact with SCA services and references which use <binding.ajax>. This is done by simply including the following script tag within the HTML page:

{code}
    <script type="text/javascript" src="SCA/SCADomain/scaDomain.js" />
{code}

This creates proxy objects for the SCA services which can then be used make requests to the server-side components. For example, if there was a service named "myService" using <binding.ajax> which had operations "aOnewayRequest" and "anRpcRequest" the scripts in the HTML page could now invoke these opperations with the following:

{code}
myService.aOnewayRequest(args);
{code}
or
{code}
myService.anRpcRequest(args, responseFunction);
{code}

In the that example 'responseFunction' is the name of a function which is called to process the response and which gets called asynchronously on another thread when the response is avaialble. RPC requests are done this way instead of the simpler "answer = myService.anRpcRequest(args)" to avoid hanging the browser while the (potentialy slow) request is being processed. An example of the responseFunction for the previous example is:
{code}
function responseFunction(answer){
  // do something with answer
}
{code}

For SCA references using <binding.ajax> a function needs to be written to handle each operation that may be called by the reference. The operations used by the reference cannot return any response but must be one-way style operations. As an example, if there is an SCA reference named "myReference" which has an operation named "foo" then the client side function required would be:
{code}
myReference.foo = function(args) {
  // do something with args
}
{code}

SCA references using <binding.ajax> require a communication channel between the server-side Tuscany runtime and the remote web browser client. This channel can be explicitly opened and closed by the client, and it must be opened before any client side function assoicated with a SCA reference will be invoked. This is done with:
{code}
scaDomain.open();
{code}
and
{code}
scaDomain.close();
{code}
The connection is automatically closed when the web page is closed so if the client does not need fine grain control the 'onLoad' of the HTML body element can be used to establish the connection, for example:
{code}
<body onLoad="scaDomain.open()">
{code}

h4. Some examples:

See the [chat-webapp|https://svn.apache.org/repos/asf/incubator/tuscany/java/sca/samples/chat-webapp/] sample in the Tuscany SCA samples folder for an example of using <binding.ajax>

{info:title=Differences between <binding.jsonrpc> and <binding.ajax>}
The current Tuscany SCA runtime supports <binding.jsonrpc> and <binding.ajax> which provide similar functionality. The differences are:
* <binding.jsonrpc> supports the SMD protocol enabling easy use with Dojo, <binding.ajax> does not support SMD
* <binding.ajax> supports SCA references and using [COMET|http://en.wikipedia.org/wiki/Comet_(programming)] style asynchronous operation, <binding.jsonrpc> does not
* <binding.jsonrpc> uses the standard [JSON-RPC|http://json-rpc.org/] protocol, <binding.ajax> uses a proprietry protocol using [DWR|http://getahead.org/dwr/] 

These differences should be resolved by the Tuscany SCA 1.0 release.
{info}

{column}
{section} 

---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence

Unsubscribe or edit your notifications preferences
   http://cwiki.apache.org/confluence/users/viewnotifications.action

If you think it was sent incorrectly contact one of the administrators
   http://cwiki.apache.org/confluence/administrators.action

If you want more information on Confluence, or have a bug to report see
   http://www.atlassian.com/software/confluence



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org