Service Oriented Architecture with Java - CA Binildas - E-Book

Service Oriented Architecture with Java E-Book

CA Binildas

0,0
20,53 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

In Detail

Service Oriented Architecture provides a way for applications to work together over the Internet. Usually, SOA applications are exposed through web services.

Web services have been around for a while, but complex adoption processes and poor standardization hampered their use at first. However, with the adoption of new, simpler protocols such as REST, and major companies supporting SOA, the time is now right to adopt these standards.

This book will show you how to build SOA, web services-based applications using Java. You will find out when SOA is the best choice for your application, how to design a sound architecture, and then implement your design using Java.

The book covers the important web services protocols: XML-over-HTTP, REST, and SOAP. You will learn how to develop web services at all levels of complexity and for all kinds of business situations.

This book shows how to use SOA and web services to build powerful applications in Java. It teaches the concepts and the implementation with best-practice real-world examples. You will learn to design a sound architecture for successful implementation of any business solution, the different types of architecture, and various tenets of SOA. The book explains the fundamentals and the advantages of using the Service Oriented Architecture in designing your business solution.

Approach

This book is an overview of how to implement SOA using Java with the help of real-world examples. It briefly introduces the theory behind SOA and all the case studies are described from scratch.

Who this book is for

This book is for Java programmers or architects who are interested in implementing SOA concepts in their applications. Readers should be familiar with Java Enterprise concepts.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 198

