In: Categories » » AJAX » Implementing an SOA Architecture
I touched on the topic of using a service-oriented architecture (SOA), Web services, and Ajax to build a client from a theoretical perspective, but I didn’t delve into the practical details of how to implement the SOA architecture. In this feast of a article, I cover how to implement an SOA architecture using Web services and Ajax. The solution also addresses the issue of how to upgrade an already existing architecture to an SOA architecture. This article covers the following topics:
• Designing Representational State Transfer (REST)–based URLs to content that is described as a set
• Creating a new SOA architecture without throwing out all of the original architecture
• Validating and testing aWeb service
• Picking apart the data
• Implementing a REST-based Web service
• HTML
• Really Simple Syndication (RSS)
• Atom Each of the formats is unique, but the content structure within the formats is the same. From a programming perspective, the solution would involve a Model-View-Controller The re-architected application has only one URL and one data format, Atom, so the code behind the URL needs to generate content just for that format. In the case of the re-architected application, the Atom format is considered aWeb service, the idea behind which is to present a universal format understood by a wide audience. And if the end device does not understand the format, then it is up to the browsing device to figure it out. Of course, asking the end device to figure out the format might sound harsh, but it isn’t really whenever you are generating HTML using the HTTP protocol, you are asking the end device to figure out how to display the data.
If HTML and HTTP are nearly universal, why not just generate well-structured HTML and let the Atom end device figure it out? The answer is that it doesn’t work quite as smoothly as that. HTML is a user interface technology that is not universally understood across all devices. An Atom end device could probably guesstimate the format structure, but you probably know the sweat and pain associated with writing HTML code that can display on all devices. With aWeb service based on the Atom format, you have a clear understanding of what the data is and represents. For a start, aWeb service says to the server, “Here’s the data figure out how to display it.” If the end device is an Atom reader, it’s easy to figure out what to do with the data, but if the end device is aWeb browser, you have a challenge. Most new browsers do understand Atom Web services, but another option is to have Ajax at hand to help and specifically the XMLHttpRequest object, which can generate a request to call the Web service. The Web service delivers the data, which is then processed by the XMLHttpRequest object, and because the vast majority of Web services are XML based, figuring out the format of the data delivered by the Web service is trivial. By delegating the work of creating a GUI away from the server, there is a clear separation between the roles the client and server play. This separation is absolutely critical, as it allows the server developers to focus on performance, scalability, robustness, and storage, while the client can focus on usability, visual aesthetics, and understandability. The designer and the programmer have two very different skill sets, and they should not interfere with each other.
Implementing the Server The example application is a blog whose architecture will be kept plain vanilla for ease of understanding. For the blog architecture, only database support is going to be required and discussed in any depth. The legacy portion of the blog example is not code; rather, it is data generated by the previous blog software. It is not beyond the realm of possibility to write a piece of software to convert the old data into a new format, but that act itself causes more problems than it solves. Let’s put the act of converting the data from one format to another into a bigger context. Imagine writing an application that serves as an incremental version of a working application. The chances of any corporation switching from one application to another with the flick of a switch is virtually zero. Thus, for a period of time, you will have two applications running and concurrently processing data. If during that period of time your data becomes inconsistent, you will have major problems reconciling the changes and you will potentially lose data this makes it not worth the effort. Returning to the blog architecture, you could implement one of two solutions. The first solution is to use the existing database; the second is to create an adapter using aWeb service. In the blog architecture, two Web applications run concurrently, and they access, process, and manipulate the same data. This does not mean that the two applications use the same physical database. With most modern databases, you have the ability to couple two database processes and synchronize the two physical databases. This has the advantage that data consistency is managed by the database. If you plan on writing synchronization software, ask yourself if you think you could do a better job than a database when it comes to managing consistency.
The modified architecture has two database processes, and the two processes are connected using the synchronization mechanism of the database. From the perspective of the user, developer, and administrator, each application uses its own database. The two database processes manage the exact same tables, views, and stored procedures. It is assumed that this new architecture will use the same tables, views, and stored procedures, but in reality this is not always the case because a new application typically involves the addition of tables, columns, and data. The solution to this issue is to use database encapsulation, which is possible with views and stored procedures. Database synchronization reduces the complexity to an absolute minimum. The reason for using database synchronization is to begin the process of separating two applications without losing data integrity. As the new architecture stands, the wp_authors and wp_users tables are the only dependencies of the original database. Thus, when a database synchronization is defined, only the wp_authors and wp_users tables are synchronized. Any other table used by the original blog architecture is not synchronized and thus does not affect the architecture of the new application.
The developer can go ahead and create his or her own database design without having to worry about corrupting the old database design. It goes without saying that the old database design is not modified, but this design does not stop the creation of stored procedures that could potentially corrupt the data in the original database design. To prevent or at least minimize the potential of data corruption, it is absolutely vital that the database design use constraints and validations. Most SQL databases allow the definition of constraints. Stepping back and looking at this architecture, you should notice that it relies on the capabilities of the relational database. There could be situations where a developer is not using a relational database. For those situations, I have no solution, as for the most part I have to deal with relational databases, and I am tempted to believe most readers have the same problem. Relying on the capabilities of the relational database requires that you understand the database. With the introduction of object-relational mapping (ORM) tools, the need to know SQL is reduced. For example, using ORM tools such as Hibernate does not require knowledge of views or stored procedures. ORM tools create “views” in the form of object hierarchies. Using an ORM tool allows you to implement the same architecture; however, it means that you will probably not be using stored procedures and views.
The real difference between using an ORM and the relational database stored procedure and view solution is the shifting of the coupling between the code and the persistence of the data. By contrast, the relational database layer uses views and stored procedures to interact with the data. The coder needs to know about the columns and types of the relational database and has to provide a mapping between his or her programming language and the SQL programming language. Using classical programming languages such Java and C# involves quite a bit of legwork in terms of preparing commands and retrieving data. Using a programming language such as Ruby, Python, or PHP, interacting with a relational database is trivial since the aforementioned languages do not have to declare the data types. Using an ORM, the coder washes his or her hands of the problem and puts the focus on the ORM layer.
For Java and C# programmers, an ORM removes the drudgery of interacting with a database, with the only cost being the programmers’ lack of control of the transactions and manipulations of the database although in most cases that lack of control is acceptable when weighed against the drudgery of writing the relational database code. The question is, which architecture should you use? Personally, I use whatever is easiest in the programming language I am developing in at the time. So when I am writing code in Java and C#, I tend to use ORMs, and when I’m writing Python code, I access the relational database directly. You need to ensure that the ORM layer does not dictate the design of the database, under any circumstances. The database design is determined by the database and the data being persisted, so it means you need to understand table, view, constraint, and trigger design. This could become tricky if the ORM dictates the database design, and it could result in an inefficient database as well. Remember that in any application, the slowest part will be the database. The database has to pore through millions of records, manage transactions, and send that data across a network. If you design an application to be efficient at the expense of database design, then there is no way you can magically speed up the performance of the database.
legal notice
Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.
Useful tools and features
If you like this article (tutorial), please link to it from your web page using the information above.
related articles
Given the recent interest in Ajax, you’d be forgiven for thinking it was a new technology. In fact, the XMLHttpRequest object has been around for years. In technical terms, asynchronous JavaScript interaction with the server is nothing new. All of the other elements of the Ajax model have also been around for quite some time: CSS, (X)HTML, and DOM Scripting. Yet in 2005, interest in this methodology soared. Could it really be that simply giving this approach a snappy name like Ajax was responsible for the sudde...
2. Understanding the Definition and Philosophy of Ajax
The focus of this article is to provide solutions to some common, general problems and questions that are bound to arise before or during development of Asynchronous JavaScript and XML (Ajax) and Representational State Transfer (REST) applications. These common questions are not always technical in nature, often leaning more toward theory or philosophy of development. The problem with these kinds of questions is that once you begin to think about them, you keep going in a circle and end up where you star...
3. Understanding the Definition and Philosophy of Web Services and SOA
Understanding the Definition and Philosophy of Web Services and SOA Wikipedia offers the following definition of Web services:4 The W3C defines aWeb service as a software system designed to support interoperable machine-to-machine interaction over a network. This definition encompasses many different systems, but in common usage the term refers to those services that use SOAPformatted XML envelopes and have their interfaces described by WSDL. For ex...
4. Understanding the Definition and Philosophy of REST
Understanding the Definition and Philosophy of REST REST is a controversial topic among Web service enthusiasts, because it’s considered to stand for the opposite of what Web services and SOA are trying to achieve. The problem with this thinking is that REST is not in contradiction with the abstract definition of SOA and Web services. REST is in contradiction with technologies such as SOAP, WSDL, and WS-* specifications. The following offers a quick definition of REST:...
5. The Easiest Way to Get Started with Ajax and REST
The Easiest Way to Get Started with Ajax and REST Problem You want to know the best way to get started with writing Ajax and REST. Solution When developing an Ajax and REST application, you must decide on the tools and frameworks you’ll use. The choice is simple: Use whatever you’re using today, and write some Ajax applications. You don’t need to change the tools you’re using today. Whether you’re using ASP.NET, JavaServer Pages (JSP), PHP, Ruby, or Python, you...
6. Testing a Dynamic Contract with Ajax
Coding the Contract Using Test-Driven Development Techniques Coding the contract using agile and test-driven development techniques requires writing a number of tests and implementing aMock URL layer. Problem You want to code the contract using these development techniques. Solution To demonstrate, let’s define a use case, implement the use case as a contract, write a test case(s) to implement the contract, implement the contract in the Mock URL, and finally...
7. Testing the Client Side Logic
Problem You want to effectively test your application’s client-side logic. Theory Testing GUI code tends not to be a productive task because of the complications that arise. The main complication is how to test the correctness of a user interface. Imagine a situation where clicking a button causes a table to be filled with data. Now imagine that when a check box is checked and the button is clicked again, a different table is filled with content. The fact that clicking the same button results in two ...
8. Understanding JavaScript and Types
Understanding JavaScript and Types Problem You want to work around the fact that JavaScript does not have types declared for its variables. Theory JavaScript code does not have any variables with a declared type. The lack of typed variables is apparent when you declare functions. That said, not having typed variable declarations does not mean JavaScript has no types or no type safety. Let’s start out with the simple declaration of a function, as illustrated by the following ex...
9. Coding Using Conventions and Not Configurations
Coding Using Conventions and Not Configurations Problem You want to make your JavaScript constructs more efficient by applying the Rails “convention over configuration” principle to them. Theory You may already be familiar with the programming platform Ruby on Rails, which is used to build Web applications. The focus of this recipe is not Ruby on Rails, but one aspect of Ruby on Rails namely, convention over configuration (see http://en.wikipedia.org/wiki/ Ruby_on_Rails for m...