Skip to main content

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

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

All information submitted is secure.

  • Close [x]

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.

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

All information submitted is secure.

  • Close [x]

Web services programming tips and tricks: Ease service discovery with WSIL4J

Processing Web Services Inspection Language documents is a snap with this Java API

Alfredo Silva (afdasilv@us.ibm.com), Advisory Software Engineer, IBM Software Group
author
Alfredo da Silva is a software developer at IBM. He is a member of the group responsible for the IBM Web Services Toolkit (WSTK). You can contact Alfredo at afdasilv@us.ibm.com.

Summary:  Before you can make use of Web services on the network, you have to discover them and get information about them. Web Services Inspection Language (WSIL) eases this process somewhat. In this article, Alfredo da Silva presents a Java API that makes it even simpler. You'll take a look at code that processes WSIL documents and presents the information they contain in an easy-to-read tabular format. Once you've mastered this API, you'll be able to unleash its power in your own applications.

Date:  06 Sep 2002
Level:  Introductory
Also available in:   Japanese

Activity:  6029 views
Comments:  

IBM's contribution of the WSIL4J API to the Apache Software Foundation simplifies the process of writing applications that need to perform service discovery. This article will introduce a sample application, the WSIL Loader, that unleashes the power of the WSIL4J API.

By examining the WSIL Loader, you'll see how to write JSP/servlet code that takes as input a WSIL inspection document URL and displays a WSDL table based upon the contents of that WSIL document. The generated table has three columns, listing the names, abstracts, and locations of various discovered services. Each column is only displayed if the corresponding element in the loaded WSIL inspection document is present. The location column contains hyperlinks to the WSDL documents that were enclosed by the passed WSIL inspection document reference.

Note: You can download this article's sample code, and find other useful links as well, in the Resources section below.

Information flow in WSIL4J

Figure 1 depicts the information flow between the client (Web browser) and the wsdlTableGenerator JavaServer Page (JSP), and also between this JSP and InspectionHandlerServlet. When the JSP is requested, the client displays the page illustrated in Figure 2. The user then enters a valid WSIL inspection document URL. The control is forwarded to the InspectionHandlerServlet, which provides the needed information and forwards control back to the JSP. The information is then processed by the JSP, which generates the page shown in Figure 3.

It is worth noting that errorPage.jsp is called to handle any error, in order to create a centralized and cleaner error-handling mechanism. A error page is then sent to the client.


Figure 1. WSIL Loader application information flow
WSIL Loader application information flow

Figure 2. WSIL loader initial page
WSIL loader initial page

Figure 3. WSIL loader displaying WSDL table
WSIL loader displaying WSDL table

WSIL implementation

Download the InspectionHandlerServlet code. The doPost() method is where all the action happens. I'll go over its code in some detail to make it easier to understand.

First, you create a WSILProxy object using the WSIL document URL obtained from the received HTTP request. This object parses the passed WSIL inspection document and allows for the retrieval of an WSIL document object, as shown in Listing 1.


Listing 1. WSIL document object creation

      // Create WSIL proxy
      WSILProxy wsilProxy = new WSILProxy(req.getParameter(INSPECTION_URL));

      // Create a new WSIL document
      wsilDoc = wsilProxy.getWSILDocument();

Next, you need to query the WSIL document object for information regarding service names, service abstracts, and WSDL document location elements. The returned information is then stored in an instance of an HttpServletRequest class for further retrieval. These method calls are illustrated in Listing 2.


Listing 2. WSIL inspection data retrieval

      // Set service names
      req.setAttribute(SERVICE_NAMES, getAllWSDLServiceNames(wsilDoc));

      // Set abstracts
      req.setAttribute(ABSTRACTS, getAllAbstracts(wsilDoc));

      // Set locations
      req.setAttribute(LOCATIONS, getAllWSDLLocations(wsilDoc));

Control is then forwarded back to the wsdlTableGenerator.jsp code, as shown in Listing 3.


Listing 3. JSP code control transfer

      // Transfer control
      RequestDispatcher rd = req.getRequestDispatcher(JSP_VIEWER);

      rd.forward(req, res);

Listing 4 shows how errors are handled: by transferring control to the errorPage.jsp code.


Listing 4. Error handling

      req.setAttribute("javax.servlet.jsp.jspException", t);

      // Transfer control to Error page
      RequestDispatcher rd = 
        getServletContext().getRequestDispatcher(ERROR_PAGE);
      
      rd.forward(req, res);

Download wsdlTableGenerator.jsp. This code is responsible for extracting the elements that you're interested in: service names, service abstracts, and WSDL locations from the HTTP request sent by the InspectionHandlerServlet code. There is logic responsible for verifying which elements are actually present, and then a for loop builds a table with the available columns.


Running the WSIL Loader application

The WSIL Loader application is available as part of the IBM Web Services Toolkit (WSTK; see Resources for more information). Once WSTK is installed and configured, follow these steps to get the WSIL Loader up and running:

  1. Start Tomcat.
  2. Point your Web browser to http://localhost:8080/wstk/wsilLoader/wsdlTableGenerator.jsp, replacing localhost and the port number with the values you selected when configuring the toolkit, if necessary.
  3. Enter an inspection document URL (e.g., http://www.xmethods.net/inspection.wsil), or use the default, which generates a table with the WSDL documents available in the toolkit.
  4. Select any entry from the "Location" column to load the corresponding WSDL document.

Use WSIL4J to build better Web services

The sample application discussed here shows how simple it is to handle WSIL documents using the WSIL4J API. This in turn makes the service discovery process a lot easier to implement.

Please feel free to use this code in your own work. You may find it useful when dealing with unknown WSIL, as the code organizes the information contained in these documents in a tabular format. The most relevant inspection data -- the service name, the service abstract, and the associated WSDL document URL location -- is fully exposed; the URL location is even shown as a hyperlink to the related WSDL document. This extends the examination capability provided by a given WSIL inspection document.

Remember to let IBM's Web services team know what other types of articles or tools you would find useful. You'll find links to the WSTK page (and links to feedback forms for the project team) listed in the Resources section.


Resources

About the author

author

Alfredo da Silva is a software developer at IBM. He is a member of the group responsible for the IBM Web Services Toolkit (WSTK). You can contact Alfredo at afdasilv@us.ibm.com.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


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. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

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.

(Must be between 3 – 31 characters.)

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

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and Web services
ArticleID=11704
ArticleTitle=Web services programming tips and tricks: Ease service discovery with WSIL4J
publish-date=09062002
author1-email=afdasilv@us.ibm.com
author1-email-cc=