[Bernstein09] 10.2. Web Browser Front-End Programs

来源:百度文库 编辑:神马文学网 时间:2024/04/27 17:41:47

10.2. Web Browser Front-End Programs

As described in Chapter 3,a web browser is a common front-end program for TP applications. MostTP applications support them directly or can be adapted to supportthem, so we’ll cover them as a general topic applicable to anytransactional middleware.

Aweb browser requires a web server to handle HTTP requests and replies.In the multitier architecture the web server may directly interact withthe database or with one or more intermediate tiers created usingtransactional middleware components, as illustrated in Figure 10.1.In some cases the database system can function as a web server.Intermediate tiers typically introduce mechanisms for scalability andavailability, such as partitioning, replication, caching, and requestrouting. HTTP load balancers can be used to scale up browser access tothe web server itself. Typical web servers include Microsoft’s InternetInformation Server (IIS) and the Apache HTTP Server.

Figure 10.1. Web Browsers and Multitier TP Architecture. Webbrowsers work with TP applications in a variety of ways, includingdirect database access and multitier architectures using transactionalmiddleware.
[View full size image]

Onepopular type of web browser programming environment is AJAX(Asynchronous JavaScript and XML). AJAX enables browser-based forms andmenus to be highly efficient and interactive. Compared to browsersusing plain HTML or XML, AJAX introduces three major benefits for TPapplications: using AJAX the browser needs to exchange only the changedinformation with the web server, instead of the entire page, therebyreducing communication expense and improving response time; AJAX allowsasynchronous interaction with the web server, which does not block theuser’s interaction with forms and menus; and AJAX allows the browser tooffload the web server by absorbing more of the application processingload.

A simpleAJAX program typically involves the exchange of an XML document with aweb server and mapping the data into and out of the fields in the menusand forms that users interact with. A more complex AJAX program mighthandle a REST-style interaction or a Web Service invocation. JavaScript Object Notation (JSON) is another popular supported data formatfor AJAX.

Figure 10.2illustrates a simplified browser-based form for a money transferoperation. The form obtains account numbers from the user along withthe amount to be transferred. This data is sent to the server where theaccounts are updated and the resulting balances for the two accountsare returned to the browser. While this exchange is taking place theuser does not leave the form.

Figure 10.2. Simple Web Browser Form. Theleft boxes are labels. The user types the customer ID, transferaccounts, and transfer amount as input and receives the updated accountbalances in the shaded boxes as output.


Figure 10.3shows an AJAX program snippet that works for both Microsoft’s InternetExplorer and other browsers. Internet Explorer implements AJAX using anActiveX control (XMLHTTP), which is a mechanism specific to Windows, whereas other browsers typically use the standardXMLHttpRequestclass. AJAX support also is included in the .NET Framework ActiveServer Pages (ASP) .NET library, including integration between AJAX andserver-side ASP.NET.

Figure 10.3. Sample AJAX Program for Browser-Based Funds Transfer Operation. TheAJAX program is divided between its related JavaScript and HTMLelements. After it detects the user input, it obtains the changedinformation from the form, sends it asynchronously to the web server,and then displays the results.
Code View: Scroll / Show All


Transfer


























In either case, theXMLHttpRequestclass interacts with the web server asynchronously. It provides methodsfor exchanging data in various formats with the web server, includingSOAP, XML, and JSON. Since AJAX is also a popular technology fordeveloping Web Service clients, an AJAX library is available forgenerating and handling Web Services, calledws.js.Apache CXF provides an option for generating client-side JavaScriptfrom a server-side Web Service definition. In ASP.NET, an AJAX scriptcan be used to call either an ASP.NET Web Service (.asmx) or a WindowsCommunication Foundation (WCF)-based Web Service (.svc).

Typically, an HTTPGET operation is performed first to display an HTML form. The modified fields are sent to the server as XML elements in an HTTPPOST operation, returned in the response message, and displayed on the form. In the example aPOSToperation sends the URL of the server along with the data from the form(in this case to and from account numbers and the transfer amount). Thetrue parameter in the open method indicates that the HTTP operation is to be performed asynchronously. Theonreadystatechange method is used to detect a state change in the data and trigger the data exchange with the server.

Likeany other front-end program, the AJAX script creates a request to run atransaction. The subsequent control flow depends on whether theapplication uses one resource manager, many resource managers, ormultiple tiers. Some applications simply connect the web tier to thedatabase tier, so no independent transaction manager is needed. Othersintroduce tiers in between, some of which may need to controltransactions. Still others may introduce a business process layer,which also controls transactions. Each of these back-end designsrequires transactional middleware functionality to glue it together.This can be implemented using the .NET Framework and/or Java-EE-basedtransactional middleware products, which are the subjects of the nexttwo sections.