You are previewing Apache CXF Web Service Development.
O'Reilly logo
Apache CXF Web Service Development

Book Description

Learn how to design and develop SOAP and RESTful web services using the Apache CXF framework. This course flattens the learning curve with practical examples to take you from novice to expert in easy steps.

About This Book

  • Design and develop web services using contract-first and code-first approaches

  • Publish web services using various CXF frontends such as JAX-WS and Simple frontend

  • Invoke services by configuring CXF transports

  • Create custom interceptors by implementing advanced features such as CXF Interceptors, CXF Invokers, and CXF Features

  • The first practical guide on Apache CXF with real-world examples

  • Who This Book Is For

    This book is for developers who want to design and develop SOAP and RESTful services using Apache CXF framework and leverage various CXF features for service development. It is ideal for developers who have some experience in Java application development as well as some basic knowledge of web services, but it covers some of the basic fundamentals of web services and REST to get you acquainted with these technologies before using these concepts to develop services using the CXF framework.

    What You Will Learn

  • Become familiar with the different features of Apache CXF architecture and set up the CXF environment

  • Develop a simple web service using CXF-based Spring configuration

  • Build a web service using contract-first and code-first approaches in simple frontend APIs such as JAX-WS

  • Create dynamic web service clients by using various CXF frontend APIs

  • Develop web services with different transports by configuring various CXF transports such as HTTP, HTTP(S), JMS, and CXF Local

  • Create RESTful services that support JSON and XML as the message formats

  • Develop services with features such as Interceptors by implementing advanced CXF features

  • Attain configuration and dependency management by integrating web services with the de facto Spring framework

  • Unit test POJO services in a stand-alone environment as well as promote applications to the Tomcat container for production ready deployments

  • Speed-start developing web services by using CXF tools effectively

  • Basics of Spring framework and IOC container for readers who are not acquainted with Spring framework

  • In Detail

    Apache CXF framework helps you to develop a standards-based programming model and also provides a flexible deployment model for deploying web services. Developing SOAP and RESTful applications can be made easy by using Apache CXF framework. However, getting started with developing web services using the Apache CXF framework is not easy.

    This is the first book that gives details on how to use the Apache CXF framework for developing SOAP and REST web services. It is a hands-on practical guide that simplifies working with CXF framework as it covers all major aspects with real-world examples. The chapters cover the various CXF features in detail and each has systematic steps with practical, simple examples to implement these features on your web services.

    The book introduces the Apache CXF framework and its features such as Frontend API, Data Bindings, Transports, Spring-based configuration, and CXF tools. It also has chapters on SOAP and RESTful services. It will help you create RESTful services that support XML as well as the widely accepted Java Script Object Notation (JSON) format. It explains the components of CXF architecture that help developers customize the Apache CXF framework to suit the target application. The book covers both code-first and contract-first approaches for service deployment. You will see how to develop services in a flexible deployment model offered by CXF, unit test them in a stand-alone environment, and finally promote them in an application server environment.

    The instructions in this book will help developers to build their application according their requirements by using any of the frontends supported by Apache CXF framework. The various CXF frontend APIs covered in this book provide a wide variety of options in developing and deploying your application.

    The book introduces some advanced concepts such as Interceptors and features that will add extra capability to your service component. It will help you take advantage of different transport features offered by the CXF runtime such as HTTP, HTTP(S), and JMS protocols.

    Finally, the book mentions various tools that help developers creating web services as well as creating Java and JavaScript-based web services clients which invoke a real-world .NET web service. These tools are standard batch files that can be easily executed from the Windows command shell by following the instructions in the book.

    Style and approach

    This book provides a quick start in developing web services using the open source Apache CXF framework. Each chapter uses illustrations from an Order Processing Application and all the code examples are built using the ANT tool. These practical, simple, and easy-to-work-with illustrations are accompanied by step-by-step instructions.

    As a developer you can take advantage of these practical scenarios to understand the CXF framework and also make use of them in real-life applications. After reading this book, you will be able to develop and deploy services using the CXF framework.

    Table of Contents

    1. Apache CXF Web Service Development
      1. Table of Contents
      2. Apache CXF Web Service Development
      3. Credits
      4. About the Authors
      5. About the Reviewer
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. Getting Familiar with CXF
        1. Web service technology standards
          1. XML
            1. SOAP (Simple Object Access Protocol)
            2. WSDL (Web Services Description language)
          2. REST (Representational State Transfer)
          3. Service Registry
        2. Introducing web services
          1. Approaches for web service development
          2. Web service SOAP communication styles
        3. Apache CXF
          1. History of CXF
          2. Why CXF?
            1. Support for web service standards
            2. Support for POJO (Plain Old Java Object)
            3. Frontend programming APIs
            4. Tools support
            5. Support for RESTful services
            6. Support for different transports and bindings
            7. Support for non-XML binding
            8. Ease of use
            9. Flexible deployment
        4. Setting up the environment
          1. For ANT users
          2. For Maven users
        5. Summary
      8. 2. Developing a Web Service with CXF
        1. The Order Processing Application
        2. Developing a service
          1. Creating a Service Endpoint Interface (SEI)
          2. Developing a service implementation class
          3. Spring-based server bean
        3. Developing a client
          1. Developing a Spring-based client bean
          2. Developing web service client code
        4. Running the program
          1. Building the code
          2. Deploying the code
          3. Executing the code
        5. CXF architecture
          1. Bus
          2. Frontend
            1. JAX-WS
            2. Simple frontend
          3. Messaging and Interceptors
          4. Service model
          5. Data binding
          6. Protocol binding
          7. Transports
        6. Summary
      9. 3. Working with CXF Frontends
        1. JAX-WS frontend
          1. Code-first development
            1. Creating Service Endpoint Interface (SEI)
            2. Adding Java annotations
              1. javax.jws.WebService
              2. javax.jws.soap.SOAPBinding
                1. RPC versus Document style
              3. javax.jws.WebMethod
            3. Publishing the service
            4. Developing a consumer
            5. Running the Code-first example
          2. Contract-first development
            1. Generating service components
              1. JAXB input and output message classes
              2. Service Interface
              3. Service implementation class
              4. Standalone server class
              5. Build file
            2. Implementing the service method
          3. Publishing the web service
          4. Invoking the web service
        2. Using dynamic client
          1. Creating a simple dynamic client
          2. Running the dynamic client
          3. Using the CXF service model for building dynamic client
            1. Running the dynamic client which uses Service Model API
        3. Provider and Dispatch services
          1. Understanding messaging modes
            1. Message mode
            2. Payload mode
          2. Understanding types of message objects
            1. javax.xml.transform.Source
              1. DOMSource
              2. SAXSource
              3. StreamSource
              4. javax.xml.soap.SOAPMessage
              5. javax.activation.DataSource
          3. Implementing Provider service
          4. Publishing the Provider service
          5. Implementing the Dispatch service
          6. Running the provider dispatch example
          7. Web service context
          8. Implementing Context in service
            1. Running the web service context example
        4. Simple frontend
          1. Developing a simple frontend
            1. Creating service implementation class and interface
            2. Creating server implementation
            3. Creating client
        5. Running the simple frontend example
        6. Summary
      10. 4. Learning about Service Transports
        1. Transport protocols in CXF
          1. HTTP transport
            1. SOAP over HTTP
              1. SOAP 1.1 over HTTP
              2. SOAP 1.2 over HTTP
            2. HTTP only
            3. HTTP conduit
            4. HTTP destination
          2. HTTPs transport
            1. Developing the service and implementation class
            2. Generating crypto key
            3. Creating client and server bean configuration
            4. Configuring the server to support SSL
            5. Developing the client component
            6. Building and deploying
            7. Configuring SSL for Jetty runtime
          3. JMS transport
            1. Developing the service and implementation class
            2. Developing an embedded broker
            3. Creating a server and client bean configuration
            4. Developing a client component
            5. Performing build and deployment
          4. Local transport
            1. Developing SEI and an implementation class
            2. Developing a server
            3. Creating client bean configuration
            4. Developing a Client
            5. Building and executing
        2. Summary
      11. 5. Implementing Advanced Features
        1. Understanding CXF interceptors
          1. Understanding interceptor phase and chain
          2. Overview of the interceptor API
            1. Interceptor interface
            2. The PhaseInterceptor interface
            3. The AbstractPhaseInterceptor class
        2. Developing the custom interceptor
          1. Developing the server side interceptor
          2. Adding a server side interceptor to the Order Process service
          3. Developing the client side interceptor
          4. Adding a client side interceptor to the client code
          5. Developing the standalone server for publishing the Order Process web service
          6. Building and running the Order Process web service and interceptor
            1. Building the code
              1. Deploying the code
            2. Executing the code
          7. Testing the custom interceptor for negative condition
        3. Understanding CXF features
        4. Applying the GZIP feature to the Order Process web service
          1. Developing service and implementation class
          2. Developing a server component
          3. Creating the client bean configuration file
          4. Creating a client component to consume the service
          5. Building and executing the code
        5. Understanding CXF Invoker
          1. Overview of Invoker API
            1. The Invoker interface
            2. The AbstractInvoker class
        6. Developing custom invoker
        7. Summary
      12. 6. Developing RESTful Services with CXF
        1. Overview of REST and RESTful services
          1. Java API for RESTful services
          2. CXF JAX-RS implementation
        2. Developing end-to-end RESTful services using CXF JAX-RS implementation
          1. Developing the RESTful service
            1. Creating Java data objects for Request and Response
            2. Providing binding for the Request and Response data objects
            3. Developing the implementation class
              1. Adding Data Access logic to the implementation class
            4. Creating the client
              1. Making RESTful service available over HTTP
            5. Running the program
            6. Building the code
            7. Deploying the code
            8. Executing the code
          2. Adding exception handling to RESTful service
        3. Summary
      13. 7. Deploying RESTful Services with CXF
        1. Packaging the Book Shop application
          1. Configuring CategoryService RESTful bean using Spring
          2. Integrating Spring using web.xml
          3. Building and deploying the WAR file
            1. Building the code
            2. Deploying the code
        2. Invoking operations on the Book Shop RESTful application
          1. Installing POSTER client
          2. Invoking the Book Shop application using the the POSTER tool
            1. Invoking the Get Category operation
            2. Invoking the Add Category operation
            3. Invoking the Update Category operation
            4. Invoking the Add Books operation
            5. Invoking the Get Books operation
            6. Invoking the Update Category operation with invalid request
            7. Invoking the Get Category operation with invalid request
            8. Invoking the Delete Category operation
          3. Invoking the Book Shop application using CXF APIs
        3. Configuring JSON support for the Book Shop application
          1. Incorporating JSON message format for the Book Shop application
            1. Invoking the Get Category operation with JSON as the message format
            2. Invoking the Add Category operation with JSON as the message format
          2. Invoking the Book Shop application with JSON as the message format using CXF APIs
        4. Intercepting messages for the Book Shop application
        5. Deploying the Book Shop application in the application servers
        6. Summary
      14. 8. Working with CXF Tools
        1. Invoking a web service using the Java client
          1. Analyzing the service WSDL definition
          2. Building and running the Java web service clients
            1. Generate the web service clients
            2. Analyzing the JAX-WS and client generated artifacts
            3. Modifying the generated client
            4. Building the client
            5. Running the client
        2. Invoking the web service using JavaScript
          1. Building and running the Java web service clients
          2. Generating the JavaScript client
            1. Analyzing the generated artifacts
            2. Creating the client
            3. Running the client
        3. Creating Service Implementation from the WSDL file
          1. Generating and deploying the Service Implementation from the WSDL file
            1. Generating the web Service Implementation
            2. Analyzing the Service Implementation generated artifacts
            3. Modifying the generated Service Implementation
            4. Building the web service project
            5. Deploying and publishing the web service
            6. Invoking the web service
        4. Validating WSDL files
        5. Summary
      15. A. Getting Ready with Code Examples
        1. Downloading the source code
        2. Downloading the software required for the book
        3. Setting up the environment
        4. Using Maven for Build management
          1. Building chapter source code using Maven
      16. B. Getting Started with Spring
        1. Concept of POJO-based development
        2. Understanding Inversion of Control
        3. Overview of aspect-oriented programming
        4. Introduction to Spring framework
          1. The Spring IoC container
        5. Creating a Spring IoC application
          1. Creating the entity model
          2. Creating services
          3. Creating the application and wiring POJO
          4. Creating the standalone client
          5. Running the program
            1. Building the code
            2. Executing the code
        6. Summary
      17. Index