Overview of JWSDP XML

JWSDP consists of software, tools, and a set of APIs that Sun Microsystems, Inc. provides. You can use these components of JWSDP to develop, deploy, and test Java Web services.

While you're unpacking and installing the JWSDP package, you are prompted for a username and a password. You need to provide this username and password (see Figure) while you deploy the application in the Tomcat container.

The Interface for Accepting the Username and Password

The Interface for Accepting the Username and Password

However, if you forget your username and password, you can look up the tomcat-users.xml file to find them. You will learn more about the tomcat-users.xml file in the later section "Authenticating Users to Access Web Services."

You need to install Java2SDK Standard Edition version 1.3.1_03 or later to be able to use JWSDP. After you have installed the JWSDP toolkit, you need to set the following paths:

  • Create and set the environment variable JWSDP_HOME to the directory where the JWSDP is installed.
  • Set the Path variable of the system to the Bin folder of the JWSDP parent directory.

JWSDP consists of the following components:

  • JAXM
  • JAXP
  • JAXR
  • JAX-RPC
  • Java Server Pages Standard Tag Library (JSTL)
  • JWSDP Registry Server
  • Apache Tomcat
  • Web Application Deployment tool
  • Ant Build tool

JSTL

JSPs are dynamic Web pages that are executed at a server. A JSP page contains Java code scriptlets that are executed during runtime. The output of execution of Java scriptlets is displayed on the client Web browser. You can write the code for scriptlets to perform numerous tasks, such as accessing databases, performing numerical calculations, and so on.

Many tasks are common across JSP applications. To perform such common tasks, you are provided with a set of standard tags that work the same way everywhere. These tags are packaged in Java Server Pages Standard Tag Library (JSTL).

JSTL contains tags for performing tasks that include editing XML documents, querying databases, performing iteration, performing conditional operations, and so on. JSTL also enables you to integrate existing tag libraries with JSTL.

JSTL uses multiple Tag Library Descriptors (TLDs) to specify a namespace and its functionality. You can categorize the tags in JSTL into the following divisions:

  • Core. Some of the tags in this category are catch, out, choose, forEach, forTokens, import, and url.
  • XML. Some of the tags in this category are out, parse, for Each, if, and transform.
  • Internationalization. Some of the tags in this category are setLocale, bundle, formatNumber, and parseDate.
  • Database. Some of the tags in this category are setDatasource, query, and transaction.

You can use a JSTL core tag in a JSP page by using the taglib directive, as shown in the following example:

In a web.xml file, TLDs are referenced by using the following code snippet:

JSTL tag libraries are available in two versions:

  • STL-RT tag library
  • JSTL-ET tag library

These libraries differ in the way they support the use of runtime expressions. Expressions are specified in a scripting language by the tags in the JSTL-RT tag library. In contrast, for the tags in the JSTL-EL tag library, expressions are specified in the JSTL expression language. The naming conventions of the TLDs in both the libraries are as follows:

You can find the JSTL TLDs in JWSDP in the directory <JWSDP_HOME>/tools/jstl/tlds.

Note?/td>
To enable a Web application to use the tag libraries, you need to ensure that the JSTL API is available to the application. In addition, you must ensure that the application can implement the API.

JWSDP provides you with JSTL API and its implementation in the form of the archives jstl.jar and standard.jar. The jstl.jar archive is available in the <JWSDP_HOME>/tools/jstl directory. You can access the standard.jar archive from the < JWSDP _HOME >/tools/jstl/ standard directory.

The JSTL API defines some implicit objects for JSP. These implicit objects are as listed:

  • pageContext
  • pageScope
  • requestScope
  • sessionScope
  • applicationScope
  • param
  • paramValues
  • header
  • headerValues
  • cookie
  • initParam

You can refer to these implicit objects by using the following syntax:

For example:

In the preceding example, the number of items in the current session is being evaluated.

JWSDP Registry Server

Another important component of JWSDP is the JWSDP registry server. You need to register the Web services that you create and deploy so that a client is able to access them. To enable registration of Web services, JWSDP provides you with the JWSDP registry server. The registry server provides UDDI registry for Web services in a private environment.

You can use the registry server to test the applications that you develop by using the JAXR API. The registry server includes the following components:

  • A database based on the Xindice database, which is part of the Apache XML project. This database is a repository of registry data.
  • A tool named Indri that allows you to create and inspect database data by using a graphical user interface.

Starting the Registry Server

Before you use the registry server, you need to start both Tomcat and the Xindice database. To start Tomcat, execute the following command at the command prompt:

C:> startup

Tip?/td>
You can execute this command from any directory if you have set the environment variable PATH to <JWSDP_HOME>/bin.

To verify that the Tomcat server has started, type the following address in the address bar of the Web browser:

http://localhost:8080

To start the Xindice database, execute the following command:

Xindice-start

To stop the Xindice database, execute the following command:

Xindice-stop

The registry server provides a shell script to perform the following tasks:

  • Obtain authentication from the registry server.
  • Add a business to the registry server.
  • Search for a business.
  • Obtain business details.
  • Delete a business.
  • Validate UDDI messages.
  • Retrieve the business that belongs to a specific user.
  • Send UDDI request messages.

