1.1 Introduction to Web Services and Applications

The rise of the Internet and the World Wide web sparked a revolution not only in network communications but also in application design and development. Programmers have encapsulated pieces of business functionality into distinct objects or components, and then made them available as self-contained web services that can be accessed using Internet-based protocols and tools.

As network servers have become capable of supporting Internet-based services, software developers have devised new programming paradigms to take advantage of the widespread availability of these services. This new class of software is categorized as web-based or web-enabled applications.

This section introduces some basic concepts and technologies that are helpful to understand when working with web application services.

1.1.1 What Are Web Services?

The term web services can be confusing because it is used in many different ways. In most contexts, web services are business logic components that can be connected together and exchange data to perform a useful task. The components can be internal or external to an organization, and they communicate using Internet-based protocols such as the HyperText Transfer Protocol (HTTP). In brief, web services run on servers and process substantial amounts of data that users want to be able to access quickly and easily.

A popular programming model in which individual web services are combined to create a functional whole is the service-oriented architecture. In this model, a service consumer sends requests to a service provider over a standard connection. The request and subsequent response are defined in a way that is understandable to both the consumer and provider.

Most web services use Extensible Markup Language (XML) to define the format of request and response messages. XML features a tagged structure that provides the needed flexibility for exchanging data between disparate components. XML can also be used to define how data is stored in a database.

Simple Object Access Protocol (SOAP) provides a standard for enveloping and sending web services messages. It is an XML messaging specification that describes a message format along with rules for exchanging data in the proper sequence between structured data types and arrays. SOAP generally uses HTTP, but it can use other standard web protocols as well.

In the service-oriented architecture, service consumers can find available service providers through various discovery mechanisms. One such mechanism is the Universal Description, Discovery, and Integration (UDDI) registry. As web services are developed, they can be added to the UDDI registry. The registry can then be searched in various ways to find the web services available for a particular organization and obtain contact information.

1.1.2 What Are Web Applications?

In its simplest form, a web application is an interactive system that allows its users to execute business logic that resides on a server and to view the results of that logic through a web browser on a client workstation. The defining factor that makes the system a web application is that the server and client communicate over the Internet. In brief, web applications make the data processed by web services available to users quickly and easily through their web browsers.

Web applications are built on a client/server architecture. The business logic is contained in the application itself, which runs on a web server and uses HTTP to communicate with clients over the Internet. The web server manages the application, passes requests from clients to the application, and returns the application's responses to the client.

On the client side, the web application is viewed with a browser. The application's user interface takes the form of HyperText Markup Language (HTML) pages that are interpreted and displayed by the browser. In addition to text, these HTML pages can contain web forms, image files, audio and video clips, and other types of displayable data.

Although web applications can use a website as the front end to their business logic, you can do many things in a web application that you can't do with a static website, such as:

  • Identify specific users and present a customized interface for each user

  • Collect information from users and store that information on the server

  • Perform tasks for users, such as retrieving information from a database, registering to access specific content, or placing an order for a product

1.1.3 Web Application Tools (Java and J2EE)

Java has become a standard programming language for web applications because it is simple and portable to various hardware platforms. All you need to run Java applications is a Java Virtual Machine (JVM) for your particular platform. JVMs are available for almost every server platform in existence, including SUSE Linux Enterprise Server, Novell NetWare, Sun Solaris, Microsoft Windows, and Apple Macintosh OS.

Java 2 Platform, Enterprise Edition (J2EE) is a widely used environment for developing enterprise web applications. J2EE offers a multitiered distributed application model, the ability to reuse components, integrated XML-based data interchange, a unified security model, and flexible transaction control. Best of all, applications developed for a J2EE application server are not tied to any one vendor's products or APIs.

The J2EE specification defines the following components:

  • Servlets: A Java servlet is a server-side component that provides a simple, consistent mechanism for extending the functionality of a web server and for accessing existing business systems. A servlet dynamically processes client requests and constructs responses. Servlets are commonly used to process forms, handle redirects or authenticate user names and passwords, and create dynamic content for a web application.

  • JavaServer Pages: JavaServer Pages (JSPs) are text-based documents that execute as servlets but allow a more natural approach to creating web content. JSPs allow web developers to rapidly develop and easily maintain dynamic web pages that leverage existing business systems. JSP technology separates the user interface from content generation, enabling the overall page layout to be changed without altering the underlying dynamic content.

  • Enterprise JavaBeans: Enterprise JavaBeans (EJBs) are the basic components of an architecture that allows developers to create objects that precisely model the structure and logic of a business application domain. The system-level details of building the distributed application are abstracted out, enabling domain experts to be developers who freely focus on solving business problems. EJB technology enables rapid development of distributed, transactional, secure, and portable Java-based applications.

1.1.4 Enabling Technologies

Web applications employ various enabling technologies to make their content dynamic and to create user interfaces into the business logic on the server.

Scripting Languages

Foremost among the enabling technologies are scripting languages such as PHP and Perl.

PHP (PHP: Hypertext Preprocessor) is a powerful server-side scripting language that is easy to learn. It offers all of the power and flexibility of JSP, but does not require as much memory and processing power. You mix specially delimited PHP code in with regular HTML to create a dynamic web page. PHP is commonly used to access web databases such as MySQL. It also supports library extensions to leverage standard services such as LDAP, FTP, POP3, Java, and many others.

Perl (Practical Extraction and Report Language) is another server-side scripting language commonly used by web programmers to create scripts for web servers. It uses a syntax similar to C/C++ and its file-manipulation and text-manipulation facilities make it ideal for tasks involving software tools, database access, graphical programming, networking, and system management.

Servlet Containers

A complementary component for both servlets and JSPs is the servlet container. The container acts as a simple application server that executes Java servlets and renders web pages that include JSP code. It provides necessary functions such as life cycle management and interaction with a web server.

The official reference implementation of the Java servlet API is Jakarta-Tomcat, an open source project released under the Apache Software Foundation. Tomcat is typically used in conjunction with a web server such as Apache.

Web Database Servers

MySQL is an open source, structured query language (SQL) web database server that is often used by PHP and Perl developers because its syntax is similar to those languages. It offers fast performance and is designed to work well with web servers. It is widely used in building basic database-driven web applications.

PostgreSQL is another web database server that offers more advanced features often found in commercial database systems, such as transactions, subselects, triggers, views, referential integrity, and sophisticated locking. It is often used to provide more complex database functionality for websites and web applications.

Application Servers

In more sophisticated web application models, an application server is added to enable the system to manage business logic and track the user's progress through the application. The application server software runs in a middle tier, between web browser-based clients and back-end databases and business applications. The application server handles all of the application logic and connectivity that old-style client/server applications contained.

Examples of J2EE application servers is the open source JBoss application server.

1.1.5 General Web Services and Applications Architecture

The following diagram shows the basic architecture of the web components and services that are commonly used to host websites and build web applications.

Figure 1-1 Architecture of Key Web Components and Technologies