Skip to main content

skip to main content

developerWorks  >  SOA and Web services  >

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

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

developerWorks
Document options

Document options requiring JavaScript are not displayed


Rate this page

Help us improve this content


Level: Introductory

Alfredo Silva (afdasilv@us.ibm.com), Advisory Software Engineer, IBM Software Group

06 Sep 2002

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.

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


Back to top


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.



Back to top


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.


Back to top


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.




Rate this page


Please take a moment to complete this form to help us better serve you.



YesNoDon't know
 


 


12345
Not
useful
Extremely
useful
 


Back to top