Developing a Web Service with CXF

July 23, 2010

Webservices

«»

Apache CXF Web Service Development


Apache CXF is an open source services framework that makes web service development
easy, simplified, and standard based. CXF provides many features such as frontend
programming, support for different transports and data bindings, support for different
protocols, and other advanced concepts like Features and Invokers. It also provides a
programming model to build and deploy RESTful services.


The focus of the book is to provide readers with comprehensive details on how to use the
overview of CXF features and architecture. Each feature is explained in a separate
chapter, each of which covers well defined practical illustrations using real world
examples. This helps developers to easily understand the CXF API. Each chapter
provides hands on examples and provides step-by-step instructions to develop, deploy,
and execute the code.


What This Book Covers


The book is about the CXF service development framework. The book covers two of the
most widely used approaches, for web services development, SOAP and REST. Each
chapter in the book provides hands on examples, where we look in detail at how to use
the various CXF features in detail to develop web services in a step-by-step fashion


Chapter 1: Getting Familiar with CXF revisits web service concepts and provides an
introduction to CXF framework and its usage, and prepares the CXF environment for the
following chapters. By the end of this chapter the reader will be able to understand the
core concepts of CXF.


Chapter 2: Developing a Web Service with CXF focuses on getting the reader quickly
started with the CXF framework by developing a simple web service and running it under
the Tomcat container.


By the end of this chapter the reader will be able to develop a simple web service
using CXF.


Chapter 3: Working with CXF Frontends illustrates the use of different frontends, like
JAX-WS and CXF simple fronted API, and shows how to apply code-first and contractfirst
development approaches for developing web services. We will look at how to create
dynamic web service clients, the use of web service context, and how to work directly
with XML messages using CXF Provide and Dispatch implementation.


By the end of this chapter the reader will be able to apply different frontends to develop a
web service.


Chapter 4: Learning about Service Transports explains basic transport protocols for a
service and shows you how to configure HTTP, HTTP(s), JMS, and Local protocol for
web services communication. You will get introduced to the concept of HTTP conduit,
which enables the client program to apply policies or properties to HTTP and HTTPs
protocols, and how to generate a crypto key and a key store for HTTPs based service
communication. You will learn how to use JMS protocol for web services
communication and how to facilitate web services message exchange using CXF Local
service transport.


By the end of this chapter the reader will be able develop services with
different transports


Chapter 5: Implementing Advanced Features will explain advanced concepts using CXF
Features, Interceptors, and Invokers, and how to integrate these concepts in existing
applications.


By the end of this chapter the reader will be able develop services with features like
Interceptors and Invokers


Chapter 6: Developing RESTful Services with CXF explains the concept of REST
demonstrates additional features for developing enterprise RESTful services. We will
look at how to design, develop, and unit test the RESTful Service by taking a real world
example using CXF JAX-RS implementation.


By the end of this chapter the reader will be able to design, develop, and unit test the
RESTful service


Chapter 7: Deploying RESTful Services with CXF will explain how to deploy
REST services in a container like Tomcat using Spring configuration, and how to
test out the various operations exposed by the RESTFul application using CXF RESTful
client APiusing a web service development tool. We will look at how to enable
exception handling, JSON message support, and logging support for RESTful
applications using CXF framework.


By the end of this chapter the reader would be able utilize various CXF features for
developing RESTful services and how to leverage Spring configuration for deploying
RESTful service in the tomcat container.


Chapter 8: Working with CXF Tools will explain some of the commonly used CXF
tools that assist us in web services development. We will look at how to invoke a real
world .NET service over the internet using a Java client and JavaScript, create web
service implementation from WSDL files, generate WSDL files from web service
implementation, and validate the WSDL file for compliance.


By the end of this chapter the reader will be able to use different CXF tools to
develop a service.


Appendix A deals with how to set up the CXF environment, provides details on how the
source code for each chapter is organized, and shows how to run the source code
examples using the ANT tool and Maven Tool.


Appendix B provides an explanation of the basics of the Spring framework and IoC
concepts, along with an end-to-end example which utilizes Spring IoC concepts.


By the end of this Appendix chapter the reader will have a good understanding of Spring
capabilities used in the context of CXF web services development in this book.


Developing a Web Service with CXF


The first chapter provided an introduction to web services and CXF framework. We
looked at the features supported by the CXF framework and how to set up the CXF
environment. This chapter will focus on programming web service with CXF. CXF
provides a robust programming model that offers simple and convenient APIs for
web service development. The chapter will focus on illustrating a simple web service
development using CXF and Spring-based configurations. The chapter will also talk
about the architecture of CXF.


Before we examine CXF-based web service development, we will review the example
application that will be illustrated throughout the book. The example application
will be called Order Processing Application. The book will demonstrate the same
application to communicate different concepts and features of CXF so that the reader
can have a better understanding of CXF as a whole. This chapter will focus on the
following topics:



  • Overview of a sample Order Processing Application

  • CXF-based web service development with Spring

  • Insight into CXF architecture


The Order Processing Application


The objective of the Order Processing Application is to process a customer order.
The order process functionality will generate the customer order, thereby making
the order valid and approved. A typical scenario will be a customer making an
order request to buy a particular item. The purchase department will receive the
order request from the customer and prepare a formal purchase order. The purchase
order will hold the details of the customer, the name of the item to be purchased,
the quantity, and the price. Once the order is prepared, it will be sent to the
Order Processing department for the necessary approval. If the order is valid and
approved, then the department will generate the unique order ID and send it back to
the Purchase department. The Purchase department will communicate the order ID
back to the customer.



For simplicity, we will look at the following use cases:



  • Prepare an order

  • Process the order


The client application will prepare an order and send it to the server application
through a business method call. The server application will contain a web service
that will process the order and generate a unique order ID. The generation of the
unique order ID will signify order approval.



In real world applications a unique order ID is always accompanied by
the date the order was approved. However, in this example we chose to
keep it simple by only generating order ID.


Developing a service


Let’s look specifically at how to create an Order Processing Web Service and then
register it as a Spring bean using a JAX-WS frontend.



In Chapter 3 you will learn about the JAX-WS frontend. The chapter
will also cover a brief discussion on JAX-WS. The Sun-based JAX-WS
specification can be found at the following URL:

http://jcp.org/aboutJava/communityprocess/final/

jsr224/index.html


JAX-WS frontend offers two ways of developing a web service—Code-first and
Contract-first. We will use the Code-first approach, that is, we will first create a Java
class and convert this into a web service component. The first set of tasks will be to
create server-side components.



In web service terminology, Code-first is termed as the Bottoms Up
approach, and Contract-first is referred to as the Top Down approach.


To achieve this, we typically perform the following steps:



  • Create a Service Endpoint Interface (SEI) and define a business method
    to be used with the web service.

  • Create the implementation class and annotate it as a web service.

  • Create beans.xml and define the service class as a Spring bean using a
    JAX-WS frontend.

email

«»

Comments

comments