Build HTTPS Web services with Rational Application Developer, Part 1: Web services and Web services clients

Build secure Web services using transport-level security (HTTPS) with IBM® Rational® Application Developer Version 6.0.1.1 and later. In Part 1 of this series, you will build Web services for a calculator application. You will generate and test two different types of Web services clients: a J2EE client and a J2SE client.

Share:

Henry Cui (henrycui@ca.ibm.com), Software Engineer, IBM Toronto Lab

Henry Cui photoHenry Cui works with the Rational Application Developer Technical Support team at the IBM Toronto Lab. He is the subject matter expert of the support team in Rational Application Developer Web services tooling.



15 August 2006

Also available in Chinese

Before you start

About this series

This series shows you how to develop and configure HTTPS Web services with IBM Rational Application Developer (hereafter called Application Developer).

HTTP, the most commonly used protocol for information exchange on the Internet, is an inherently insecure protocol, because all information is sent in clean text between unauthenticated peers over an insecure network.

HTTPS, which stands for HTTP via SSL (Secure Sockets Layer), allows client-side and server-side authentication through certificates. SSL is a protocol that transmits your communications over the Internet in an encrypted form. SSL ensures that the information is sent, unchanged, only to the server you intended to send it to. HTTPS Web services can be applied to all client types, including Java™ 2 Enterprise Edition (J2EE) client and Java 2 Platform, Standard Edition (J2SE) client.

HTTPS is the transport level security. It can be applied in combination with message level security (WS-Security). As a mature technology, SSL is widely used in today's production system.

About this tutorial

In Part 1 of this tutorial, you will:

  • Develop a Web services J2EE client
  • Develop a Web services J2SE client

This will lay the groundwork for Part 2 of this series, when you will learn how to configure HTTPS Web services. In Part 2, you will:

  • Create the Key Stores, trust stores and certificates using iKeyman for Web services and Web services client. Import the server certificate into client trust store. Import the client certificate into server trust store.
  • Create an SSL configuration for Web services provider
  • Create an SSL configuration for Web services client
  • Modify the Web container to use the new SSL configuration for Web services provider
  • Configure the Web service client deployment descriptor
  • Test HTTPS Web services from J2EE client
  • Test HTTPS Web services from J2SE client

Objectives

Learn how to use Rational Application Developer to develop Web services, and how to develop J2EE Web services client and J2SE Web services client.

System requirements

You need Application Developer v6.0.1.1 with the latest fixes. If you are not sure if your Application Developer is at the latest level, please go to IBM Rational Product Updater (hereafter called Product Updater) to find if there are new updates. You can start Product Updater from Windows Start Menu > All Programs > IBM Rational > Rational Product Updater. After the Product Updater is started, you can click "Find Updates" button to check if there are new updates available.

You also need to update the integrated IBM WebSphere® Application Server v6.0 test environment. By default, the integrated WebSphere Application Server v6.0 test environment shipped with Application Developer is at 6.0.0 level. You need to upgrade WebSphere test environment to 6.0.2.5 or above. If you've never upgraded your WebSphere test environment, you can use Product Updater to upgrade. The updates can be found in "Optioal Features" section of Product Updater.


