Web Service Development Using CXF - WordPress.com

67 downloads 414 Views 244KB Size Report
Web Service define a standard way of integrating systems using XML, SOAP, WSDL and UDDI open ... Apache CXF is an open source services framework.
Web Service Development Using CXF - Praveen Kumar Jayaram

Introduction to WS Web Service define a standard way of integrating systems using XML, SOAP, WSDL and UDDI open standards over an internet protocol backbone (HTTP).

XML – Tags the data (Extensible Markup Language) SOAP – Used to transfer data (Simple Object Access Protocol) WSDL – Describes services available (Web Service Definition Language) UDDI – Lists the services available in directory (Universal Description Discovery Integration)

Why Web Service? High interoperability. Web services are not tied to any programming language or operating system

Web Service Frameworks: Axis CXF – We are interested in CXF in this session

CXF – Web Service Framework Apache CXF is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. Why CXF? 1) JAX-WS support (Frontend) - Ease of building services - Generating WSDL from java classes and java classes from WSDL 2) Spring integration for declaring service endpoints 3) Aegis data binding - Unlike JAXB Aegis does not require annotation for building services 4) Apache liberal licensed and can be used for any type of applications Advantages of CXF over Axis: 1) CXF is JAX-WS complaint whereas Axis falls into proprietary things 2) CXF is very active in fix packs, releases and committers respond to issues often 3) CXF has better support for Spring integration 4) CXF is bit faster than Axis 1 (almost same for Axis 2) and easier to use http://cxf.apache.org/docs/index.html

Creating a service using CXF Create a service contract interface using annotations:

@WebService(serviceName=“HelloWorldService”, targetNamespace=“http://helloworld.com”) public interface IHelloWorld{ @WebMethod public String sayHello(@WebParam(name=“name”) String name); }

JAX-WS includes the annotations: 1) WebService – Allows to customize the service name, target namespace and port 2) WebMethod – Allows to customize the operation name 3) WebResult – Allows to customize return value of the web service call 4) WebParam – Helps in giving a name for parameter (Clear for service consumers)

Using JAX-WS annotated services Implement the service method sayHello(), package com.honeywell.ws.demo; public class HellowWorldImpl implements IHelloWorld{ public void sayHello(String name){ return “Hello ” + name; } } As we are aware CXF has better integration with Spring, we shall create service endpoint using configurations. Lets create a spring configuration file by name appContext.xml