< Previous | Next >

 

 

Lesson 3: Expose the RPC Adapter Service

 

+

Search Tips   |   Advanced Search

 

In this lesson you will learn how to create the RPC Adapter service that returns a JSON response.

To expose the Movie service:

  1. Create the ShowMovies.jsp Web page:

    1. In the Enterprise Explorer view, expand

      web2Project.

    2. Right-click

      WebContent and select

      New | Web Page. The

      New Web Page wizard opens.

    3. In the File Name field, type ShowMovies.

    4. From the Template list, click

      Basic Templates | JSP. Click Finish. ShowMovies.jsp is created and opens in the editor.

  2. Expose the RPC Adapter Service:

    1. In the Page Data view (

      Window | Show View | Page Data), right-click

      RPC Adapter Services and select

      New | RPC Adapter Service. The

      Expose RPC Adapter Service window opens.

    2. In the Class field, click Browse. The

      Select a Java class to expose dialog opens.

    3. In the Select entries field, type MovieService. In the Matching items list, click

      MovieService - web2. Click OK.

    4. In the Methods list, click

      getMovieList(), then click Next.

    5. In the URL section, the URL that is displayed is the URL that calls your getMovieList method when it is invoked:

      Click Finish.

      The RPC Adapter Service is created in the Page Data view.

      The RPC Adapter configuration file, RpcAdapterConfig.xml, is created and the getMovieList() is exposed.

  3. By default the RPC Adapter is configured to return all service invocations as JSON. To see how the RPC Adapter works, invoke the service that you just exposed in a Web browser.

    Test the Web application:

    1. In the Enterprise Explorer view, right-click ShowMovies.jsp, and then select...

      Run As | Run on Server

      The Run On Server window opens.

    2. In the servers list, select WAS v7.0, then click Finish. ShowMovies.jsp opens in a browser. Since you have not populated the Web page, the Web browser displays a blank Web page.

    3. Once the server is started, click

      Window | Show View | Other | General | Internal Web Browser | OK

      ...to open another Web browser. Paste the following URL into the location bar:

      https://localhost:10016/web2Project/RPCAdapter/httprpc/MovieService/getMovieList

      To determine the port number for your server, right-click the server in the Servers view and select Properties.

      In the Properties list, click...

      WAS | The Properties for WebSphere® Application Server v7.0

      The HTTP port field displays the port number.

    4. A browser dialog opens asking you how to handle the getMovieList file. Save the file.

    5. Open the file in a text editor. It looks like the following:

      {"result":[{"director":"Victor Fleming","actor":"Vivien 
      Leigh","rating":10,"title":"Gone with the Wind"},
      {"director":"Robert Zemeckis","actor":"Michael J Fox",
      "rating":10,"title":"Back To The Future"},{"director":
      "George Lucas","actor":"Harrison Ford","rating":10,
      "title":"Star Wars"}]}

      The Movie list is serialized as JSON.

Tip: The RPC Adapter includes function that displays all of the services and methods that are currently exposed. With the server running, open a Web browser and type the following URL into the location bar:

http://localhost:<port>/web2Project/RPCAdapter/httprpc/

The browser displays the exposed services as a table:

When you click on a service, the individual methods of the service are displayed:

Web-remoting is a pattern that provides support for JavaScript or client-side code to directly invoke server side logic. This pattern provides the ability to invoke Java™ methods from JavaScript. The invocation is by means of a JSON-RPC call. The most common usage is asynchronous calls with XmlHttpRequest. Data is transferred between the server and client in JavaScript Object Notation (JSON) format. Therefore, this pattern is essentially a form of JSON Web services.

IBM implementation for Web remoting is referred to as the Remote Procedure Call (RPC) adapter for IBM. The RPC adapter is designed to help developers create command-based services quickly and easily in a manner that complements programming styles for AJAX applications and other lightweight clients. Implemented as a generic servlet, the RPC adapter provides an HTTP interface to registered JavaBeans.

The RPC adapter provides an HTTP interfaces to registered JavaBeans. It will deserialize the input and call the corresponding method in the JavaBean. It will serialize the output from the JavaBean to JSON/XML format.

The RPC adapter currently supports two RPC protocols:

The Remote Procedure Call (RPC) Adapter provides a mechanism for exposing server-side Java objects to AJAX-based user interfaces.

 

Lesson checkpoint

You have created the RPC Adapter service that returns a JSON response.

You learned the following:

< Previous | Next >