C H A P T E R  3

Creating a Web Service Client

The Sun ONE Studio 5, Standard Edition IDE gives you several ways to create a web service client without writing client code. This chapter describes the IDE tools and procedures that you can use to do each of the following tasks:


Creating a Client From a Local Web Service

This section assumes that you start with an existing web service developed in the IDE.

You can automatically generate a simple client to test your web service during development. (See .)

You can customize the generated client or replace it entirely by a more sophisticated client that can be used for business purposes.

Creating the Client

You can create a client starting at a web service node, a package node, or the IDE's main window menu.

To start at a web service node:

1. To open the New Web Service Client wizard from the Explorer, right-click the web service node (the one with the blue sphere icon Web service icon) and choose Create New Web Service Test Client.

A dialog box is displayed, as illustrated in FIGURE 3-1.

 FIGURE 3-1 New Client From Local Web Service Dialog Box

Screenshot of new web service client wizard, opened from web service node. Buttons are Browse, OK, and Cancel.

2. Enter the desired location of your web service client in the Package field, or click Browse to find and select a package.

3. In the Name field, type a name for the new web service client and click OK.

Your new web service client is displayed in the Explorer. A client node (Client icon) appears under the designated package.

If you enter the name of a web service client that already exists in the package designated in the wizard, the IDE displays an informative error message.

To start at a Java package node:

1. Right-click a Java package node and choose New right arrow All Templates right arrow Web Services right arrow Web Service Client.

Alternatively, Choose File right arrow New right arrow Web Services right arrow Web Service Client from the IDE's main window.

In this case the IDE displays the Web Service Client dialog box, as illustrated in FIGURE 3-2.

 FIGURE 3-2 New Web Service Client Dialog Box

Screenshot of new web service client wizard, opened from package node or main menu. Buttons are Browse, Back, Next, Finish, Cancel.

2. Set the desired name and package.

3. Select Create From: Local Web Service.

4. Click Next to open a chooser, select the desired web service, and click Finish.

Your new web service client is displayed in the Explorer. A client node (Client icon) appears under the designated package.

Setting the Client Type: JAXRPC or kSoap

The IDE can generate a client that uses the JAX-RPC runtime (the default) or the kSOAP runtime. A JAX-RPC client is implemented as a web application with JSP pages as the presentation layer and a web browser as the front end. kSOAP is a SOAP API suitable for the Java 2 Microedition (J2ME) and wireless applications.



Note - If you have an old Apache SOAP client, the IDE automatically converts it to a JAX-RPC client during the generation.



To set the client type:

1. Create the client.

2. Right-click the client node and choose Properties. The Soap Runtime property has the default value JAXRPC.

3. Click the property value.

The choices JAXRPC and kSoap are displayed, as shown in FIGURE 3-3.

4. Choose kSoap or leave the default value, JAXRPC.

When you generate the client, a kSOAP or JAX-RPC client is created.

 FIGURE 3-3 Client SOAP Runtime Property

Screenshot of client properties, showing SoapRuntime property with choices JAXRPC and kSoap.

Clients that use the kSOAP runtime execute on small J2ME devices such as cell phones and PDAs, whose user interfaces are typically constrained by the display limitations. Developers often use Java AWT, WML, and other presentation technologies to create the user interfaces.



Note - In order to generate a kSOAP client in the IDE, you must have the kjava module installed. In order to test a kSOAP client in the IDE, you must have the kjava-emulator module installed. These two modules are not automatically installed with the IDE, but you can download them from the Update Center. To do this, choose Tools right arrow Update Center and use the Update Center Wizard. For more information about the Update Center, see Sun ONE Studio 5, Standard Edition Getting Started Guide, or the IDE's online help, or the Release Notes.



For information about wireless applications, see the following resources:

The following sections describe JAX-RPC clients and kSOAP clients.

Generating a JAX-RPC Client

To generate a JAX-RPC client:

1. Set the Soap Runtime property value to JAXRPC.

