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.
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
Figure 2. WSIL loader initial page
Figure 3. WSIL loader displaying WSDL table
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
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);
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
There is logic responsible for verifying which elements are actually present,
and then a
for loop builds a table with the available columns.
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:
- Start Tomcat.
Point your Web browser to
localhostand the port number with the values you selected when configuring the toolkit, if necessary.
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.
- Select any entry from the "Location" column to load the corresponding WSDL document.
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.
- Download the two code files that accompany this article,
- Download the IBM Web Services Toolkit from alphaWorks.
- For more on the latest version of the WSTK, read part 1 of James Snell's WSTK tutorial on developerWorks.
- The WSDL 1.1 specification contains information on the structure of WSDL documents.
- The Web Services Inspection Language (WS-Inspection) specification is located on the developerWorks site.
- Visit the IBM Web services page.
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 firstname.lastname@example.org.