WebSphere 5.02 Web Services

Part 1:  Consuming an existing Web Services using Eclipse and WAS 5.02 Engine


Introduction

WAS 5.02 fixpack includes a brand new Web Services engine that supports JSR101 (JAX-RPC) programming model and JSR109 (J2EE Web Services) deployment model.  The development process is quite different from that of using the original Apache SOAP based engine that is shipped with WAS 5.0.  This is Part 1 of a series of articles that walks you through the new programming model, discusses some key FAQs and do's and don'ts.  They focus on WAS 5.02 specifics from a developer's perspective.   In the end, I hope that you'd find accessing and developing Web Services on WAS502 isn't exactly rocket-science and the process requires little knowledge on XML and SOAP itself.

Pre-requisites

Overiew of Steps

  1. Create standalone Java Project in Eclipse
  2. Use WSDL2Java to generate Java artifacts from WSDL file (from Amazon)
  3. Setup JRE and build path
  4. Create and code MyAmazonClient.java
  5. Test with live external server http://soap.amazon.com

Step 1 - Create standalone Java Project

Step 2 - Use WSDL2Java to generate Java artifacts from WSDL file (from Amazon)

Step 3 - Setup JRE and Java Build Path in Eclipse

jdk
Java Build Path

Click OK

Right-click on the Java Project again and select Refresh.  Eclipse will recognize the new Java classes generated by WSDL2Java and compile them.  If you have no compile errors, you are half-way there now.  2 more steps to go.

Step 4 - Develop your main class (MyAmazonClient)

package com.ibm.test;

import com.amazon.soap.*;

public class MyAmazonClient {

    public static void main(String[] args) {
       
        try {
           
            AmazonSearchServiceLocator locator = new AmazonSearchServiceLocator();      //  ServiceLocator
            AmazonSearchPort service = locator.getAmazonSearchPort();                   //  Port class
            KeywordRequest aKeywordRequest = new KeywordRequest();                      //  construct request
            aKeywordRequest.setMode("books");
            aKeywordRequest.setType("lite");
            aKeywordRequest.setKeyword("Finding Nemo");
            ProductInfo aProductInfo = service.keywordSearchRequest(aKeywordRequest);   // invoke the service
           
            System.out.println("Total number of matches = " + aProductInfo.getTotalResults() + "\n");


            Details details[] = aProductInfo.getDetails();
           
            for (int i = 0; i < details.length; i++) {
                Details aDetail = details[i];
                System.out.println(i + ": " + aDetail.getProductName() + " " + aDetail.getOurPrice());   
            }
          
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Step 5:  Execute your code!

output


Additional discussion points:

tcpmon
The output should look like this:

tcpmon




I hope that you'd find this tutorial useful.  Invoking a Web Service using WAS502 is fairly simple and requires very little knowledge on XML and SOAP itself.   You can use WSAD 4.x or WSAD 5.0 instead of Eclipse.  If you are using WSAD 5.1, there are some wizards which make thing even easier (without invoking WSDL2Java outside of the IDE).



Courtesy of www.websphere-world.com
Billy Lo