Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 464 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
464
Dung lượng
1,59 MB
Nội dung
26.1 System Architecture Most distributed architectures discuss three tiers in the development of Web-based applications, but the Web Server tier should really be thought of as a separate layer In fact, as we move closer and closer to Web services this layer might be replaced altogether Therefore, the layers modeled for the CRSS are: Client tier Web Server tier Application tier Database tier Let's look at each tier and the technologies used today The Client tier typically consists of HTML and JavaScript for computers and Wireless Markup Language (WML) for PDAs It is possible to embed many other controls (Shockwave, applets, ActiveX), but we will exclude these plug-in technologies from our application The simplest way to model the application is to start with highlevel architectural diagrams and then model the tiers one at a time The architecture shown in Figure 26.1 has been used in many applications for quite a few years now In fact, the success of this architecture has accelerated the acceptance and emergence of XML standards Figure 26.1 n-Tier architecture You might wonder why XML Schema and the other XML concepts should be introduced to the mix illustrated in Figure 26.1 We certainly have enough acronyms without introducing all the X-based ones You should not start to use all these X technologies without a good justification Properly justifying the use of XML-based technologies will seem simple if you have already been dealing with some of the following issues: HTML browsers do not comply with rigid standards This might not be a stunning revelation to any Web developer who has been up all night sorting out a Netscape versus Internet Explorer issue Use XML with XSLT to produce wellformed HTML—or better yet, XHTML The Web Server tier in Figure 26.1 has many competing technologies Learning all of them is difficult They are all trying to do the same thing: accept user inputs as HTTP messages and format the output results as HTML or WML Many applications have misused the Web server layer and placed far too much validation and business logic in it Maintaining these projects is extremely difficult The technologies are simplified dramatically if you switch to XML-based technologies and use XML schemas to perform the validation The Component tier is certainly the most interesting You have the never-ending debate about Java versus anything else What is frequently lost in this debate is the real purpose of this tier, which is to provide business logic Business logic is based on data, and XML is tailor-made for manipulating data By using XML, you can simplify your components by passing XML nodes back and forth Each node can use an XML schema for its test case This eliminates the need to write software to test software—a classic Catch-22 If you ask Web developers how they test an application, they're likely to say they open Netscape and Internet Explorer and verify that the application works Could you imagine testing a new aircraft wing by installing it on a plane and taking it up for a flight? If it works once, will it work every time? Will it work with all revisions? Obviously, much better test methodology is required The Database tier is a moving target right now Both Microsoft and Oracle are rapidly adding XML capabilities to their databases These capabilities enable you to use XML messages to request database actions, eliminating all the formatting required in an Active Server Page/Active Data Object (ASP/ADO) solution or corresponding Java Server Page/Java Database Connectivity (JSP/JDBC) scenario Note Microsoft and Oracle are not the only vendors using XML in their database products IBM, Informix, Sybase, and others are adding similar capabilities Our Campus Resource and Schedule System (CRSS) case study uses XML as its foundation, which is illustrated in Figure 26.2 When comparing Figure 26.2 to Figure 26.1, the most striking difference is the reliance on XML across all the tiers Figure 26.2 n-Tier XML architecture As you can see from Figure 26.2, XML technologies do not replace HTML, JavaScript, NET, Java, or SQL XML simply is used by these technologies to increase their reliability and robustness In the model in Figure 26.2, XML schemas are used in two ways: Defining interfaces between different processes or tiers Validating data Figure 26.2 shows that the Web tier converts an incoming HTTP request into an XML message This message is validated against an XML schema Once you have valid user input, the message is sent to the Component tier where business logic is applied Database access is also accomplished with XML messages The challenge at the database interface is different than at the user interface You can ensure that your components are producing valid XML in the design of the components, but you need to map the data from an XML source to a relational database format and vice versa XML schemas can provide the hierarchical to relational mapping, as you will see a bit later Interfaces between all three tiers are simplified when using XML Testing at all interfaces is accomplished using XML schemas This ability to test the interfaces declaratively allows software projects to be worked on by teams more easily You will begin the CRSS application by modeling the Client tier to the Web Server tier You will model each requirement by using UML sequence diagrams Then you will convert each of these sequence diagrams into XML messages These messages define the workflow of the application Let's start by modeling the following requirement: View existing reservations on a per resource basis Obviously, user input will be required You need to support multiple devices, but let's start by assuming a browser interface As you will see later, implementing the support for any other Web-enabled device is easy The sequence diagram in Figure 26.3 models the first requirement Figure 26.3 View Resource Reservation sequence diagram You can see from the sequence diagram in Figure 26.3 that each tier is modeled by an interface There is a Web interface that can be implemented by using Active Server Pages (ASP), Java Server Pages (JSP), Common Gateway Interface (CGI), or any other Web-server-based framework The Web interface does not do any significant processing; its purpose is to support user interaction This is exactly what you intend Keep the code in ASP or JSP to an absolute minimum to increase the maintainability of your applications Simply applying an XML schema provides user-input validation The parser will throw any validation errors in the repackaged XML data You have enough information at this point to decide on the contents of the XML message The XML message used to request the resource calendar view is shown in Listing 26.1 Listing 26.1 XML Message to Get Resource Calendar As you can see, the preceding code is a simple XML message created in the Web Client tier You can use an XML schema to validate this message The schema provides the contract you have with the input device Using this model enables us to support Web-based clients or XML-enabled devices You can use schemas to open your service to the Internet by creating a Web service Note The ability to publish schemas on the Internet so your services can be made available to anyone is the basis for Web services Web Services Description Language (WSDL) uses XML schemas and has been submitted as a possible standard to the W3C WSDL uses XML schemas to describe your application interfaces and interface definitions You need to create the XML schema by using the XML message created in Listing 26.1 You have several ways you could go about creating the XML schema There are quite a few tools that do a reasonable job; however, no tool can know your business application requirements Most tools that automatically generate XML schemas produce something similar to the example in Listing 26.2, produced by XML Spy Listing 26.2 XML Schema for Resource Calendar Message Now you have a schema to validate your input message against You can test this schema by using a plug-in (http://msdn.microsoft.com/downloads) for Internet Explorer that lets you simply right-click on a file and select Validate You could also use any validating XML parser for this operation Before you can do any testing, however, you have to associate the XML source with its corresponding schema You can do that as shown in Listing 26.3 Listing 26.3 Schema Reference Added to Get Resource Calendar Message