Section 1: Develop Web services and Web services J2EE client

  1. Start Application Developer
  2. Enable Web services development capabilities in Application Developer. Click Window > Preferences > Workbench > Capabilities, check all the capabilities under Web Service Developer, click OK.
    Figure 1. The Preferences page
    The Preference page
  3. Select File > New> Dynamic Web Project, enter CalculatorWeb. Click Finish.
    Figure 2. New Dynamic Web Project wizard
    New Dynamic Web Project wizard
  4. If you are prompted for the window below, click No. We will stay in J2EE perspective.
    Figure 3. Confirm Perspective Switch dialog window
    Confirm Perspective Switch dialog window
  5. In the Servers view, right-click WebSphere Application Server v6.0 and select Start.
  6. Right click CalculatorWeb project, New > Class, enter com.ibm for the Package name and Calculator for the Java class Name, click Finish.
    Figure 4. Create a New Java Class
    New Java Class
  7. Paste the code below to the java editor and Save
    Listing 1. Calculator.java
    package com.ibm;
    
    public class Calculator {
    	public Calculator() {
    	}
    
    	public double add(double i, double j) {
    
    		return i + j;
    	}
    
    	public double subtract(double i, double j) {
    		return i - j;
    	}
    
    }
  8. Right-click java class Calculator, New > Other ... > Web Service, click Next.
    Figure 5. New Web Service wizard
    New Web Service wizard
  9. In the Web Services page, check Generate a proxy, check Test the Web Service and also check Overwrite files without warning, click Next.
    Figure 6. Web Services page
    Web Services page
  10. In the Object Selection Page, click Next.
    Figure 7. Object Selection page
    Object Selection page
  11. In the Service Deployment Configuration page, you will see the default client type is Web. Accept the default settings click Next.
    Figure 8. Service Deployment Configuration page
    Service Deployment Configuration page
  12. Continue to click the Next button until you reach Finish. You may click the Finish button now. However, the Web services code generation is pretty intense. If you click the Finish button now, you may wait for some time to see new activity. I prefer to click the Next button to see the progress of the code generation.
  13. After a while, the sample JSP test client comes up. Click add and subtract method to do testing to make sure the Web services are working.
    Figure 9. Sample JSP test client page
    Sample JSP test client page

Section 2:Develop Web Services J2SE client

Starting with WebSphere Application Server 6.0.2 (hereafter called Application Server), Application Server provided an exciting feature called Web Services Thin Client (WSTC). You can invoke Web services from a client library without the J2EE container overhead using WSTC. It is packaged in ibm-jaxrpc-client.jar. If you upgraded your WebSphere Test Environment inside Application Developer 6 to 6.0.2 and above, this jar is located in your %Application Developer install root%\runtimes\base_v6\runtimes directory. Click OK.

  1. Start Application Developer
  2. In the Project Explorer, expand CalculatorWeb project , right click Calculator.wsdl under WebContent/wsdl/com/ibm folder, select Web Services > Generate client
  3. In Web Services page, click Next.
  4. In Web Services Selection page, click Next.
  5. In client Environment Configuration page, choose Java for Client type and enter CalculatorJavaClient as Client project name. The Web services client will be generated in a Java project.
    Figure 10. Web Service Client Environment Configuration page
    Client Environment Configuration Page
  6. click Next, click Finish.
    In the Project explorer, expand Other Projects, you will see CalculatorJavaClient project is generated, which contains the Web services client artifacts.
  7. Right click CalculatorJavaClient project, select Properties, select Java Build Path, click libraries tab, remove "WebSphere v6.0 runtime" entry, then click Add External JARs.. button, add ibm-jaxrpc-client.jar,which is located in %Application Developer install root%\runtimes\base_v6\runtimes directory. Click OK.
    Figure 11. Java Build Path page
    Java Build Path Page
  8. In the CalculatorJava project, create a Java class TestCalc.java that utilizes the generated proxy, copy/paste the code below to the editor.
    Listing 2. TestCalc.java
    package com.ibm;
    
    public class TestCalc {
    	public static void main(String[] args) throws Exception {
    		try {
    			CalculatorProxy proxy = new CalculatorProxy();
    			System.out.println("2 + 2 = " + proxy.add(2, 2));
    			System.out.println("2 - 2 = " + proxy.subtract(2, 2));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
  9. Right click TestCalc.java, Run > Java Application. You will see the correct result is displayed in the console:

    2 + 2 = 4.0
    2 - 2 = 0.0

Conclusion

Good Job! You have finished the creation of Web services and Web services client in Application Developer. In Part 2 you'll learn how to configure HTTPS Web services.


Download

DescriptionNameSize
Web services sample codesamplecode.zip44KB

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into SOA and web services on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and web services, Rational
ArticleID=154201
ArticleTitle=Build HTTPS Web services with Rational Application Developer, Part 1: Web services and Web services clients
publish-date=08152006