Veröffentlichungsjahr: 2008

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Service Oriented Architecture with Java
Credits
About the Authors
About the Reviewer
Preface
What This Book Covers
Conventions
Reader Feedback
Customer Support
Downloading the Example Code for the Book
Errata
Questions
1. The Mantra of SOA
Architecture
Application Architecture
Client-Server Architecture
1-Tier Application
2-Tier Application
3-Tier Application
N-Tier application
Enterprise Computing or Architecture
Business
Application
Information
Technical
The Design
Security
Administration
EA for Managers
EA for Developers
Analogy of SOA
Web Services for SOA
'Orientation' of Web Services
History of SOA
The SOA Bandwagon
Why SOA?
How SOA...
Service
Messaging
Nodes
RPC Style
Message Path
Summary
2. Web Services and SOA
The SOA Approach
XML — Advantages and Disadvantages
XML Pitfalls
Listing 1 — Stateful Approach
Listing 2 — Stateless Approach
Introduction to Web Services, RESTful Services, and Other Transport with XML
Basic SOA With XML Over HTTP Protocol
Create
Read
Update
Delete
Generic CRUD Action
Non-CRUD Action
Web Service Decoupling
A Basic Java Implementation of POX-over-HTTP
Listing 3 — XML Binding Annotations
Listing 4 — ItemCrudService Server Implementation
Listing 5 — ItemCrudService Client Request
Listing 6 — findAllItems Service Implementation
Listing 7 — ItemList Binding
Listing 8 — findAllItems Service Client Request
REST — Exploiting the HTTP Protocol
Listing 9 — Outcome Binding
Listing 10 — REST CREATE Server Implementation
Listing 11 — REST CREATE Client Request
Listing 12 — servlet Mapping Section in web.xml
Listing 13 — REST READ Service Implementation
SOAP
Listing 14 — JAX-WS Annotations
Listing 15 — JAX-WS Sample Client
RPC and Document Based-WS: How to Communicate, Pros and Cons of the Two Approach
Listing 16 — SOAP XML Request
Listing 17 — SOAP XML Response
RPC / Literal
Listing 18 — SOAP RPC Style
Listing 19 — SOAP RPC Request
Listing 20 — SOAP RPC WSDL
Listing 21 — SOAP RPC XSD
Document / Literal
Listing 22 — SOAP Document style
Listing 23 — Request Wrapper
Listing 24 — Web Service Using the Defined Wrapper
Listing 25 — SOAP Document Client Request
Listing 26 — SOAP Document XML Request
Listing 27 — SOAP Document WSDL
Listing 28 — SOAP Document XSD
Document / Literal Wrapped
Listing 29 — SOAP Document Wrapped Style
Listing 30 — SOAP Document Wrapped Web Service
Listing 31 — SOAP Document Wrapped XML Request
Why We Should Use Doc-WS?
The RPC Inheritance
The Document-Oriented Way
Document Style
Self-Containing Documents and Asynchronous Models
Validating Capabilities
Loose Coupling
Interoperability
Implementations: JAX-WS 2, Axis2, Spring-WS, and XFire/CXF 2.0
JAX-WS 2
Axis 2
Spring-WS
XFire / CXF
Summary
3. Web Service Implementations
Web Service Using JAX-WS 2.0
JAX-WS 2.0 — A Primer
Web Service Implementation in Java SE 6
Code Server and Client
IHello.java
HelloImpl.java
HelloServer.java
HelloClient.java
Run the Server and Client
Web Service Implementation in Java EE Server
Install and Start the Server
Code Server and Client
HelloWebService.java
Client.java
Run the Server and Client
Web Service Using Apache Axis
Contract-First versus Contract-Last
Web Service Implementation in Axis
Code Server and Client
IHelloWeb.java
HelloWebService.java
build.xml
RpcClient.java
CallClient.java
Run the Server and Client
Web Service Using Spring
Spring-WS — A Primer
Web Service Implementation in Spring
Code Server and Client
IHello.java
IHelloWeb.java
HelloWebService.java
Hello.java
applicationContext.xml
web.xml
Client.java
ClientObject.java
applicationContextClient.xml
Run the Server and Client
Web Service Using XFire
Web Service Implementation in XFire
Code Server and Client
IHello.java
HelloServiceImpl
web.xml
services.xml
Run the Server and Client
Summary
4. Data and Services — All Roads Lead to Enterprise Service Bus
JDO
Why JDO?
JPOX — Java Persistent Objects
JDO Sample Using JPOX
BDOM for the Sample
Code BDOM Entities for JDO
OrderList.java
LineItem.java
package.jdo
jpox.PROPERTIES
Main.java
Build and Run the JDO Sample
Data Services
Service Data Objects
Why SDO?
SDO Architecture
Apache Tuscany SDO
SDO Sample Using Tuscany SDO
Code the Sample Artifacts
hr.xsd
hr.xml
ReadEmployees.java
CreateEmployees.java
Build and Run the SDO Sample
Service Component Architecture
What is SCA?
Apache Tuscany SCA Java
SCA Sample Using Tuscany SCA Java
Code the Sample Artifacts
Code Fine-Grained Service Components
FlightServiceComponent
HotelServiceComponent
CabServiceComponent
Code BookingAgent Service Component
Code BookingAgent Client
Build and Run the SCA Sample
Message-Oriented Middleware
What is MOM?
Benefits of Using MOM
Enterprise Service Bus
EAI and ESB
Java Business Integration
OpenESB
Summary
5. Traditional Integration Technology
Case Study #1 — Based on EAI
Customer Information
Business Need
Solution
Hub and Spoke Architecture
Step One — Identifying Applications (Spokes)
Step Two — Messaging Hub
Step Three — Identifying Adapter
Goals Achieved
Goal #1 — Integration between Internal Business Processes and Business Partners
Goal #2 — Avoid Duplicity
Goal #3 — Achieve Re-Usability, Flexibility, and Scalability
Goal #4 — Platform Independence
Goal #5 — Setting up Messaging Exchange
Goal #6 — Less Manual Intervention
Goal #7 — Cost Effective
EAI Drawbacks
Proprietary Architecture
Messaging Bottlenecks
Tight Coupling
Non-Flexible Architecture
Manpower
SOA to Rescue
Case Study #2 — Based on SOA
Step One — Defining Organization Assets
Step Two — Generate Services
Information is eXtensible
Information Represented in Textual Form
Information is Structured
Platform Independency
Step Three — Model
Co-relation of Events
Co-relation of Services and Information
Step Four — Integrate
ESB — Enterprise Service Bus
Goals Achieved
Goal #1 — Proprietary Architecture
Goal #2 — Eliminating Messaging Bottlenecks
Goal #3 — Loose Coupling of Applications
Goal #4 — Flexible Architecture
Goal #5 — Return On Investment (ROI)
Summary
6. Goals We Can Achieve with SOA
Loose Coupling
Reusability
Seamless Integration
Return on Investment (ROI)
Summary
Index

Service Oriented Architecture with Java

Binildas A. Christudas

Malhar Barai

Vincenzo Caselli

