ebook img

Apache CXF Web Service Development PDF

335 Pages·2009·3.097 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Apache CXF Web Service Development

Apache CXF Web Service Development Develop and deploy SOAP and RESTful Web Services Naveen Balani Rajeev Hathi BIRMINGHAM - MUMBAI This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 Apache CXF Web Service Development Copyright © 2009 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, nor Packt Publishing, and its dealers and 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 of 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: December 2009 Production Reference: 1111209 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847195-40-1 www.packtpub.com Cover Image by Vinayak Chittar ([email protected]) This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 Credits Authors Editorial Team Leader Naveen Balani Akshara Aware Rajeev Hathi Project Team Leader Priya Mukherji Reviewer Brett Porter Project Coordinator Ashwin Shetty Acquisition Editor Usha Iyer Proofreader Kevin McGowan Development Editor Reshma Sundaresan Graphics Nilesh R. Mohite Technical Editor Shadab N Khan Production Coordinator Adline Swetha Jesuthas Copy Editor Leonard D'silva Cover Work Adline Swetha Jesuthas Indexer Hemangini Bari This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 About the Authors Naveen Balani works as a Software Architect with IBM India Software Labs (ISL). He leads the design and development activities for WebSphere Business Services Fabric product out of ISL Mumbai. He has over nine years of industrial experience and has architected and implemented large scale enterprise solutions. Naveen Balani likes to research upcoming technologies and is a Master Author with IBM developerWorks having written over 60 plus publications, on topics such as Web services, ESB, JMS, SOA, architectures, open source frameworks, semantic Web, J2ME, pervasive computing, Spring, Ajax, and various IBM products. He started working with web services way back in 2001 and proposed the first MVC web services-based pattern (http://www.ibm.com/developerworks/library/ws-mvc/) in 2002. Naveen Balani's articles on Spring Series (http://www.ibm.com/developerworks/ web/library/wa-spring1/) were rated as the top articles in the last 10 years for developerWorks web architecture zone. He has co-authored books on Spring framework (http://www.wrox.com/WileyCDA/WroxTitle/Beginning-Spring- Framework-2.productCd-047010161X.html) and Multiple IBM Redbooks on WebSphere Business Services Fabric and BPM 6.2 Product deployments. You can reach him on his website—http://soaweb.co.in I would like to thank my wonderful wife, Sonia, for her love and patience and her endless support in spending many hours sitting beside me, reviewing my work and providing valuable inputs. I would also like to thank my parents for their support and encouragement in all my endeavors. And last but not least, to my good friend and co-author Rajeev Hathi. This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 Rajeev Hathi is a J2EE Consultant and Developer living in Mumbai, India. He grew up in a joint Hindu family and pursued his primary education in the field of Economics and Commerce. His hobbies are watching sports and listening to rock music. His favorite bands are Pink Floyd and Dire Straits. Rajeev has written several articles for IBM developerWorks portal. His major contributions are in the fields of Java, web service, and DB2. He developed an interest in computers after pursuing a diploma in Advanced Systems Management at NIIT (National Institute of Information Technology). Rajeev has been working on J2EE-based projects for more than ten years now. He has worked with several companies offering software services and conducted various knowledge sessions on Java and J2EE. He has attained several Java-based certifications such as SCJP, SCWCD, SCBCD, and SCEA. He, along with the co-author Naveen Balani, has initiated a portal http://soaweb.co.in which aims to provide online consulting on the subject of web services. A book is often the product of many hands. To start with I'd like to thank Usha Iyer, an Acquisition Editor with Packt Publishing, for having enough faith in my writing skills and abilities.. My special thanks to the Packt Publishing team in making enormous efforts to make this book a reality. A good book cannot be made better without a constructive review and feedback and the reviewers equally contributed to the whole writing process. I owe thanks to my wonderful and lovely friend, Sunita, who instilled in me enough confidence and zest to make my writing look effortless. I owe thanks and gratitude to my family members who have supported and encouraged my writing efforts day and night. And last but not least, without my co-author and amazing friend Naveen Balani, this project would not have been achievable. Finally, I would like to dedicate this book to my late parents and late sister. without their blessings, this project would have just remained a mere thought. This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 About the Reviewer Brett Porter is a software developer from Sydney, Australia, with a passion for development tooling, and automation. Seeking a more standardized and reproducible solution to organize, build, and deploy a number of software projects across teams, he discovered an early beta of Maven 1.0 in 2003, and has since been heavily involved in the development of the project. Brett is a Director and a Member of the Apache Software Foundation. He is a member of the Apache Maven Project Management Committee, and has conducted presentations and training on Maven and related tooling at several conferences and events. He founded the Archiva project in 2005. Brett is the co-author of Apache Maven 2: Effective Implementation, published by Packt Publishing in 2009. He was also the co-author of Better Builds with Maven, the first book to be written about the Maven 2.0 release in 2005, and has been involved in reviewing Maven: A Developer's Notebook and Java Power Tools. My thanks goes to everyone involved at the Apache Software Foundation, and all those that contribute to and use the software. You make projects such as CXF and the many others possible. I'd also like to thank my wife Laura and my young daughter Samantha, who could afford to spare me the extra hours to review this book, so soon after having written my own! This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 Table of Contents Preface 1 Chapter 1: Getting Familiar with CXF 7 Web service technology standards 8 XML 8 SOAP (Simple Object Access Protocol) 9 WSDL (Web Services Description language) 10 REST (Representational State Transfer) 12 Service Registry 13 Introducing web services 13 Approaches for web service development 14 Web service SOAP communication styles 15 Apache CXF 16 History of CXF 16 Why CXF? 17 Support for web service standards 17 Support for POJO (Plain Old Java Object) 18 Frontend programming APIs 18 Tools support 19 Support for RESTful services 19 Support for different transports and bindings 20 Support for non-XML binding 20 Ease of use 20 Flexible deployment 21 Setting up the environment 21 For ANT users 21 For Maven users 22 Summary 24 This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 Table of Contents Chapter 2: Developing a Web Service with CXF 25 The Order Processing Application 26 Developing a service 27 Creating a Service Endpoint Interface (SEI) 27 Developing a service implementation class 30 Spring-based server bean 31 Developing a client 32 Developing a Spring-based client bean 33 Developing web service client code 33 Running the program 36 Building the code 37 Deploying the code 38 Executing the code 38 CXF architecture 39 Bus 39 Frontend 41 JAX-WS 41 Simple frontend 43 Messaging and Interceptors 43 Service model 45 Data binding 46 Protocol binding 47 Transports 49 Summary 49 Chapter 3: Working with CXF Frontends 51 JAX-WS frontend 51 Code-first development 52 Creating Service Endpoint Interface (SEI) 53 Adding Java annotations 54 Publishing the service 59 Developing a consumer 60 Running the Code-first example 61 Contract-first development 62 Generating service components 64 Implementing the service method 73 Publishing the web service 73 Invoking the web service 74 Using dynamic client 74 Creating a simple dynamic client 74 Running the dynamic client 76 Using the CXF service model for building dynamic client 77 Running the dynamic client which uses Service Model API 80 [ ii ] This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 Table of Contents Provider and Dispatch services 81 Understanding messaging modes 82 Message mode 82 Payload mode 83 Understanding types of message objects 83 javax.xml.transform.Source 83 Implementing Provider service 85 Publishing the Provider service 88 Implementing the Dispatch service 89 Running the provider dispatch example 91 Web service context 93 Implementing Context in service 94 Running the web service context example 95 Simple frontend 96 Developing a simple frontend 96 Creating service implementation class and interface 97 Creating server implementation 97 Creating client 98 Running the simple frontend example 99 Summary 100 Chapter 4: Learning about Service Transports 101 Transport protocols in CXF 102 HTTP transport 102 SOAP over HTTP 103 HTTP only 105 HTTP Conduit 106 HTTP destination 107 HTTPs transport 108 Developing the service and implementation class 109 Generating crypto key 109 Creating client and server bean configuration 110 Configuring the server to support SSL 113 Developing the client component 113 Building and deploying 114 Configuring SSL for Jetty runtime 115 JMS transport 118 Developing the service and implementation class 119 Developing an embedded broker 119 Creating a server and client bean configuration 120 Developing a client component 122 Performing build and deployment 123 Local transport 126 Developing SEI and an implementation class 127 Developing a server 127 Creating client bean configuration 127 [ iii ] This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111 Table of Contents Developing a Client 128 Building and executing 129 Summary 130 Chapter 5: Implementing Advanced Features 131 Understanding CXF interceptors 131 Understanding interceptor phase and chain 132 Overview of the interceptor API 133 Interceptor interface 134 The PhaseInterceptor interface 134 The AbstractPhaseInterceptor class 135 Developing the custom interceptor 137 Developing the server side interceptor 138 Adding a server side interceptor to the Order Process service 141 Developing the client side interceptor 141 Adding a client side interceptor to the client code 144 Developing the standalone server for publishing the Order Process web service 145 Building and running the Order Process web service and interceptor 146 Building the code 147 Executing the code 148 Testing the custom interceptor for negative condition 149 Understanding CXF features 151 Applying the GZIP feature to the Order Process web service 152 Developing service and implementation class 152 Developing a server component 153 Creating the client bean configuration file 154 Creating a client component to consume the service 155 Building and executing the code 155 Understanding CXF Invoker 157 Overview of Invoker API 157 The Invoker interface 158 The AbstractInvoker class 158 Developing custom invoker 159 Summary 164 Chapter 6: Developing RESTful Services with CXF 165 Overview of REST and RESTful services 166 Java API for RESTful services 168 CXF JAX-RS implementation 170 Developing end-to-end RESTful services using CXF JAX-RS implementation 171 Developing the RESTful service 172 Creating Java data objects for Request and Response 172 [ iv ] This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December 2009 6393 south jamaica court, , englewood, , 80111

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.