6. Publishing a AJAX service using DWR

PROBLEM

Rich Internet Applications (RIA) are applications that resemble desktop applications, and there are a variety of technologies for implementing RIAs. Independent of the framework or toolkit used for implementing the front-end of an RIA, all RIA applications need to access logic and/or databases that reside on the server. There needs to be mechanism to easily publish a Spring DSL service in a format that can be consumed by RIAs.

SOLUTION

Skyway Builder Web Services Edition has some accelerators for exposing the Spring DSL Services and Operations as DWR services. DWR is "a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible". The DWR functionality in Skyway Builder makes it very easy to make the functionality of Spring Services accessible to RIAs.

HOW IT WORKS

The Spring DSL services aren't automatically exposed as DWR services. The decision of exposing application logic as DWR services is left to the developer to decide based on their requirements.

Steps for publishing a DWR service:

  1. Open the Service editor for the Spring DSL Service that needs to DWR enabled and switch to the DWR tab.

  2. Click on the Synchronize button to refresh the DWR service meta-data from the Spring DSL service meta-data.

  3. Under DWR Service Details, check the Publish option.

  4. Deploy your application, and the service will be available as a DWR service.

The web service is preconfigured using common conventions for the service and operations, but the DWR tab provides some configuration options. By default all the Operations in the Service are published with DWR. If you want to exclude certain operations, you can highlight the operation in the DWR tab and check the "Exlude" option.

DWR will automatically generates some pages that can assist in developing with DWR. The DWR Service index page lists all the classes known to DWR. It's usefull for verifying which Spring DSL services are or are not DWR enabled. The URL for the accessing the index page is http://server:port//context/dwr/index.html

Figure 3.1. DWR Service - Index Page

DWR Service - Index Page

Each service listed on the index page includes a hyperlink to access the DWR Service details page. The details page lists the script includes needed to use the DWR-enabled service from javascript. The name of the javascript file is specified by the DWR configuration in the DWR tab. The details page also include a listing of all available javascript methods. There should be a javascript method for every operation in the DWR-enabled service that wasn't configured to be excluded. Beside each javascript function there is an "Execute" button that can be used for testing client/server communication prior to building the front-end that used javascript functions..

Figure 3.2. DWR Service - Service Details Page

DWR Service - Service Details Page

RELATED RECIPES

  1. Creating a Contract-First SOAP Web service

  2. Consuming a SOAP Web service

  3. Consuming a REST Web Service