The Indri tool provides a GUI interface to access the registry server database. To start the Indri tool, execute the following command at the command prompt:

The output is displayed in Figure.

The Output of the Command to Run Indri

The Output of the Command to Run Indri

The GUI interface of Indri is displayed in Figure.

The GUI Interface of Indri

The GUI Interface of Indri

Working with Service Registries by Using JAXR

Service registries allow you to publish, access, and use Web services. Service brokers host Service registries that can implement different registry standards, such as UDDI, OASIS, and ebXML.

Microsoft and IBM provide registries that implement UDDI Version 2. You can use these test registries to publish your service.

In Java, you can use different applications to publish or access registered services. These registered services can implement different registry standards. JAXR helps you work with disparate registries. For example, you can use JAXR in your application to search for services in the IBM registry. Similarly, you can use JAXR to publish your service and manage your service data in some registries that might implement other registry standards.

The following two packages are used to encapsulate the complexities of working with
registries in the Java service model:

  • javax.xml.registry
  • javax.xml.registry.infomodel

Tip?/td>
To use JAXR in your application, you need to import these packages.

We will now discuss the code sample that uses JAXR. When you create an application, you need to create an instance of the Properties class, which specifies the URL of the UDDI registry. Instead of the UDDI registry, you can specify the URL of the IBM test query registry:

Next, you can create an instance of the ConnectionFactory class, as shown in the following code:

You need to obtain a BusinessQueryManager object for performing simple queries. To obtain the BusinessQueryManager object, you first need to obtain the RegistryService object. The following code discusses how to obtain the RegistryService object and use it to create an object of the BusinessQueryManager type:

To query an UDDI registry for an organization, you can use the findOrganization() method. The usage of the findOrganization() method is shown in the following code:

Observe in the code that the findOrganization() method returns a BulkResponse object. The BulkResponse object is used to obtain the Collection objects. After you obtain the Collection objects, you can iterate through these objects to locate the Organization object.

In the preceding code, notice the add() method. You can hard-code the organization name you want to query in the add() method. Alternatively, you can use a command-line argument that represents an organization name.

The following code shows how to locate the Organization object:

After you locate the Organization object, you can use it to obtain a collection of the services that the organization offers. The following code prints the service information and shows how you can obtain the service information:

In addition to querying registries, you can perform simple queries on registries and use JAXR in your application to register your service in a registry. You can also delete your service from a registry by using JAXR.

XML Documents by Using JAXP

In the Java service model, information is exchanged in the form of XML documents. Therefore, developers for the Java service model often need to process XML documents from with in Java applications. JAXP enables developers to easily access, process, and transform XML documents.

As you know, JAXP parses the XML documents by using the SAX or DOM parsers. JAXP encapsulates the complexities of using SAX and DOM APIs from Java applications to parse XML documents.

JAXP also enables you to switch effortlessly between different vendor-specific parsers. You can switch between parsers without needing to recompile your Java application. JAXP also supports the format transformation of XML documents by using XSLT.

To process XML documents by using JAXP, you need to perform the following steps:

  • Start the JWSDP and include xercesImpl.jar in the classpath.
  • Create an XML document called organization.xml that provides information about organizations.
  • Create a DTD with the name organization.dtd to which your XML document should conform.

We will now discuss the content of these files.

organization.dtd File

The code of the organization.dtd file is as follows:

organization.xml File

The code of the organization.xml file is as shown:

OrganizationInfo Class

To parse the XML document and display the result, create a Java class with the name OrganizationInfo. The packages that you need to import are as listed:

The OrganizationInfo class extends the DefaultHandler class. In the OrganizationInfo class, you need to implement the required callback methods that the parser calls. The following code illustrates the implementations of the required callback methods:

Next, create an object of the OrganizationInfo class in the main() method of the OrganizationInfo class. Then create an instance of the SAXParser class. Using this instance, parse the XML document, organization.xml. The following code illustrates the main() method of the OrganizationInfo class:

Compile and run the OrganizationInfo class.

Performing Service Message Transactions by Using JAXM

As discussed JAXM enables you to create, send, and receive SOAP messages. JAXM conforms to SOAP version 1.1 and SOAP with Attachment specifications.

A JAXM client can use a messaging provider, which is a service that transmits messages. JAXM provides the following packages to perform messaging in the Java service model:

  • javax.xml.messaging
  • javax.xml.SOAP

In the applications used, you provide the URL of the receiver of a message. The SoapConnection object obtains a connection directly to the receiver. The SoapConnection object is obtained from the factory class SoapConnectionFactory.

The code for specifying the URL of the receiver and obtaining a connection is shown in the following snippet:

After you obtain a connection, you need to create a SOAP message. You then obtain the various parts of the SOAP message to add your message content. The following code illustrates how to add contents to a SOAP message:

After you add contents to the SOAP message, save the message and send it to the receiver. The following code illustrates how to send the SOAP message to a receiver:

You can use the SOAPMessage object to print the receiver's response.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XML Topics