Skip to main content

CXF Example –Web Service Client Using Spring

Continuing from my previous post on (CXF Example –Web Service Using Spring and Maven), let's create a client application to consume the web service.

Steps

  1. Generate POJOs from WSDL to access the Web Service using the tool wsdl2java as below.

    You can access the WSDL used in this example from here.


     

    wsdl2java rateServiceWSDL.xml


     

    WSDL2Java is a command line tool that generates Java classes from an existing WSDL document. Generated classes represent client stubs, server skeletons and data types that will helps you to write client side and server Java programs for Web services defined in the WSDL document.    

  2. Create a client-beans.xml as below:

    <beans
    xmlns="http://www.springframework.org/schema/beans"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"

        xsi:schemaLocation="

    http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans.xsd

    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

        <jaxws:client
    id="rateServiceClient"
    serviceClass="com.mycompany.webservice.service.InterestRateService"

            address="http://localhost:8080/rateservice-1.0/webservices/interestRate"
    />

    </beans>

  3. Create the client Class to access the Web Service as below:


     

    ClassPathXmlApplicationContext context

= new ClassPathXmlApplicationContext(

                new String[] { "com/mycompany/webservice/client-beans.xml" });


 

    InterestRateService client = (InterestRateService) context

                .getBean("rateServiceClient");

    ArrayOfMortgageType arrayOfTypes = client.getMortgageTypes();

        

    List<MortgageType> types = arrayOfTypes.getMortgageType();

        

    for (MortgageType aType: types){

        System.out.println(aType.getDescription().getValue());

    }

        

You may download the complete source code from


 


 

Comments

Paul said…
Thanks a ton Santhosh. It was very helpful.

Popular posts from this blog

SAAS Simple Maturity Model

There are two architectural models – commonly referred as SAAS Maturity models- that describe the transition of a service to what is called Multi-tenant efficient, highly scalable application. The SAAS Maturity model described by Microsoft has four distinct stages and is illustrated below. Another similar well-known model for SaaS-maturity is known as Forrester-model but adds another stage known as "Dynamic Business Apps-as-a-service". The three key Attributes of a SAAS Architecture: Configurability: Metadata used to configure the way the application behaves for customers Multi-tenant Efficiency : Maximizing the sharing of resources across tenants Scalability: Maximizing concurrency, resource efficiency SAAS Simple Maturity Model (Microsoft, 2006) SaaS Maturity Model (Forres

SpringBoot : Performance War

Reactive Systems are designed to address challenges posed by modern software systems - the challenges related to large number of users and high throughput. Reactive systems are expected to be highly responsive, resilient, elastic and message driven. In this article we will: Build a set of fully non-blocking REST API using SpringBoot 2.0, WebFlux and Reactive Redis. Performance test the above Reactive APIs against the traditional non-reactive APIs. The code used in this example can be downloaded from GitHub Step 1: Create a skeleton Reactive WebFlux SpringBoot project Create a SpringBoot maven project using - https://start.spring.io/ Add the following dependencies: spring-boot-starter-web spring-boot-starter-data-redis spring-webflux spring-boot-starter-data-redis-reactive Refer to the dependencies in pom.xml Step 2: Create Domain Objects The demo project uses the domain objects Customer and Account . A customer can have multiple accounts.

Web Service Framework comparison

Web Services is one of those concepts made all the more difficult to understand because of the myriad acronyms and abbreviations that are superfluous in any discussion. Covering all the concepts and standards associated with Web Services is a vast topic in itself. There are a large number of standards around Web Services. These standards define the norms of a Web Services implementation and ensure that a Web Services is accessed independently of the client platform. There are numerous frameworks available to select to build web service today. Below is the most widely used ones. Product Does it fit my need? Axis2.0 Apache Axis2 is a complete re-design and re-write of the widely used Apache Axis SOAP stack to build on the lessons learnt from Apache Axis. An advantage of Axis 2 is its support for the binding frameworks XMLBeans. Axis 2 with XMLBeans is widely