Use Jruby on Rails and XML to Supercharge Ajax with a Java Application Server Learn How XML Can Improve the Efficiency of Your Jruby on Rails and Ajax Development

Use Jruby on Rails and XML to Supercharge Ajax with a Java Application Server Learn How XML Can Improve the Efficiency of Your Jruby on Rails and Ajax Development

Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server Learn how XML can improve the efficiency of your JRuby on Rails and Ajax development Skill Level: Intermediate Tyler Anderson ([email protected]) Freelance writer Backstop Media 27 May 2008 The Ruby on Rails framework has handy XML features that will make developing with and serving database data in XML format to your JavaScript applications easier than ever. JavaScript also has built-in XML parsing capabilities that make it a snap to receive and parse data in XML format. But what if you now want to hook into Java™ applications without having to deploy another server? That's where JRuby comes in. JRuby on Rails is the Java implementation of the Ruby on Rails framework, bringing the benefits of Rails to Java programming by allowing deployment of Ruby apps to Java application servers. In this tutorial, you'll develop a JRuby on Rails application deployable to a Java application server that will serve database data in XML format to an Ajax client that you'll build for film lovers to manage their online films database. You'll also deploy a couple of Java Server Pages pages on the same Java application server to assist the Ajax client in adding and updating films. Section 1. Before you start This tutorial is recommended for XML developers interested in using JRuby on Rails, Java technology, and a database. It's also for those XML developers who wish to reduce their development time as they leverage the JRuby on Rails framework to use scaffolding without having to sacrifice the option of also using Java code. Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 57 developerWorks® ibm.com/developerWorks About this tutorial This tutorial shows how to develop Ajax applications more efficiently with the help of JRuby on Rails and Java Server Pages (JSP) technologies hosted on a Java application server, IBM® WebSphere® Application Server Express. You'll use the framework set up by JRuby on Rails to give simple access, through XML, to your database of films, and you'll use JSP technology to add new films to and edit existing films in the database. In all, you'll learn to do the following: • Install WebSphere Application Server Express • Install and set up your first JRuby project • Install the Goldspike plugin to your JRuby project for deployment to WebSphere Application Server Express • Set up your JRuby project to use Derby as the database • Get a working JRuby on Rails 2.0.2 project to properly send XML requests to the Ajax client • Develop JSP files to handle adding and editing film entries by utilizing XML requests made by the Ajax client • Develop an all-Ajax client to manage your films • Deploy and test on WebSphere Application Server Express To accomplish the above, you'll develop an example application for the online film industry where lovers of film will be able to manage, tag, and be redirected to their library of online videos. The Ajax application will receive communications in XML format from JRuby on Rails and send XML communications to JSP applications running a single Java application server instance. Prerequisites For this tutorial you'll need the following downloads: • WebSphere Application Server Express —Get a trial version of WebSphere Application Server Express from IBM (this tutorial uses V6.1). You'll use WebSphere Application Server as a full featured Java application server to host your JRuby on Rails Web application. However, please note that you can use any application server, such as Apache Tomcat or Apache Geronimo. • JRuby —JRuby is a Java-based interpreter for Ruby, allowing deployment Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server Page 2 of 57 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® to Java application servers through the Goldspike plugin with full integration with Java libraries. This tutorial uses JRuby version 1.1.1, and Rails version 2.0.2. Rails will be downloaded and installed by RubyGem, which is part of the JRuby package. • Database—The example application requires a database to store and retrieve film entries. This tutorial uses the version of Derby that comes with WebSphere Application Server Express, though you can use any version. Derby is nice because it's free and lightweight. Knowledge of JSP and Rails technology is useful for this tutorial, but not required. Section 2. Introduction This section gives an overview of how to leverage the XML features of JRuby on Rails, JSP and Ajax technology, and how WebSphere Application Server Express brings them all together. XML, Rails, Java and Ajax technologies Frequently used acronyms • Ajax: Asynchronous JavaScript and XML • DOM: Document Object Model • XML: Extensible Markup Language With built-in XML features of JRuby on Rails, you can access to database data in XML format with little effort, and with JRuby's greater Java compatibility you bring a host of other Java features into your arsenal. Thus in a single Ajax application, as you'll build in this tutorial, your Ajax application will reference both JRuby on Rails and JSP code to combine the strengths of both programming languages in a single Web application. These strengths include the easily used Ruby on Rails framework, and the power of Java programming in a JSP page. Next you'll see how WebSphere Application Server Express fits in. How WebSphere Application Server Express brings them all together Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 57 developerWorks® ibm.com/developerWorks WebSphere Application Server Express is a Java Servlet container, and thanks to JRuby and the Goldspike plugin, you can now deploy JRuby on Rails applications to Java application servers as packaged WAR files. It doesn't stop there, either. You can deploy JSP files within the Ruby application, to have them work alongside your Ruby files. In Figure 1 is a sneak peek into the application that you'll develop. Figure 1. Showcase of the example application You'll code the film management application in Ajax complete with the ability to add new films, and view, edit, and delete each individually. Before the fun begins, however, first you'll do a quick installation and setup of WebSphere Application Server Express and JRuby. Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server Page 4 of 57 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® Section 3. Quick WebSphere Application Server Express installation guide Installing WebSphere Application Server Express is pretty simple. Simply follow along and you shouldn't run into any problems. Installing WebSphere Application Server Express To begin the installation, unzip the file you downloaded, navigate to the WebSphere Application Server directory, and open the install.exe file. This should bring you to the welcome page (Figure 2). Figure 2. Welcome page Click Next to view the license agreement (Figure 3). Figure 3. Accept the license agreement Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 5 of 57 developerWorks® ibm.com/developerWorks Select the I accept both the IBM and the non-IBM terms radio button to accept the license agreement. Click Next to open the Install Sample applications page (Figure 4). Figure 4. Installing sample apps Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server Page 6 of 57 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® Check the Install the sample applications box and click Next. This brings you to the installation location page (Figure 5). Figure 5. Choose installation location Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 7 of 57 developerWorks® ibm.com/developerWorks Choose your destination, and click Next to open the page where you'll set up administrative security (Figure 6). Figure 6. Enabling admin and samples security Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server Page 8 of 57 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® Choose any username and password you wish. For this tutorial, username and password, respectively, were chosen. Click Next to open the installation summary page (Figure 7). Figure 7. Installation summary Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 9 of 57 developerWorks® ibm.com/developerWorks If everything looks correct, click Next. After installation completes, you see the installation results page (Figure 8). Figure 8. Installation success Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server Page 10 of 57 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® Click Finish to complete the installation. You can play with the First steps console if you wish, but you don't have to worry about it for now. To start the server, simply click Start > Programs > IBM WebSphere > Application Server - Express V6.1 > Profiles > AppSrv01 > Start the server. And installing WebSphere Application Server Express is as simple as that! Next you'll install JRuby. Section 4. Quick JRuby installation and first project setup guide Use JRuby on Rails and XML to supercharge Ajax with a Java Application Server © Copyright IBM Corporation 1994, 2008.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    57 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us