2. Right-click the client node in the Explorer, and choose Generate Client Files.

The IDE generates:

Each of these elements is described in the following sections.

The Generated Files

The IDE displays the generated client files under two nodes in the same package as the client:

The Explorer hierarchy for a JAX-RPC client is illustrated in FIGURE 3-4.

 FIGURE 3-4 Client Documents Node and GenClient Node in Explorer

Screenshot of Explorer display of web service client, showing Generated Documents node andGenClient node.[ D ]

The JSP Custom Tags

This book assumes general knowledge of JSP technology. There are many books available on this subject. You can find the JSP specification at:
http://java.sun.com/products/jsp/download.html#specs

The IDE generates a JSP tag library with custom tags that make the client's JSP pages easier to read. Web designers can customize the client's presentation without expert knowledge of the Java programming language, using web design tools such as Macromedia's Dreamweaver.

Here is an example of a custom tag:

<ws:sayHello string_1=":?" var="resp">
</ws:sayHello>

This tag could be used to invoke a remote web service operation exposing the following method:

String resp = sayHello(String string_1);

Each web service's operation name and operation parameters are mapped to the corresponding tag name and tag attributes.

The tag attribute value ":?" instructs the tag handler to automatically bind the attribute value from HTML form request variables.

The result of the web service operation call is returned to the JSP page as a JSP scripting variable named in the attribute var. The JSP page renders the content of the returned scripting variable, using JSTL (Java Standard Tag Library) tags to produce the default result presentation.

The Client HTML and JSP Pages

The generated client documents include:

The names of the welcome page and JSP error page appear in the IDE as properties of the client node, as illustrated in FIGURE 3-3.

To view the code of an HTML page or JSP page:

single-step bulletRight-click the node of the desired document and choose Open.

Sample code for a generated welcome page is illustrated in FIGURE 3-5.

 FIGURE 3-5 Client HTML Welcome Page

Screenshot of Source Editor display of part of a client welcome page, showing HTML code with JSP references.

Sample code for a generated JSP page is illustrated in FIGURE 3-6.

 FIGURE 3-6 Client Sample JSP Page

Screenshot of Source Editor display of part of a client JSP page for the findCompany method.

The Client Proxy Classes

FIGURE 3-7 shows an Explorer view of some of the classes generated for a JAX-RPC client.

 FIGURE 3-7 Client SOAP Proxy GenClient Node

Screenshot of Explorer partial display of classes for a client JAX-RPC proxy.

To view the Java source code:

single-step bulletRight-click a class or method node and choose Open.

The IDE lets you edit the proxy source, but if you regenerate the client in the IDE your proxy source changes are not preserved.

You can use the generated client proxy with a Java Swing client or more sophisticated HTML and JSP pages.

Using Your Own Front-End Client Components

You might already have a front end for your business client, such as a Swing component or a more sophisticated set of HTML pages and JSP pages than those generated by the IDE. Under those circumstances you might want the IDE to generate only the client proxy classes.

To generate only the client proxy classes:

1. Create the client.

2. Right-click the client node and choose Properties. The Generate Presentation property has the default value True.

3. Change the Generate Presentation property value to False.

When you generate the client, only the client proxy classes are created. Typically you might do this if you are using your own front-end presentation. In this case, you might need to add your own documents, libraries, or classes to the client's WAR file.

To add documents, libraries, or classes to your client's WAR file:

1. If the files were created outside the IDE, such as HTML and JSP pages created in a web design tool, mount the directory containing the files so they are visible in the IDE's Explorer.

2. Right-click the client node and choose Add to WAR File > objectType, where object-type is Documents, Libraries, or Classes.

The IDE displays a chooser.

3. Navigate to a folder that contains your documents, libraries, or classes, select the desired objects, and click OK.

The IDE creates a Documents, Libraries, or Classes folder under the client node, with references to the added objects, as illustrated in FIGURE 3-8.

 FIGURE 3-8 Client References to Documents, Libraries, and Classes