Service Oriented Architecture with Java

Copyright © 2008 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: June 2008

Production Reference: 1180608

Published by Packt Publishing Ltd.

32 Lincoln Road

Olton

Birmingham, B27 6PA, UK.

ISBN 978-1-847193-21-6

www.packtpub.com

Cover Image by Nik Lawrence (<[email protected]>)

Credits

Authors

Binildas CA

Malhar Barai

Vincenzo Caselli

Reviewer

Shyam Sankar S

Acquisition Editor

Bansari Barot

Technical Editor

Dhiraj Chandiramani

Editorial Team Leader

Akshara Aware

Project Manager

Abhijeet Deobhakta

Project Coordinator

Abhijeet Deobhakta

Indexer

Monica Ajmera

Proofreader

Petula Wright

Production Coordinator

Shantanu Zagade

Cover Work

Shantanu Zagade

About the Authors

Malhar Barai is a senior systems analyst with Satyam Computer Services Ltd., one of India's leading IT services organizations. He has more than seven years of experience in the industry working for leading organizations across India.

Malhar has interest in service-oriented technologies and application integration tools. He has worked on EAI toolset of webMethods and Cast Iron, Java technologies.

You can catch him on various forums that deal with SOA and some of the webMethods forums, or you can read about him on his blog http://malharbarai.blogspot.com

He gets spurred by the daily challenges at work, finding solutions to the problems, and trying his hand at improving processes and solutions.

I would like to acknowledge and dedicate this book to my parents for being sources of inspiration and for guiding me on the right path when it mattered the most. To Jalpa, my lovely wife for, being a constant support and carving out a wonderful life for us. My ex-manager Ajay Mulkalwar for his guidance and encouragement, and the most important person — my soul, my sweet daughter Preisha whose lovely smile makes my time wonderful...

Vincenzo Caselli graduated with a degree in electrical engineering in 1991 from the University of Bologna. He has worked as an independent consultant and a Java trainer for several Italian software houses since 1996. He began working as a developer in Delphi and other visual IDE's with AS/400-based companies. Soon he shifted his focus on Java and began to propose Swing client/server multi-layered solutions to his customers. He also worked in the web development area with several frameworks (Struts, Hibernate, Spring, JSF, and GWT) in different fields (banking, manufacturing, healthcare, e-learning). Recently, he collaborated with IBM in projects based on Eclipse RCP and SOA. He is interested in consultancy and training activities aimed to improve the productivity and quality of the software development process by using open-source products.

I would like to thank my wife Silvia and my daughter Linda for being patient while I worked on this book. I also want to thank my friend Luca Masini for his precious technical advice and help.

Binildas C. A. provides Technical Architecture consultancy for IT solutions. He has more than 13 years of IT experience, mostly in Microsoft and Sun technologies. Distributed Computing and Service Oriented Integration are his mainstream skills, with extensive hands-on experience in Java and C#.NET programming. Binil holds a Bachelor of Technology degree in mechanical engineering from the College of Engineering, Trivandrum (www.cet.ac.in) and an MBA in systems management from Institute of Management, Kerala (www.imk.ac.in). A well-known and a highly sought-after thought leader, Binil has designed and built many highly scalable middle-tier and integration solutions for several top-notch clients including Fortune 500 companies. He has been previously employed by multiple IT consulting firms including IBS Software Services (www.ibsplc.com) and Tata Consultancy Services (www.tcs.com), and he currently works for Infosys Technologies (www.infosys.com) as a Principal Architect where he heads the J2EE Architects group servicing Communications Service Provider clients.

Binil is a Sun Certified Programmer (SCJP), Developer (SCJD), Business Component Developer (SCBCD) and Enterprise Architect (SCEA), Microsoft Certified Professional (MCP), and Open Group (TOGAF8) Certified Enterprise Architecture Practitioner. He is also a Licensed Zapthink Architect (LZA) in SOA. Besides Technical Architecture, Binil also practices Enterprise Architecture.

When not in software, Binil spends time with wife Sowmya and daughter Ann in 'God's Own Country', Kerala (www. en.wikipedia.org/wiki/Kerala). Binil is a long distance runner and is a national medalist in power lifting. You may contact Binil at <[email protected]> or <[email protected]>.

About the Reviewer

