WebSphere Process Server is an IBM flagship business integration product that supports the runtime activities in the SOA lifecycle. WebSphere Process Server is built on top of the WebSphere Enterprise Service Bus product, and it provides many additional functions, including support for BPEL-based processes, business state computers, business rules, and human tasks. The Service Component Architecture (SCA) provides the basic programming model for WebSphere Process Server and WebSphere Enterprise Service Bus. SCA describes all integration artifacts as service components with well-defined interfaces.
Ruby is a dynamically typed, interpreted, object-oriented scripting language. It is known for its straightforward syntax and ease of use. Rails is a powerful add-on to the Ruby programming language, providing a dynamic framework for the development of database-driven Web applications. Ruby on Rails is a Web application framework that uses the model-view-controller architectural pattern for organizing applications. It is built on two solid principles:
- Convention over configuration
- Don't repeat yourself (DRY)
Convention over configuration means that a developer needs to conform to all of the naming conventions Rails uses, avoiding custom configurations. This tradeoff allows the framework to drastically speed up application development. DRY means that information is located in a single place, allowing the framework to standardize the organization of the project. These principles work together to allow the framework to speed up the development of the applications by making key assumptions about the artifacts that compose the application.
For example, if you have an object in Rails called LineItem, Rails assumes that there is a corresponding database table called line_items to store the data. Therefore, the developer does not have to repeat work by providing a mapping to the framework telling it where the persistence store is for the object. In order for this approach to work, the developer follows the proper naming scheme for the object and table names. When the proper naming conventions are followed, Rails can generate the DDL scripts for creating the tables in the database, thus putting the development cycle on fast-forward.
This article demonstrates the integration of a Web service client running in the Ruby on Rails framework with an SCA component deployed into WebSphere Process Server.
Exposing the SCA component as a Web service
This section describes how to create a simple SCA component and expose it as a Web service. You should have WebSphere Integration Developer installed (see Resources).
Open WebSphere Integration Developer, and use the context menu to create a new SCA module called
TestModule to hold the component.
Figure 1. Context menu for module creation
Complete the following steps to create a new SCA component.
- Create an interface for the component by downloading the
TestServiceData.xsd file and drag-and-dropping it onto the Data Types folder.
Figure 2. Drag and drop the TestServiceData.xsd file
- Right-click interfaces, and create a new interface called
TestServiceInterface.
Figure 3. Context menu for interface creation
- Create a two-way operation called
callTestService, selecting the appropriate message types, as shown in Figure 4.
Figure 4. Completed service interface
- Open the assembly diagram, if it is not already open, and drag a new SCA
component with no implementation type onto the canvas. Rename the component
TestService.
Figure 5. Context menu for SCA component creation
- Use the context menu for the component to associate the interface with
the component.
Figure 6. Context menu for the interface assignment
- Select the Show WSDL radio button, select TestServiceInterface, and
click Apply.
Figure 7. Selecting TestServiceInterface
WebSphere Integration Developer supports the following implementation types for SCA components:- BPEL
- State machine
- Business rule
- Human task
- Java™
Next, you can create a simple Java component and expose it with a Web service binding. However, you can use any supported WebSphere Integration Developer implementation type.
- Right-click on the SCA component, and generate a Java implementation for the
component.
Figure 8. Context menu for Java implementation generation
Notice that WebSphere Integration Developer has generated a callTestService method to match the operation that you created in the service interface.
- Add the following code to the callTestService method.
Listing 1. Sample code for callTestService methodpublic DataObject callTestService(DataObject input) { String firstName = input.getString("firstName"); String middleName = input.getString("middleName"); String lastName = input.getString("lastName"); String outputStr = "Hello " + firstName + " " + middleName + " " + lastName + ", I am WebSphere Process Server!"; ServiceManager sm = new ServiceManager(); BOFactory bof = (BOFactory)(sm.locateService("com/ibm/websphere/bo/BOFactory")); DataObject output = bof.create("http://TestModule/Data", "TestServiceOutput"); output.setString("returnMessage", outputStr); return output; }
The code takes the first, middle, and last names as input, and it creates a hello message from the process server and sends it back to Ruby on Rails. The next section describes how that is done.
Expose the component as a Web service
- Drag an export component onto the canvas, and wire it to the Java
component. Select OK when prompted.
Figure 9. Context menu for the export component
Figure 10. Wiring the export to the component
- Use the context menu of the export component to generate a SOAP/HTTP
Web service binding.
Figure 11. Generating the Web service binding
Figure 12. Selecting the SOAP protocol
- Notice the new entry under Web Service Ports.
Figure 13. Generated Web service port
Generating the Ruby on Rails Web service client
Locate the Ruby on Rails installation packages at the Ruby Web site (see Resources) Follow the instructions in this section to perform the installation.
This article uses a Ruby package called SOAP4R to generate the Ruby client code required to invoke the Web service running on WebSphere Process Server.
- Use the RubyGems packaging system to install SOAP4R by issuing the following
command:
gem install soap4r --source http://dev.ctor.org/download/.
- Edit the classDefCreator.rb file under C:\ruby\lib\ruby\1.8\wsdl\soap
to direct soap4r to support anonymous types. Search for the text do we define a
class for local complexType from it's name? in the file, and comment out the
text type = nil just above it. Uncomment the text type =
create_class_name(element.name).
Figure 14. classDefCreator.rb
Generate the Web service client code
- Create a folder to hold the Web service client code. In this article,
use C:\GeneratedRubyScripts.
- Select the Data Types, Interface, and Web Service Port in WebSphere Integration Developer, and
copy them into C:\GeneratedRubyScripts.
Figure 15. Copying files into C:\GeneratedRubyScripts
The following files should now be in C:\GeneratedRubyScripts:
- TestServiceData.xsd
- TestServiceInterface.wsdl
- Export1_TestServiceInterfaceHttp_Service.wsdl
As of version 1.5.6 of SOAP4R, the generation of Web service clients from multiple wsdl files is not supported. Therefore, combine the two wsdl files.
- Open the Export1_TestServiceInterfaceHttp_Service.wsdl
file in a text editor, and copy the binding and service elements as shown in
Figure 16.
Figure 16. Copying the binding and service elements only
- Paste this text to the bottom of the TestServiceInterface.wsdl
file.
- Copy and paste the SOAP namespace
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/from Export1_TestServiceInterfaceHttp_Service.wsdl to TestServiceInterface.wsdl. Be sure to paste it inside of the definitions element, as shown in Figure 17.
- In the binding element of the TestServiceInterface.wsdl file, change
type="Port_0:TestServiceInterface to
type="tns:TestServiceInterface.
- In the service element of the TestServiceInterface.wsdl file, change
binding="this:Export1_TestServiceInterfaceHttpBinding" to
binding="tns:Export1_TestServiceInterfaceHttpBinding".
Figure 17. Configured TestServiceInterface.wsdl
- Navigate to the GeneratedRubyScripts directory, correct the server name if
needed (see Running on a remote server sidebar), and run the following
command to generate the Web service client files: wsdl2ruby.rb --wsdl
TestServiceInterface.wsdl --type client --classdef --force.
- Ensure that the command returns
End of app. (status: 0), as shown in Figure 18.
Figure 18. wsdl2ruby.rb output
After running the script, the following files should be generated:
- TestServiceInterface.rb
- TestServiceInterfaceDriver.rb
- TestServiceInterfaceMappingRegistry.rb
- Export1_TestServiceInterfaceHttpServiceClient.rb
- Open the TestWebServiceMappingRegistry.rb file, and ensure that the
following lines of code are present at the top of the file in the correct
order. You might have to add the reference to rubygems and soap4r.
Listing 3. Code for configuring module dependenciesrequire 'TestServiceInterface.rb' require 'rubygems' gem 'soap4r' require 'soap/mapping'
- Open the Export1_TestServiceInterfaceHttpServiceClient.rb file, and
replace the last two lines with the following code to call the service. In this
test, you will send Ruby on Rails as the service input.
Listing 4. Code for setting up the call to the service# Setup call to the Web Service testServiceInput = TestServiceInput.new("Ruby", "on", "Rails") callTestServiceInput = CallTestService.new(testServiceInput) # Call Web Service callTestServiceResponse = obj.callTestService(callTestServiceInput) # Print Response puts callTestServiceResponse.output.returnMessage
Test the Web service using the Ruby standalone script
Ensure that the WebSphere Process Server is running, and run the following command from the command prompt: ruby -d Export1_TestServiceInterfaceHttpServiceClient.rb. Note: The -d option is used to display the SOAP wire dumps during service execution, if needed.
Figure 19. Output of service call without the SOAP wire dump
Using the generated client files in a Rails application
Create a new Rails application
- Run the rails webServiceDemo command to create a new Rails application and folder
structure under the GeneratedRubyScripts directory. After running the command, you
should have a webServiceDemo directory created to hold the artifacts for the Web
application.
- Modify the boot.rb file under webServiceDemo\config to ensure that
SOAP4R loads properly. Search for require 'rubygems' in the file, and add
gem 'soap4r' below it.
Figure 20. Modify boot.rb.
- Change directory to webServiceDemo, and create a new controller called
WebService using the following command: ruby script/generate controller
WebService.
Figure 21. Creating the Rails controller
- Edit the web_service_controller.rb file located in
webServiceDemo\app\controllers. Add require 'TestServiceInterfaceDriver.rb'
to the top of the web_service_controller.rb file so that the driver can be
loaded.
- Add code from Listing 5 to create the action. Notice that the code is
similar to the code that was used in the
Export1_TestServiceInterfaceHttpServiceClient.rb standalone Ruby script in Listing 4.
Listing 5. Code for creating the actionrequire 'TestServiceInterfaceDriver.rb' class WebServiceController < ApplicationController def invoke # Setup call to the Web Service testServiceInput = TestServiceInput.new("Ruby", "on", "Rails") callTestServiceInput = CallTestService.new(testServiceInput) # Call Web Service obj = TestServiceInterface.new() callTestServiceResponse = obj.callTestService(callTestServiceInput) # Assign Response Message @returnMessage = callTestServiceResponse.output.returnMessage end end
- Copy the Web service client files from the GeneratedRubyScripts
directory to the webServiceDemo\lib directory so they can be used by the
controller. The following files are needed:
- TestServiceInterface.rb
- TestServiceInterfaceDriver.rb
- TestServiceInterfaceMappingRegistry.rb
- In order to create a view for the invoke action, create a file
called invoke.rhtml in the webServiceDemo\app\views\web_service directory, and
copy the following code into the file:
Listing 6. Code for creating the action<html> <head> <title>Invoke Web Service</title> </head> <body> <h1><%= @returnMessage %></h1> </body> </html>
Notice that the @returnMessage instance variable that is used in the code above was set in the action code from Listing 5.
- Start the WEBrick Web server (see the sidebar About
WEBrick) by running the following command: ruby script/server webrick.
- Access the page using the following URL:
http://localhost:3000/web_service/invoke.
Figure 22. View of Web page
This article used a simple SCA service to demonstrate how to integrate a Ruby on Rails Web application with a WebSphere Process Server module. The article offered the steps on how to expose an SCA module as a Web service in WebSphere Integration Developer and how to use SOAP4R to generate Ruby scripts that can be migrated into a Ruby on Rails Web application. The scope of the article was limited to the integration of WebSphere Process Server and Ruby on Rails; therefore, there are many features of Ruby on Rails and WebSphere Process Server that were not highlighted (see Resources for further exploration of these topics).
| Description | Name | Size | Download method |
|---|---|---|---|
| Sample test file | TestServiceData.xsd | 695 KB | HTTP |
Information about download methods
Learn
- Visit the
WebSphere Process Server
Web site.
- Check out the Ruby on Rails Web site.
- Review the
SOAP4R release notes.
- Visit the
SOAP4R wiki.
- Visit the
WebSphere Process Server
Web site.
- The
SOA and Web services zone
on IBM developerWorks hosts hundreds of informative articles and
introductory, intermediate, and advanced tutorials on how to develop Web services
applications.
- The
IBM SOA Web site offers
an overview of SOA and how IBM can help you get there.
- Stay current with developerWorks technical events and webcasts.
Check out the following SOA and Web services
tech briefings in particular:
- Get started on SOA with WebSphere's proven, flexible entry points
- Building SOA solutions and managing the service lifecycle
- SCA/SDO: To drive the next generation of SOA
- SOA reuse and connectivity
- Browse for books on these and other technical
topics at the
Safari bookstore.
Get products and technologies
- Innovate your next
development project with
IBM trial software,
available for download or on DVD.
Discuss
- Participate in the discussion forum.
- Participate in the
SOAP4R Google Discussion Group.
- Get involved in the developerWorks community
by participating in developerWorks blogs.




