Interface ApplicationDeclaration


public interface ApplicationDeclaration

Application Declaration Files

When using the Smart GWT server, server side methods written in java can be directly invoked from client side code via the DMI.call() API.

In order to support this an application configuration file needs to be present on your server. This file lists out what server side methods are exposed for direct invocation. The application configuration file should be named appID.app.xml (where "appID" is some arbitrary id for your application) and must be present at the location specified by the project.apps setting in the server.properties file.

The application declaration should be written in xml, and should contain a rpcBindings block, which holds ServerObject definitions for each exposed method. Here's an example demonstrating the specified format:

     <Application>
         <rpcBindings>
             <ServerObject ID="MathUtil" className="com.example.package.MathUtil">
                 <visibleMethods>
                     <method name="addIntegers"/>
                 </visibleMethods>
             </ServerObject>
         </rpcBindings>
     </Application>
  
In this example we're exposing a method "addIntegers" on the server side java class com.example.package.MathUtil. A developer could then call DMI.call(...) on the client side code to invoke this method on the server, and get at the returned value in the RPCResponse passed to the RPCCallback. Note that the application config file does not explicitly list out a method signature - the appropriate method to call is detected automatically based on the parameters passed to DMI.call on the client side.

The method may be also written using Server Scripting if it is short or if it is needed to add fuctionality to the referred ServerObject without modyfing its Java code. The example above may be extended with the addAbsIntegers method imlpemented using groovy script, which from the client perspective can be called the same way as the addIntegers method above:

     <Application>
         <rpcBindings>
             <ServerObject ID="MathUtil" className="com.example.package.MathUtil">
                 <visibleMethods>
                     <method name="addIntegers"/>
                     <method name="addAbsIntegers" language="groovy" args="values">
                         <script>
                             int res = 0;
                             for (int i: values) {
                                 res += Math.abs(i);
                             }
                             return res;
                         </script>
                     </method>
                 </visibleMethods>
             </ServerObject>
         </rpcBindings>
     </Application>
  
See the DMI overview for further information on Direct Method Invocation in Smart GWT.