Shyam Sankar S is currently working as a Technical Architect with Allianz Cornhill Information Services, Trivandrum. He has around 11 years of experience in the IT industry and has worked in companies like IBS, Verizon, and Infosys. He has been working on Java technologies since 1999 and has been the lead architect for many JEE systems. Shyam, an Industrial Engineer from the University of Kerala, is also a Sun Certified Enterprise Architect and a Sun Certified Java Developer.

Preface

Service Oriented Architecture is mainly a mindset, an enterprise strategy whose natural implementation is represented by web services. SOA is not a single product or single reference architecture to be followed, but SOA is all about best practices, reference architectures, processes, toolsets, and frameworks, along with many other things which will help you and your organization to increase the responsiveness and agility of your enterprise architecture. Standards and frameworks play a greater role in enabling easy and widespread industry adoption of SOA.

This book will help you learn the importance of designing a sound architecture for successful implementation of any business solution, different types of C/S architecture, and various tenets of SOA, explaining the fundamentals and explaining the advantage of using the Service Oriented Architecture in designing of the business solution. From a basic XML-over-HTTP approach to the REST and SOAP protocols, we get into the details of how web services can be implemented with various degrees of complexity and flexibility using JAVA.

This book will explain the concepts of business layer that is 'The SOA core'. You will also learn when SOA will define as an asset to your project with the help of practical examples.

In the early years when the WS-approach began to emerge it suffered from difficulties due to many factors, for instance, complex adoption process and poor standardization. Now, with little effort times are mature for using this technology and also getting great advantages, both immediate and as an investment for our future works. The book concludes with the focus on explanation of these assets.

What This Book Covers

In Chapter 1 we will discuss the role of Architecture for successful implementation of any business solution followed by brief discussion on different types of client-server architecture and SOA.

In Chapter 2 we will examine the relationship between the SOA methodology and the web service implementation basics. We will also discuss how XML can be used as the common language to decouple the communication between web service implementations and their consumer clients.

In Chapter 3 we will introduce major web service implementations available specifically in the Java and J2EE world, WS using JAX-WS 2.0, WS using Apache Axis, WS using Spring, and WS using XFire.

In Chapter 4 we shall see few emerging standards like SDO and SCA, addressing from data integration to service and component integration.

In Chapter 5 we will look into a couple of case studies where one of the solutions is based on principles of Enterprise Application Integration and in the second one we shall build our solution based on SOA fundamentals.

In Chapter 6 we will explore in detail the advantages that the SOA approach can lead to. Basically a concluding chapter discussing what we can and what we have achieved with SOA approach.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

There are three styles for code. Code words in text are shown as follows: "On the other hand, having a filled item into the response is meaningful just for the findById method."

A block of code will be set as follows:

public interface IHello{ String sayHello (String name); }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