Screenshot of Explorer showing a client node with Documents, Libraries, and Classes subnodes.

The IDE adds the documents, libraries, or classes to your client's WAR file and you can use them to build a custom client.



caution icon

Caution - Deleting a reference to a file or folder deletes only the reference, leaving the referenced file or folder intact. However, nodes inside a referenced folder are links that represent actual files or folders. Deleting a node inside a referenced folder deletes the file or folder that the node is linked to. Do not delete nodes within a referenced folder unless you want to delete actual files or folders.



Validation During Client Generation

During the generation process, the IDE analyzes the web service's WSDL and issues validation warning and error messages if there are problems such as invalid data types (for example, a user object that is not a valid JavaBeans component). Validation is especially important when you are creating a client from someone else's web service, such as a web service accessed through a UDDI registry. IDE validation is based on the JAX-RPC reference implementation.

Refreshing a Client From Its Web Service

The Refresh From Web Service menuitem is an alternative to Generate Client Files. When you choose Generate Client Files, the IDE generates client proxy classes and documents based on a combination of the web service properties and the client properties.

For example, if a local web service is stateful, the IDE creates a stateful client by default. The web service and client both have their Conversational property set to True. If you manually change the client's Conversational property to False and then use the Generate Client Files, the IDE keeps your change and generates a stateless client.

An alternative to Generate Client Files is Refresh from Web Service. When you choose this menuitem, the IDE generates the client proxy classes and documents based on the properties of the web service. In this case, if your local web service has the Conversational property True, the IDE makes the Conversational property of the client True to match the web service.

If a web service is enhanced after a client was created, methods might be added and method signatures might change. The Refresh uses the new WSDL and generates client files appropriate to the enhanced web service.

If the client is generated from a WSDL file or from the WSDL reference in a UDDI registry, only the web service properties that are carried in the WSDL are used by Refresh From Web Service. In particular, security and conversational properties are not specified in WSDL, so the IDE does not change the client values.

To regenerate a client based on the web service:

single-step bulletRight-click the client in the Explorer and choose Refresh From Web Service.

This causes the client proxy and documents to be regenerated.



Note - If the client was generated from a local web service, the menuitem is Refresh From Web Service. If the client was generated from a WSDL file, the menuitem is Refresh From WSDL. If the client was generated from a UDDI registry, the menuitem is Refresh From UDDI. In all cases, the IDE generates the client on the basis of the WSDL file at the original location. The IDE keeps the URL of the WSDL file as the value of the client's Source property.



The Service Endpoint URL

For your client to access a service instance at runtime, the client proxy must use the endpoint URL of the service. The IDE can set a default URL in the proxy, or the URL can be passed to the proxy at runtime in its serviceURL parameter, which overrides the default.

The client JSP pages generated by the IDE do not pass the URL at runtime but instead assume that the client proxy has a default value for serviceURL. The default URL comes from the WSDL that is used to generate the client proxy.

You might want the client to override the WSDL value of the endpoint URL if the web service is redeployed to a production system, or for other reasons.

To make your client pass the endpoint URL at runtime:

1. Right-click the client in the Explorer and choose Properties.

2. Set the SOAP RPC URL property to a URL of your choice.

This URL overrides any default URL that might have been derived from the WSDL file.

Deploying a JAX-RPC Client

The IDE deploys the client as a web application in your application server's web container.

To deploy the client:

single-step bulletRight-click its node in the Explorer and choose Deploy.

The client's deployed WAR file is visible in the Explorer's runtime tabbed pane, as illustrated in FIGURE 3-9.

 FIGURE 3-9 Client WAR File in Explorer (Deployed Web Modules Node)

Screenshot of Explorer's Runtime tabbed pane, showing the application server with deployed web modules.

The client's WAR file node is visible in the Explorer's Filesystems tabbed pane, as illustrated in FIGURE 3-10.

 FIGURE 3-10 Client WAR File in Explorer (Client Node)

Screenshot of Explorer showing a client node and the client's generated WAR node.

