Download (direct link):
416 Item 47
095 Classification wsdlSpecClass =
097 "wsdlSpec", "wsdlSpec");
099 Collection classifications = new ArrayList();
102 // Find concepts
103 BulkResponse response =
104 m_querymgr.findConcepts(null, namePatterns,
105 classifications, null, null);
107 System.out.println("Made an wsdlSpec concept query for \n’" +
108 "services matching '" +query + "'");
110 // Display information about the concepts found
111 int itnum = 0;
112 Iterator iter = response.getCollection().iterator();
113 if ( !iter.hasNext())
115 System.out.println(" No matching items!");
117 while ( iter.hasNext() )
120 Concept concept = (Concept) iter.next();
121 System.out.println(itnum + ") Name: " +
123 System.out.println(" Description: " +
126 Iterator linkit = concept.getExternalLinks().iterator();
127 if ( linkit.hasNext() )
129 ExternalLink link =
130 (ExternalLink) linkit.next();
131 System.out.println(" WSDL: '" +
132 link.getExternalURI() + "'");
Listing 47.8 (continued)
The result of our program is shown in Listing 47.9. On our concept query for services with the string 'sched' in them with WSDL documents, we had four results.
Performance Pitfalls in JAX-RPC Application Clients 417
01 Made an wsdlSpec concept query for
02 'services matching 'truman'
03 No matching items!
04 -----------SECOND QUERY--------------
05 Made an wsdlSpec concept query for
06 'services matching 'sched'
07 1) Name: Continental-com:Schedule-v1
08 Description: Flight schedule
09 WSDL: 2
10 2) Name: Interactive Scheduler
11 Description: A Web Service that provides a method to schedule meetings into someone else's calendar. 2
12 WSDL: 2
13 3) Name: Lake Forest College-com:SchedulingInterface-v1
14 Description: Scheduling Web Service for Institutions- 2
Scheduling Classes to appropriate rooms
15 WSDL: 2
16 4) Name: Metric-com:Aeroflot Flights Schedule
17 Description: Web service deliver on-line flights schedule 2
18 WSDL: 'http://webservices.aeroflot.ru/flightSearch.wsdl'
Listing 47.9 Output of querying by concept
In this pitfall, we demonstrated problems that developers encounter when using the JAXR API with UDDI registries. We showed two examples of potential pitfalls while traversing the data structures of the registry and provided solutions for these problems. Because of the difficulty that some programmers have with JAXR and UDDI, reading the JAXR specification is highly recommended.
Item 48: Performance Pitfalls in JAX-RPC Application Clients
The Java API for XML-based Remote Procedure Calls (JAX-RPC) allows us to continue to think like Java developers when we develop, deploy, and communicate with RPC-based Web services. Although JAX-RPC relies on underlying protocols (HTTP and SOAP), the API hides this complexity from the application developer. Using basic programming techniques that enterprise developers are accustomed to, you can create a Web service easily. Building a client that communicates with the Web service is also
418 Item 48
easy—proxy stubs for the Web service can be compiled prior to runtime, they can be dynamically generated at runtime, or the Dynamic Invocation Interface (DII) can be used to discover a Web service's API on-the-fly.
In this pitfall item, we use different techniques in building clients for a simple Web service. We run a timing experiment on each of the techniques and give recommendations for building clients using JAX-RPC. As a result of reading this pitfall item, you will understand the performance implications of using each technique—and hopefully use this to your advantage in your projects.
Example Web Service
For this pitfall item, we used Sun's Java Web Services Developer Pack (WSDP) and created a simple Web service called "SimpleTest." The Web service has one method called doStuff(), and the interface used to develop this Web service is shown in Listing 48.1.
001 package org.javapitfalls.item48;
003 import java.rmi.Remote;
004 import java.rmi.RemoteException;
006 public interface SimpleTestIF extends Remote
008 public String doStuff(String s) throws RemoteException;
Listing 48.1 Interface to our simple Web service.
The Web Service Description Language (WSDL) that was automatically generated from the tools available with the developer's pack is shown in Listing 48.2. Because this was automatically generated and deployed with the developer tools that generated this from our Java interface, our implementation class, and deployment descriptors, we weren't forced to write it by hand. As JAX-RPC defines Web services as collections of remote interfaces and methods, WSDL defines Web services as a collection of ports and operations. The WSDL provided in Listing 48.2 is for your reference, as we develop our Web service clients later in the pitfall examples.