@XmlRootElement(name="ItemAction") public class ItemAction{ private String method; private Item item; ... @XmlRootElement(name="ItemActionResponse") public class ItemActionResponse { private String retCode private Item item; ...

New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "clicking the Next button moves you to the next screen".

Note

Important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader Feedback

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us so that we may develop titles that you get the most out of.

To send us general feedback, simply drop an email to <[email protected]>, making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email <[email protected]>.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer Support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the Example Code for the Book

Visit http://www.packtpub.com/files/code/3216_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books — maybe a mistake in text or code — we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata are added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Questions

You can contact us at <[email protected]> if you are having a problem with some aspect of the book, and we will do our best to address it.

Chapter 1. The Mantra of SOA

Today, we are living in a world, where 'the age of information technology' is erasing the boundaries of cities, states, and countries. This age is all about M and A's and key to the success of such partnerships would depend on how well current independent resources of each of these entities is re-used. But the biggest challenge would be aligning these independent solutions into components that can be re-used across the enterprise.

The answer lies in "architecting" a design that would take care of inter-enterprise communication in a scalable form. But before getting into that, let's first try to understand the term 'architecture' in the broader sense. This is one of the most under-valued but the most important building block for any solution.

Architecture

"Architecture" is a Holy Grail for any design solution. It shows the major components of the software solution and serves as a blueprint for the entire design. It is like a core to the design of complex software solution.

It can be defined as a representation group(s) of relationship between various components of a complex software solution. The solution is decomposed into smaller, self-describing components and represented as structural relationships to provide a high-level overview of the entire system. The system is divided into runtime elements, which in itself could have architecture as well.

Shown here is a typical architecture for a database driven, web-based solution. It provides us with a high-level overview of the entire system. The consumer only has a view of the 'presentation layer' and other layers are tightly encapsulated. Each layer would have its own characteristics as well as its own architecture.

Architecture can be compounded as a logical set of decisions to describe the life of the project. These decisions will have a cascading affect on the selection and integration of components such as the selection of software, hardware, and behavior of the system. A good architecture will also take care of the future needs of the project.

But then, why is architecture so important? Without proper architecture in place, it would be difficult to achieve the following:

Achieve our designed goalDecompose our requirements into smaller entitiesQuality solutionsChange managementRe-usable or extendable solutionsAchieve business goals

Moving on from architecture, we will now dive into different architecture paradigms.

Application Architecture

At the most granular level in a system, you will always find sets of applications running to achieve some business goals. These applications are developed using different kinds of blueprints that we refer to as architecture. They provide an abstract view of the entire application, or let us say a high-level overview of the system.

Application architecture can be considered as a representation of the structure of components and the interaction between them in the system. They provide a framework within which the business objectives are represented.

The previous figure shows a typical architecture of a web-based application. The business requirements are converted into a high-level design where the:

First layer of 'HTML or JSP' acts as the presentation layer.The business logic is encapsulated in the middle layer that could be built on Servlets or EJB.Finally, the data is handled in the third layer 'MySQL'

Each organization will have multiple application architectures, which would cater to the need of different business goals. These applications could be web based, or even the custom client server applications.

Client-Server Architecture

The client-server architecture also known as two-tier architecture separates the client from the server. Client is the system requesting a service from the provider (in our case, server). The client will always initiate the request, which the server processes and responds to. The client could send the request to one or more than one server at a time.

Using this architecture, you can divide the responsibilities of the requester from the provider. Earlier, as seen in monolithic systems, objectives were divided into smaller pieces, and then tightly coupled into an application. Due to this, it was difficult to process multiple clients. But, with the client-server architecture in place, business process is done within the provider. This enables multiple clients to be plugged in at the same time.

Large organizations usually have more than one application to support their business goals. These are well supported by mainframes. Mainframes act as the core business-processing unit with capacity to handle large chunks of data transactions. Other computers in the organizations access the mainframe to achieve the business goals. So in a way, the mainframes act as a server, and cater to different clients across the organization. With the advent of monolithic computing, where applications were tied to the data sources, the client-server architecture had become a welcome sign for the industry.

The main advantage of the client-server architecture is that it is scalable. With minimal performance impact, either the client or the server could be added.

Client-server architecture can be divided further into 1, 2, 3....n-tier architecture. We will glance through each of these. The architecture is made up of three basic layers — the presentation layer, the business layer, and the database or services layer.

Presentation layer is the one with which the client will interact. The consumer shall either move through a click-based solution, or will input data into the front-end to initiate the business process.

This layer could either be a thin or a fat client.

Business layer will enumerate the consumer action(s) and process the information supplied by the 'presentation layer' to accomplish a business goal with a set of business rules.

Data layer stores the data and logic that would be used to successfully achieve business goals.

1-Tier Application

The single tier application would have the three layers, that is, the presentation, the business, and the data layer tightly coupled which runs out of a single processing unit. The application is designed in a way that the interaction between the layers is interwoven.

Within the tenets of client-server architecture, the single tier application can share the data layer in a multi-user environment and achieve the client-server capabilities. The limitations of 1-tier application in client-server architecture are as follows:

Changes to the database, in case it is being edited by multiple usersDifficulty in scalability, as the application is running on a single machine.

2-Tier Application

Within the 2-tier application, the presentation and the business layer combine on the client side, while the data layer acts as the server. This enables the business logic to be separated from the data services.

The 2-tier application would generally consist of a 'fat' client and a 'thin' server - 'fat' client because it will embed the presentation as well as the business logic of the application, and a 'thin' server, as it will only cater to the data needs of the client.

Another flavor of the 2-tier application can be a 'thin' client and a 'fat' server. This would have the presentation logic served in the 'client'. The business logic and data logic reside on the 'server'.