To view the contents of the WAR file:

single-step bulletRight-click the client's WAR node in the Explorer's Filesystems tabbed pane, and choose View WAR Content.

The IDE displays the WAR file contents, as illustrated in FIGURE 3-11.

 FIGURE 3-11 Client WAR File Contents

Screenshot of WAR contents display, listing the MANIFEST, WEB-INF classes and jar files, html and jsp files.

Executing a JAX-RPC Client

This section assumes that the web service referenced by your client has been deployed, that your client has been deployed, and that the servers hosting the service and client are running.

To execute the client:

single-step bulletRight-click the client node in the Explorer and choose Execute.

The IDE executes the client and displays the welcome page in your default web browser, as illustrated in FIGURE 3-12.

 FIGURE 3-12 Client Welcome Page

Screenshot of web browser display, showing client welcome page with buttons and fields to invoke two web service methods, passing input parameters.

Suppose that the web service is deployed in a J2EE application, and that you make the client the default test client, as explained in . In this case the IDE deploys the client with the web service, and you can execute the client from the J2EE application node.

To execute the default test client from the J2EE application node:

single-step bulletRight-click the J2EE application node in the Explorer and choose Execute.

The client generated by the IDE gives you two ways of viewing the result of each web service method call. You can view the results in a user-friendly format, or you can view the SOAP request and response messages in XML format.

Consider the example in FIGURE 3-12 and the findCompany method. Suppose you enter a valid company ticker symbol for string_1 and click Invoke. The client displays company information in the browser, as illustrated in FIGURE 3-13. This is a user-readable display that can be a starting point for a web designer to customize the presentation.

 FIGURE 3-13 Client Display of Company Information

Browser display, showing company information.[ D ]

If you click the View SOAP Request/Response link, the client displays the SOAP request message (which is sent from the client to the web service) and the SOAP response message (which is sent from the web service to the client). This display, illustrated in FIGURE 3-14, includes SOAP envelopes and data, and might be useful for debugging a client or web service.

 FIGURE 3-14 Client Display of Company Information (SOAP Req uest/Response)

Browser display, showing company information request/response messages in XML format, with SOAP envelopes.

Note - The IDE generates JSP pages with names that match the corresponding operations of the web service. If you are testing a client and you want to be sure which JSP page is implementing a given part of the display, see the URL in your browser.



Firewalls

If the client is executing inside a firewall and the web service is outside the firewall, you must specify the proxy host and proxy port.

To specify the proxy host and proxy port at runtime:

single-step bulletClick the Input proxy server link on the welcome page.

The client displays a page, illustrated in FIGURE 3-15, in which you can enter values for the proxy host and proxy port.

 FIGURE 3-15 Client Input Proxy Server Page

Screenshot of proxy server input page, with fields for HTTP and HTTPS proxy host and proxy port.

To specify default values for the proxy host and proxy port in the IDE:

single-step bulletChoose Tools right arrow Options right arrow IDE Configuration right arrow System right arrow System Settings right arrow System from the IDE's main window, and set the values of Proxy Host and Proxy Port.

These values become the default values for clients generated by the IDE.



Note - If a client's user enters runtime values for proxy host and proxy port, the runtime values override any default values set in the IDE.



Distributed Applications

A variety of problems can arise when the client and web service are running in different servers. In a development environment the servers are likely to be the same and under your control. In a production environment the servers are likely to be different and under the control of system administrators. You might encounter runtime messages, such as a java.security.AccessControlException message, that require permissions to be set on the server.

For further information about problems of this kind, see Sun ONE Studio 5, Standard Edition Release Notes.

Generating a kSOAP Client

In order to generate a kSOAP client in the IDE, you must have the kjava module installed. For information about how to install this module, see Setting the Client Type: JAXRPC or kSoap

To generate a kSOAP client:

1. Set the client's Soap Runtime property value to kSoap, as described in Setting the Client Type: JAXRPC or kSoap.

