Simon Laws Mark Combellack Raymond Feng Haleh Mahbod Simon Nash
Total Page:16
File Type:pdf, Size:1020Kb
SAMPLE CHAPTER Simon Laws Mark Combellack Raymond Feng Haleh Mahbod Simon Nash MANNING Tuscany SCA in Action by Simon Laws, Mark Combellack, Raymond Feng, Haleh Mahbod and Simon Nash Chapter 1 Copyright 2011 Manning Publications brief contents PART 1UNDERSTANDING TUSCANY AND SCA............................ 1 1 ■ Introducing Tuscany and SCA 3 2 ■ Using SCA components 33 3 ■ SCA composite applications 71 PART 2USING TUSCANY....................................................... 107 4 ■ Service interaction patterns 109 5 ■ Implementing components using the Java language 132 6 ■ Implementing components using other technologies 175 7 ■ Connecting components using bindings 197 8 ■ Web clients and Web 2.0 232 9 ■ Data representation and transformation 257 10 ■ Defining and applying policy 284 PART 3DEPLOYING TUSCANY APPLICATIONS ........................ 309 11 ■ Running and embedding Tuscany 311 12 ■ A complete SCA application 329 PART 4EXPLORING THE TUSCANY RUNTIME ........................ 355 13 ■ Tuscany runtime architecture 357 14 ■ Extending Tuscany 382 Part 1 Understanding Tuscany and SCA Tuscany SCA In Action teaches you to use the Service Component Architec- ture (SCA) through practical examples developed using the Java SCA runtime from the Apache Tuscany open source project. This part of the book provides a broad introduction to SCA and Apache Tuscany using a travel-booking scenario. It presents an overview of Apache Tuscany and helps you to set up your environ- ment so that you can develop and run the examples in this book. This is all cov- ered in three chapters. In chapter 1, “Introducing Tuscany and SCA,” you’ll learn about the Apache Tuscany open source project and the travel-booking scenario and be introduced to SCA at a high level. By the end of this chapter, you’ll have an appreciation of SCA and will be able to run a small part of our travel-booking application. Chapter 2, “Using SCA components,” covers SCA in greater detail. You’ll gain a better understanding of SCA and use it to create more of the components that compose the travel-booking application. Chapter 3, “SCA composite applications,” covers the deployment of SCA- based applications. Here, you’ll learn about the flexible deployment model that Tuscany SCA offers and experiment with deploying the travel application in a local or distributed environment. By the end of part 1, you’ll know about Tuscany and SCA and will have built and deployed a simple travel application. Introducing Tuscany and SCA This chapter covers ■ Exploring SCA and Tuscany ■ Learning basic SCA concepts ■ Developing your first SCA application Businesses are always looking for ways to lower the cost of creating and maintaining business applications. One popular approach to business application development, often called Service Oriented Architecture (SOA), is to adopt a model where busi- ness functions are described as well-defined services that can be used to compose working applications. SOA is an attractive idea, but putting it into practice can be difficult. Business computing environments typically contain many different technologies, and the integration of these technologies can be complex. In a single application you can be joining Java objects, Business Process Execution Language (BPEL) processes, browser-based clients, and Ruby scripts using web services, as well as Java Message Service (JMS) and JSON-RPC protocols, to name but a few. 3 4 CHAPTER 1 Introducing Tuscany and SCA What’s needed is a common way to describe an assembly of distributed services regardless of the technology used to implement and connect them. Step forward the Service Component Architecture (SCA) and the Apache Tuscany project. Apache Tuscany is an open source project developed by the Apache Software Foundation. The Tuscany software is freely available from the project website (http:// tuscany.apache.org) under the Apache 2.0 License. The software is a lightweight infra- structure that implements Service Component Architecture (SCA), Service Data Objects (SDO), and Data Access Service (DAS) technologies and provides seamless integration with many other technologies. This book is about Tuscany’s Java imple- mentation of SCA, which is what we mean when we use the term Tuscany SCA. The SCA specifications are the foundation upon which Tuscany SCA is built. The first version of SCA specifications (v1.0) was developed by a consortium of companies called the Open Service Oriented Architecture (OSOA) collaboration. The specifica- tions are published via the collaboration’s website (http://www.osoa.org). These are the specifications that the Tuscany Java SCA v1.x runtime and this book use. OSOA and OASIS versions of the SCA specifications Following the release of the SCA v1.0 specifications from OSOA, the SCA specifications were donated to the OASIS Open Composite Services Architecture (CSA) Member Sec- tion (http://www.oasis-opencsa.org/). Work is ongoing at OASIS to standardize v1.1 of the SCA specifications. The Tuscany 1.x runtime and this book are based on the completed v1.0 specifications from OSOA. Appendix B covers the direction that Tus- cany 2.x is taking beyond what’s available in Tuscany 1.x. The fundamentals of what you learn about SCA in this book apply to both versions. SCA provides a technology-neutral assembly capability for composing applications from business services. The services themselves can be developed and connected using many different technologies. If you look at the Tuscany project website, you’ll find subprojects providing Java language and C++ (also known as native) implementa- tions of SCA. You’ll also find Java language and native implementations of SDO and DAS, which provide ways of handling and persisting data. SDO and DAS aren’t prereq- uisites for using SCA. Although this book concentrates on Tuscany’s Java SCA runtime, in chapter 9 we do use SDO when building SCA service interfaces. If you want to know more about SDO, DAS, or the native runtimes, then the Apache Tuscany website (http://tuscany.apache.org) is a good place to start. We’ll start this chapter by taking our first high-level look at SCA and Tuscany. Then we’ll look at how an example travel-booking application can be described using SCA. This exercise sets the scene for building and running your first SCA application in sec- tion 1.3. There are already many SOA-related technology choices out there. In the last sec- tion of this chapter we look at how Tuscany and SCA are able to integrate with and complement other popular SOA technologies. The big picture 5 The samples used in this chapter, and in the rest of this book, can be downloaded following the instructions in appendix A. The source code for the samples is available in the Tuscany project, and the samples are accompanied by a README file that describes the structure and the operation of the samples. In this chapter you’ll gain a high-level understanding of the Tuscany software and the advantages of SCA, and you’ll build your first composite application. This will get you ready to dive into the rest of the book and explore what else Tuscany SCA has to offer. 1.1 The big picture SCA uses a range of terms, some of which will sound familiar and others that are new. It’s important to appreciate what SCA means when it talks about such things as compo- nents, services, references, and composites. These terms will be used repeatedly throughout the book, so we’ll start here by giving a high-level introduction of what it means to assemble applications from SCA components and what the various parts of the resulting assembly are called. Assembly is at the core of SCA, so much so that the central SCA specification con- centrates on defining what’s called the Assembly Model. The SCA Assembly Model defines an XML language for assembling components into applications and provides the framework into which extensions are plugged to support the wide variety of imple- mentation and communication technologies that are available today. In the next sec- tions, we’ll first provide an overview of the SCA Assembly Model and then give a quick summary of how Tuscany is architected to support SCA. This will provide sufficient background for understanding the details throughout the rest of the book. 1.1.1 The basics of SCA SOA promotes the benefits of constructing large and complex enterprise systems out of well-defined and sometimes replaceable component parts called component services. SCA describes an Assembly Model for doing just that. An SCA service provides a reusable piece of business function and has a well- defined interface that identifies how it can be called to provide that function. An application broken down into a set of well-defined services significantly reduces the complexity of development as well as its long-term maintenance by isolating change and simplifying testing. The challenge then becomes how to assemble the cooperat- ing network of services to provide maximum flexibility and reuse while maintaining the integrity of each service. Figure 1.1 shows a web shopping application that uses a set of connected services to allow the user to browse a catalog, add items to a shopping cart, and then pay for the items at checkout time. Figure 1.1 demonstrates that the web shopping example is made up of services that are developed in various technologies and communicate using different protocols. This mix of technologies is typical of today’s applications. The danger with the usual approach to application development is that technology integration logic can often become intermingled with business logic. For example, we may call remote web services by using a web service provider API directly from business 6 CHAPTER 1 Introducing Tuscany and SCA Figure 1.1 A web shopping application built from cooperating services showing the typical variety of technologies use to implement and connect services logic.