2. Right-click the client node in the Explorer, and choose Generate Client Files.

The IDE generates:

The generated client nodes are illustrated in FIGURE 3-16.

 FIGURE 3-16 kSOAP Client Nodes in the Explorer

Browser display, showing a kSOAP client with MIDlet and proxy class.

Clients that use the kSOAP runtime execute on small J2ME devices such as cell phones and PDAs, whose user interfaces are typically constrained by the display limitations. Developers often use Java AWT, WML, and other presentation technologies to create the user interfaces.



Note - For a kSOAP client, the IDE does not create a Generated Documents node and does not generate HTML or JSP pages.



Executing a kSOAP Client

In order to execute a kSOAP client in the IDE, you must have the kjava-emulator module installed. For information about how to install this module, see Setting the Client Type: JAXRPC or kSoap.

To execute a kSOAP client in the IDE:

single-step bulletRight-click the client node in the Explorer, and choose Execute.

The IDE opens the emulator and displays a client menu, as illustrated in FIGURE 3-17.

 FIGURE 3-17 kSOAP Client Executing In Cell Phone Emulator


Creating a Client From a WSDL File

WSDL provides a portable representation of the external interfaces of a web service. See for the procedure to create a WSDL description of your web service. See WSDL and for other information about WSDL and UDDI registries.

WSDL can be useful even if you are not using a UDDI registry. Several people on a project might be developing different kinds of clients, perhaps in different locations or on different schedules. They can be given copies of the WSDL to generate clients. A WSDL file is an XML document and can be put on a shared network drive, sent as an email attachment, or passed around on a disk. The developers must also have network access to a runtime instance of the web service to test their clients.

The following procedure assumes that you have a WSDL file, that the file name extension is .wsdl, and that the directory containing the file is mounted in the IDE. The .wsdl file appears as a node in the Explorer with a green sphere icon (WSDL icon). If someone gives you a WSDL file that does not satisfy this naming convention, you can rename it or make a copy with a file-name extension of .wsdl.

To generate a client from a WSDL file:

1. From the IDE's main window, choose File right arrow New right arrow Web Services right arrow Web Service Client, and click Next.

The IDE displays the Web Service Client dialog box, as illustrated in FIGURE 3-2.

2. Set the desired name and package, and select Create From: Local WSDL File.

3. Click Next to open a chooser window.

4. Select the desired WSDL node in the chooser window, and click Finish.

The IDE creates a client node with default Soap Runtime property JAXRPC. You can change this property to kSoap if you want a wireless client.

5. Right-click the client node in the Explorer and choose Generate Client Files.

The IDE creates the client files.



Note - As an alternative to Generate Client Files, you can choose Refresh From WSDL. See Refreshing a Client From Its Web Service for an explanation of this context-sensitive menuitem.



6. The remaining steps, including deployment and execution, are the same as in Creating a Client From a Local Web Service.

To generate only the client's supporting classes, without the Generated Documents (for a JAX-RPC client) or the MIDlet (for a kSOAP client):

1. Right-click the client node in the Explorer, choose Properties, set the value of the Generate Presentation property to False.

2. Right-click the client node in the Explorer and choose Generate Client Files.

The IDE creates only the client proxy classes.

3. Create your own client component that makes calls to the client proxy.

This might be the best approach if you already have fully developed clients that you can easily customize to use the client proxy, or if you want to use a type of client that is different from the HTML and JSP pages generated by the IDE, such as a Java Swing client.


Creating a Client From a UDDI Registry

Some of the business needs and scenarios that might lead you to create a client from a UDDI registry are described in Chapter 1. This section gives an overview of the planning and work flow, followed by the procedures for searching a UDDI registry, selecting a web service, and creating a client.

Creating a Client--Planning and Work Flow

The work flow consists of these tasks:

Determining your criteria for finding a web service in a UDDI registry requires advance planning and is part of the application design process. It is not enough to consider only the characteristics of the web service. You also have to think about the business that is providing the service, what kind of support the business offers, and how much your use of the service is likely to cost. The analysis is simplified if you are using a private registry and the service provider is a part of your own project or enterprise, or perhaps a business partner collaborating on your project.

Creating a Client--Procedure

This section describes how to use the IDE to select a registry, search the registry for a service, and generate a client that can access a runtime instance of the service.

1. Right-click a Java package node and choose New right arrow All Templates right arrow Web Services right arrow Web Service Client.

Alternatively, Choose File right arrow New right arrow Web Services right arrow Web Service Client from the IDE's main window.

The IDE displays the Web Service Client dialog box, as illustrated in FIGURE 3-18.

 FIGURE 3-18 New Web Service Client Wizard

Screenshot of new web service client wizard. Buttons are Browse, Back, Next, Finish, Cancel, and Help.

2. Set the desired name and package, and select the UDDI Registry Web Service radio button for Source.

3. Click Next to display the Select a UDDI Registry dialog box, as illustrated in FIGURE 3-19.

The dialog box displays a list of UDDI registries.

At this point you can select the desired registry.

You can also click Edit to change the default registry or edit registry information (see ).



Note - The initial default registry in the IDE is the internal UDDI registry that is bundled with the IDE. For further information about this registry, see .



 FIGURE 3-19 UDDI Registry Selection Dialog Box

Screenshot of Select a UDDI Registry dialog box. Buttons are Back, Next, Finish, Cancel, and Help.

The IDE provides two ways to search for a web service. You choose the search method my clicking one of two radio buttons. The default choice, illustrated in FIGURE 3-19, uses the IDE wizard to conduct the search. The other choice uses a web browser and browser-based software provided by the registry owners.

Most UDDI registries provide browser-based tools for registry searches and for adding, editing, and deleting registry entries. The Browser Tools URL for a registry is one of the properties that you can edit in the IDE (see ).

To search a selected registry with its own browser tools:

a. Select the "Search for service using a web browser" radio button.

The Launch Browser button becomes active.

If you already have the web service's registry key from a previous search, paste the value into the Service Key field and click Next. The IDE displays the final wizard step in which you can click Finish to create the client, bypassing intermediate UDDI registry search steps.

b. Click Launch Browser.

The IDE opens your default web browser at the Browser Tools URL web page.

c. Use the browser tools to locate the web service that you want to access with your client.

d. Copy the web service registry key and paste it into the Service Key field in the Select a UDDI Registry dialog box.

e. Click Next.

The IDE displays the final wizard step in which you can click Finish to create the client, bypassing intermediate UDDI registry search steps.



Note - The remainder of this procedure assumes that you do your search through the IDE wizard. This is the default radio button under "How to Find Web Service."



4. Select a registry from the UDDI Registry list and click Next to display the Search UDDI Registry dialog box, as illustrated in FIGURE 3-20.

 FIGURE 3-20 UDDI Registry Search Dialog Box

Screenshot showing Search a UDDI registry and select a web service dialog. Buttons are Search, Filter Businesses, Back, Next, Finish, and Cancel.[ D ]

You can search for businesses whose names contain a string that you specify. You can also base your search on a type other than business name. The list of search types is shown in FIGURE 3-21.

 FIGURE 3-21 UDDI Registry Search Types

Screenshot of registry search types. Select one type from the list. The default type is Business Name.[ D ]

You can search on tModel name, NAICS code name, or ISO 3166 code name.

You can also search for a D-U-N-S business identifier or Thomas Registry business identifier, in which case the search is for a value "Equal To" rather than "Containing." You might know the identifier from a previous search. If you are using a private UDDI registry, someone in your project or enterprise might give you the identifier.



Note - If the search type requires an exact value, the label in the UDDI Registry Search dialog box (FIGURE 3-20) changes from Containing to Equal To.



For NAICS or ISO 3166 code name searches, you can enter either a name or a code in the Containing field. For example:

A search on tModel Name returns all businesses that contain services that are based on the tModels matching the search string.

A search on NAICS Code Name or ISO 3166 Code Name returns all businesses that have categories matching the search string.



Note - When you specify a string in the Containing field, the IDE wraps your string in a wildcard: %yourstring%. You can optionally insert more wildcards. For example, you can search for a business whose name contains the string bio%tech, where % matches any string. String searches are case-insensitive.



The remainder of this procedure assumes that you search on business name.

5. Enter a string in the Containing field and click Search.

The Matching Businesses table displays all businesses in the registry whose names contain your search string, as illustrated in FIGURE 3-22. Each business is listed with its name and an optional description. The number of matching businesses is also displayed.

You can select a business from the table and proceed to Step 7 of this procedure.

Depending on your search string and the size of the registry, your search might return a large number of businesses. This is most likely to occur with public registries, which are expected eventually to grow to tens of thousands or even millions of entries. If the list returned by your search is too large, you can enter a more carefully chosen search string or you can use the registry browser tools to perform a more advanced search.



Note - In a realistic scenario, a development team or planners probably know what businesses they are interested in. The main problem when seeking a business in the registry might be spelling the name correctly or (in the case of a large enterprise with many divisions, departments, and projects) finding out which of its names is used in the registry. Registry search features can help, but in many cases this information is managed by the appropriate project leaders.



 FIGURE 3-22 UDDI Registry Search Dialog Box With Matching Businesses

Screenshot of registry search dialog displaying matching business. Buttons are Search, Filter Businesses, Back, Next, Finish, and Cancel.

6. Click Filter Businesses to further refine your search.

There might be services in the registry that have no WSDL tModel entries. Since you can't create clients for those services, the IDE enables you to filter them out of the Matching Businesses table. When you click Filter Businesses, the IDE searches the UDDI registry for services associated with the businesses in your result set. The IDE checks the services for tModels that have an OverviewDoc with an OverviewURL field that begins with http:// and ends with either wsdl or asmx. Businesses that fail this test are filtered out of the Matching Businesses table.

The IDE displays a progress monitor window with a Cancel button, as illustrated in FIGURE 3-23. The filtering process can take some time. If it takes too long, you can click Cancel and start over with a more refined search string.

 FIGURE 3-23 UDDI Registry Filter Business Progress Monitor

Screenshot of Progress Monitor with progress bar labeled Removing Business that have no Service. Button is Cancel.

7. Select a business from the Search Results list.

The IDE displays services associated with the selected business, as illustrated in FIGURE 3-24, and activates the Next button. Only services with WSDL tModel entries are displayed.



Note - The registry might not have enough information about a business or service to guide your decision. Public registries are still in their infancy and can be viewed as elements of a broader web service infrastructure in which usage patterns and practices will emerge over time. A private registry gives the registry owner more control of the criteria for publishing services. For example, a private registry might have standards for documenting entries and requirements about the runtime availability of services that are published to the registry. There might be a distinction between services available for development and testing, and services available for use in production applications.



 FIGURE 3-24 UDDI Registry Select Service

Screenshot of registry search dialog, displaying filtered businesses. A business is selected and its service is displayed.

8. Select a service and click Next to display the Service Interface dialog box, as illustrated in FIGURE 3-25.

The dialog box shows detailed information about the service and the tModels and WSDL that it references.

For the service, you see the name, network endpoint, and key. The network endpoint is the URL that a client can use to access the runtime service instance.

For each WSDL tModel, you see a name and overview URL. The overview URL is the locator for the WSDL that the IDE uses to create your client.



Note - A web service provider might publish several tModels for a given service instance. For example, one tModel might allow full use of the service methods and another tModel might provide access to a subset of the service methods. This is reflected in clients generated from the two different tModels.



 FIGURE 3-25 UDDI Registry Display Service Details and tModel

Screenshot showing selected service displayed with detail information and associated WSDL tModels. Buttons are Back, Next, Finish, Cancel.

9. Select a WSDL tModel and click Finish.

The IDE creates your web service client. It appears in the Explorer under the designated package as a new client node.

10. Right-click the client node in the Explorer and choose Generate Client Files.

The IDE creates the client files.



Note - As an alternative to Generate Client Files, you can choose Refresh From UDDI. For an explanation of this context-sensitive Refreshing a Client From Its Web Service.



11. The remaining steps, including deployment and execution, are the same as in Creating a Client From a Local Web Service.


Attachments

A web service operation's input parameters and return values are transmitted in one of two ways: encoded as XML tags or attributes within the message's SOAP body, or appended to the message as an attachment. Attachments are generally used for objects that are not easily or efficiently serialized into an XML representation, such as images. An attachment is packaged as a well-defined MIME-encoded region of the message. The IDE supports the World Wide Web Consortium (W3C) standard for SOAP attachments.

The most common use of JAX-RPC attachments is for the return of images, such as gif and jpeg data. The IDE can generate "image-aware" JAX-RPC test clients for web-centric web services that return images (objects of the Java.awt.Image class).

Attachments Example

The following example is based on a Java class named attTest that has several methods for processing images and text. A web-centric web service named attWS exposes the business methods of the Java class. A JAX-RPC test client named attWSClient communicates with the web service.

The example assumes that the web service has been deployed and that the server is running.

CODE EXAMPLE 3-1 shows the source code of the Java class, attTest. The business methods are:

FIGURE 3-26 shows an Explorer view of a web-centric web service named attWS and a test client named attWSClient, which call the methods of the attTest Java class.

 FIGURE 3-26 Explorer View of Web Service and Client That Process Images and Text

Screenshot showing Explorer view of a web service and client that process images and text.

When you right-click the web service and choose Execute, the IDE opens a browser and displays the client's welcome page, as illustrated in FIGURE 3-27.

 FIGURE 3-27 Client Welcome Page For Image and Text Processing

Screenshot showing welcome page for a client that displays images and text.

When you click Invoke for the getImage method, the client displays the page illustrated in FIGURE 3-28.

 FIGURE 3-28 Client JSP Page For the getImage Method

Screenshot showing a JSP page for a web service that displays images using the getImage method.

When you click the View Attachment link, the client displays opens a new window and displays the image, as illustrated in FIGURE 3-29.

 FIGURE 3-29 Client Display of Image

Screenshot showing a client display of a gif image (a microscope).

The DataHandler Property

The JAX-RPC specification, Section 7.2, states:

A remote method in a Java service endpoint interface may use the following Java types to represent MIME encoded content:
The JAX-RPC specification uses the JavaBeans Activation Framework to support various MIME content types. The DataHandler class provides a consistent interface the data represented in various MIME types....

(See Software Versions for the URL of the JAX-RPC specification.)

The IDE provides a client property that you can use to cause a generated client to represent MIME encoded content with the DataHandler class. To do this:

1. Right-click the client node, choose Properties, and change the Use DataHandler Only property from False (the default) to True.

2. Right-click the client node and choose Generate Client Files.

FIGURE 3-30 shows the client class attWSRPC that the IDE generates when the Use DataHandler Only property is False.

 FIGURE 3-30 Client Class attWSRPC With Use DataHandler Only Property False

Screenshot showing code for client class attWSRPC with Use DataHandler Only Property False.

FIGURE 3-31 shows the client class attWSRPC that the IDE generates when the Use DataHandler Only property is True.

 FIGURE 3-31 Client Class attWSRPC With Use DataHandler Only Property True

Screenshot showing code for client class attWSRPC with Use DataHandler Only Property True.

For information about how to use the DataHandler class, see http://java.sun.com/j2ee/sdk_1.2.1/techdocs/api/javax/activation/DataHandler.html


Stateful Web Services and Clients

For information about creating stateful web services and clients, see .


SOAP Message Handlers

For information about using SOAP message handlers with web services and clients, see Chapter 4.


Security

For information about implementing security for web services and clients, see Appendix A.