Thursday 11 September 2014

JSON with json.simple Library

Maven Dependency:

<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1</version>
  </dependency>


Student Pojo:

package com.ram.json.simple.pojo;

import java.util.ArrayList;
import java.util.List;

public class Student {
   
    public String name;
    public String age;
    public List<String> list = new ArrayList<String>();
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAge() {
        return age;
    }
    public void setAge(String age) {
        this.age = age;
    }
    public List<String> getList() {
        return list;
    }
    public void setList(List<String> list) {
        this.list = list;
    }
   
   

}


Convert Java To JSON:

package com.ram.json.simple;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.json.simple.JSONObject;

import com.ram.jackson.pojo.Student;

public class JavaToJson {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {

        Student student = new Student();
        student.setName("Ramakrishna");
        student.setAge("26");
        List<String> list = new ArrayList<String>();
        list.add("100");
        list.add("200");
        list.add("300");
        student.setList(list);
       
        JSONObject jsonObject = new JSONObject();

        jsonObject.put("Name", student.getName());
        jsonObject.put("Age", student.getAge());
        jsonObject.put("list", student.getList());
   
        try {
   
            FileWriter file = new FileWriter("/home/biton/ramakrishna/delete/json/student.json");
            file.write(jsonObject.toJSONString());
            file.flush();
            file.close();
   
        } catch (IOException e) {
            e.printStackTrace();
        }
   
        System.out.print(jsonObject);
   
      }
   
    }


Convert JSON To Java:

package com.ram.json.simple;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;


public class JsonToJava {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
       
        JSONParser parser = new JSONParser();
       
        try {
   
            Object object = parser.parse(new FileReader("/home/biton/ramakrishna/delete/json/student.json"));
   
            JSONObject jsonObject = (JSONObject) object;
           
            System.out.println(jsonObject);
   
            String name = (String) jsonObject.get("Name");
            System.out.println(name);
   
            String age = (String) jsonObject.get("Age");
            System.out.println(age);
           
            List<String> list = (List<String>) jsonObject.get("list");
            System.out.println(list);
   
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
       
      }

}



JSON with gson Library

Maven Dependency:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>1.7.1</version>
  </dependency>


Student Pojo:

package com.ram.gson.pojo;

import java.util.ArrayList;
import java.util.List;

public class Student {
   
    public String name;
    public String age;
    public List<String> list = new ArrayList<String>();
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAge() {
        return age;
    }
    public void setAge(String age) {
        this.age = age;
    }
    public List<String> getList() {
        return list;
    }
    public void setList(List<String> list) {
        this.list = list;
    }   
}


Convert Java To JSON:

package com.ram.gson;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.ram.jackson.pojo.Student;

public class JavaToJson {

    public static void main(String[] args) {

        Student student = new Student();
        student.setName("Ramakrishna");
        student.setAge("26");
        List<String> list = new ArrayList<String>();
        list.add("100");
        list.add("200");
        list.add("300");
        student.setList(list);
       
        Gson gson = new Gson();
   
        String json = gson.toJson(student);
   
        try {

            FileWriter writer = new FileWriter("/home/ramakrishna/delete/json/student.json");
            writer.write(json);
            writer.close();
   
        } catch (IOException e) {
            e.printStackTrace();
        }
   
        System.out.println(json);
      }
   
    }



Convert JSON To Java:

package com.ram.gson;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import com.google.gson.Gson;
import com.ram.gson.pojo.Student;

public class JsonToJava {

    public static void main(String[] args) {
       
        Gson gson = new Gson();
       
        try {
   
            BufferedReader br = new BufferedReader(
                new FileReader("/home/ramakrishna/delete/json/student.json"));
   
            Student student = gson.fromJson(br, Student.class);
   
            System.out.println("Name:"+student.getName());
            System.out.println("Age:"+student.getAge());
            System.out.println("Values:"+student.getList());
   
        } catch (IOException e) {
            e.printStackTrace();
        }
       
      }

}




JSON with Jackson Library

Maven Dependency:

<!-- For Jackson -->
  <repositories>
    <repository>
        <id>codehaus</id>
        <url>http://repository.codehaus.org/org/codehaus</url>
    </repository>
  </repositories>

<dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.8.5</version>
</dependency>

Studen Pojo:

package com.ram.jackson.pojo;

import java.util.ArrayList;
import java.util.List;

public class Student {
   
    public String name;
    public String age;
    public List<String> list = new ArrayList<String>();
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAge() {
        return age;
    }
    public void setAge(String age) {
        this.age = age;
    }
    public List<String> getList() {
        return list;
    }
    public void setList(List<String> list) {
        this.list = list;
    }
}
 


Convert Java To JSON:

package com.ram.jackson;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.ram.jackson.pojo.Student;

public class JavaToJson {

    public static void main(String[] args) {

        Student student = new Student();
        student.setName("Ramakrishna");
        student.setAge("26");
        List<String> list = new ArrayList<String>();
        list.add("100");
        list.add("200");
        list.add("300");
        student.setList(list);
       
        ObjectMapper mapper = new ObjectMapper();
   
        try {
   
            mapper.writeValue(new File("/home/ramakrishna/delete/json/student.json"), student);
   
            System.out.println(mapper.writeValueAsString(student));
   
        } catch (JsonGenerationException e) {
   
            e.printStackTrace();
   
        } catch (JsonMappingException e) {
   
            e.printStackTrace();
   
        } catch (IOException e) {
   
            e.printStackTrace();
   
        }
   
      }
   
    }

Convert JSON To Java:

package com.ram.jackson;

import java.io.File;
import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.ram.jackson.pojo.Student;

public class JsonToJava {

    public static void main(String[] args) {
       
        ObjectMapper mapper = new ObjectMapper();
       
        try {
   
            Student student = mapper.readValue(new File("/home/ramakrishna/delete/json/student.json"), Student.class);
   
            System.out.println("Name:"+student.getName());
            System.out.println("Age:"+student.getAge());
            System.out.println("Values:"+student.getList());
           
   
        } catch (JsonGenerationException e) {
   
            e.printStackTrace();
   
        } catch (JsonMappingException e) {
   
            e.printStackTrace();
   
        } catch (IOException e) {
   
            e.printStackTrace();
   
        }
   
      }
}





JSON Introduction

JSON Introduction

JSON (JavaScript Object Notation) is a lightweight data-interchange format.

Format of JSON is  Key with Value pair 

It is easy for humans to read and write. It is easy for machines to parse and generate.

JSON format is used for serializing & transmitting structured data over network connection.

Web Services and API'S use JSON format to provide public data.

 JSON is language independent like XML

Java libraries to process JSON data, which are Jackson, Google Gson and JSON.simple

Wednesday 10 September 2014

Map Interface Examples

package com.ram;

import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 *
 * @author ramakrishna.v
 *
 */
public class MapInterfaceExamples {
   
    public static void main(String args[]) {
       
        Map<String,String> hashMap = new HashMap<String,String>();
        hashMap.put("key1","R");
        hashMap.put("key2","A");
        hashMap.put("key3","M");
       
        //Getting all keys
        retrieveValues("Map","HashMap",hashMap.keySet());
        //Getting all values
        retrieveValues("Map","HashMap",hashMap.values());
        //Getting all values based on keys
        getValues("Map","HashMap",hashMap,hashMap.keySet());
        //Getting all values based on keys getting by set interface
        displayValues("Map","HashMap",hashMap,hashMap.entrySet());
         
        Map<String,String> treeMap1 = new TreeMap<String,String>();
        treeMap1.put("key1","R");
        treeMap1.put("key2","A");
        treeMap1.put("key3","M");
       
        //Getting all keys
        retrieveValues("Map","TreeMap",treeMap1.keySet());
        //Getting all values
        retrieveValues("Map","TreeMap",treeMap1.values());
        //Getting all values based on keys
        getValues("Map","TreeMap",treeMap1,treeMap1.keySet());
        //Getting all values based on keys getting by set interface
        displayValues("Map","TreeMap",treeMap1,treeMap1.entrySet());
       
        SortedMap<String,String> treeMap2 = new TreeMap<String,String>();
        treeMap2.put("key1","R");
        treeMap2.put("key2","A");
        treeMap2.put("key3","M");
       
        //Getting all keys
        retrieveValues("SortedMap","TreeMap",treeMap2.keySet());
        //Getting all values
        retrieveValues("SortedMap","TreeMap",treeMap2.values());
        //Getting all values based on keys
        getValues("Map","TreeMap",treeMap2,treeMap2.keySet());
        //Getting all values based on keys getting by set interface
        displayValues("Map","TreeMap",treeMap2,treeMap2.entrySet());
         
        Map<String,String> linkedHashMap = new LinkedHashMap<String,String>();
        linkedHashMap.put("key1","R");
        linkedHashMap.put("key2","A");
        linkedHashMap.put("key3","M");
       
        //Getting all keys
        retrieveValues("Map","LinkedHashMap",linkedHashMap.keySet());
        //Getting all values
        retrieveValues("Map","LinkedHashMap",linkedHashMap.values());
        //Getting all values based on keys
        getValues("Map","LinkedHashMap",linkedHashMap,linkedHashMap.keySet());
        //Getting all values based on keys getting by set interface
        displayValues("Map","LinkedHashMap",linkedHashMap,linkedHashMap.entrySet());
       
        Map<String,String> hashtable = new Hashtable<String,String>();
        hashtable.put("key1","R");
        hashtable.put("key2","A");
        hashtable.put("key3","M");
       
        //Getting all keys
        retrieveValues("Map","LinkedHashMap",hashtable.keySet());
        //Getting all values
        retrieveValues("Map","LinkedHashMap",hashtable.values());
        //Getting all values based on keys
        getValues("Map","hashtable",hashtable,hashtable.keySet());
        //Getting all values based on keys getting by set interface
        displayValues("Map","hashtable",hashtable,hashtable.entrySet());
    }
   
     @SuppressWarnings({ "rawtypes"})
     static void retrieveValues(String var1,String var2,Collection collection) {
         System.out.println(var1+" interface using "+var2+" class");
          Iterator iterator = collection.iterator();
          while (iterator.hasNext()) {
             String string = (String) iterator.next();
             System.out.println(string);
          }
          System.out.println("===========================");
       }
   
     @SuppressWarnings({ "rawtypes"})
     static void getValues(String var1,String var2,Map map,Collection collection) {
         System.out.println(var1+" interface using "+var2+" class");
          Iterator iterator = collection.iterator();
          while (iterator.hasNext()) {
             String key = (String) iterator.next();
             String value = (String)map.get(key);
             System.out.println("key:"+key+" value:"+value);
          }
          System.out.println("===========================");
       }
   
     @SuppressWarnings({ "rawtypes"})
     static void displayValues(String var1,String var2,Map map,Collection collection) {
         System.out.println(var1+" interface using "+var2+" class");
       
         Set set = (Set) collection;
          Iterator iterator = set.iterator();
          while (iterator.hasNext()) {
              Map.Entry entry = (Map.Entry) iterator.next();
              String key = (String) entry.getKey();
              String value = (String) entry.getValue();
             System.out.println("key:"+key+" value:"+value);
          }
          System.out.println("===========================");
       }

}

Set Interface Examples

package com.ram;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 *
 * @author ramakrishna.v
 *
 */
public class SetInterfactExamples {
   
    public static void main(String args[]) {
       
            Set<String> hashSet = new HashSet<String>();
            hashSet.add("a");
            hashSet.add("b");
            hashSet.add("c");
            retrieveValues("Set","HashSet",hashSet);
           
            Set<String> treeSet1 = new TreeSet<String>();
            treeSet1.add("R");
            treeSet1.add("A");
            treeSet1.add("M");
            retrieveValues("Set","TreeSet",treeSet1);
           
            SortedSet<String> treeSet2 = new TreeSet<String>();
            treeSet2.add("R");
            treeSet2.add("A");
            treeSet2.add("M");
            retrieveValues("SortedSet","TreeSet",treeSet2);
           
            Set<String> linkedHashset = new LinkedHashSet<String>();
            linkedHashset.add("R");
            linkedHashset.add("A");
            linkedHashset.add("M");
            retrieveValues("Set","LinkedHashSet",linkedHashset);
    }
   
    @SuppressWarnings({ "rawtypes"})
     static void retrieveValues(String var1,String var2,Collection collection) {
         System.out.println(var1+" interface using "+var2+" class");
          Iterator iterator = collection.iterator();
          while (iterator.hasNext()) {
             String string = (String) iterator.next();
             System.out.println(string);
          }
          System.out.println("===========================");
       }
}

List Interface Examples

package com.ram;

import java.util.Collection;
import java.util.Iterator;

import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Stack;
import java.util.Vector;

/**
 *
 * @author ramakrishna.v
 *
 */
public class ListInterfaceExamples {

    public static void main(String[] args) {
       
        List<String> arayList = new ArrayList<String>();
        arayList.add("R");
        arayList.add("A");
        arayList.add("M");
        retrieveValues("List","ArrayList",arayList);
       
        List<String> linkedList = new LinkedList<String>();
        linkedList.add("R");
        linkedList.add("A");
        linkedList.add("M");
        retrieveValues("List","LinkedList",linkedList);
       
        List<String> stack = new Stack<String>();
        stack.add("R");
        stack.add("A");
        stack.add("M");
        retrieveValues("List","Stack",stack);
       
        List<String> vector = new Vector<String>();
        vector.add("R");
        vector.add("A");
        vector.add("M");
        retrieveValues("List","Vector",vector);
       
       }
   
     @SuppressWarnings({ "rawtypes"})
     static void retrieveValues(String var1,String var2,Collection collection) {
         System.out.println(var1+" interface using "+var2+" class");
          Iterator iterator = collection.iterator();
          while (iterator.hasNext()) {
             String string = (String) iterator.next();
             System.out.println(string);
          }
          System.out.println("===========================");
       }
    }

Wednesday 3 September 2014

SOAP WebService Example Service using spring and apache cxf (Top To Bottom Approach)

=>Procedure
1)Add maven Dependencies for spring and apache cxf
2)Write wsdl and xsd 
3)Generate stubs(Generated java classes,use wsimport command)
4)Develope implementation class
5)Configue implementation class as spring bean in spring configuration file
6)Configure CXFServlet in web.xml file
7)Deploy the project into any web server

1)=>First add maven dependencies to your project

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>SoapBasicExampleTopToBottom</groupId>
    <artifactId>SoapBasicExampleTopToBottom</artifactId>
    <version>1</version>
    <packaging>war</packaging>
    <properties>
        <cxf.version>2.7.2</cxf.version>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-addr</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-security</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    </dependencies>
  </project>


2)=> Write wsdl,xsd ,Here service name is DemoService,method name is Addition.

DemoService.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:demoService="http://com.ram/services/demo"
targetNamespace="http://com.ram/services/demo">

    <wsdl:types>
        <xsd:schema>
            <xsd:import namespace="http://com.ram/services/demo" schemaLocation="DemoService.xsd"/>
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="AdditionInputMessage">
        <wsdl:part name="AdditionInputPart" element="demoService:AdditionRequest"/>
    </wsdl:message>
    <wsdl:message name="AdditionOutputMessage">
        <wsdl:part name="AdditionOutputPart" element="demoService:AdditionResponse"/>
    </wsdl:message>
    <wsdl:message name="AdditionFaultMessage">
        <wsdl:part name="AdditionFaultPart" element="demoService:AdditionFault"/>
    </wsdl:message>
   
    <wsdl:portType name="DemoServicePortType">
        <wsdl:operation name="Addition">
            <wsdl:input name="AdditionInput" message="demoService:AdditionInputMessage"/>
            <wsdl:output name="AdditionOutput" message="demoService:AdditionOutputMessage"/>
            <wsdl:fault name="AdditionFault" message="demoService:AdditionFaultMessage"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="DemoServiceBinding" type="demoService:DemoServicePortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="Addition">
            <soap:operation soapAction="Addition"/>
            <wsdl:input name="AdditionInput">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="AdditionOutput">
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdditionFault">
                <soap:fault name="AdditionFault" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="DemoService">
        <wsdl:port name="demoServicePort" binding="demoService:DemoServiceBinding">
            <soap:address location="No Target Adress"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>


DemoService.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://com.ram/services/demo" targetNamespace="http://com.ram/services/demo"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="AdditionRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="value1" type="xs:integer"/>
                <xs:element name="value2" type="xs:integer"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="AdditionResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="result" type="xs:integer"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="AdditionFault">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Fault" type="xs:string">
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>


3)=> Generate stubs based on your wsdl

wsimport -keep -s yourProjectsrcLocation yourProjectWsdlUrl

4)=> Provide Implementation 

package com.iton.serviceimpl;

import java.math.BigInteger;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;

import ram.com.services.demo.AdditionFaultMessage;
import ram.com.services.demo.AdditionRequest;
import ram.com.services.demo.AdditionResponse;
import ram.com.services.demo.DemoServicePortType;

/**
 *
 * @author ramakrishna.v
 *
 */
public class ArithmeticServiceImpl implements DemoServicePortType {

    @Override
    @WebResult(name = "AdditionResponse", targetNamespace = "http://com.ram/services/demo", partName = "AdditionOutputPart")
    @WebMethod(operationName = "Addition", action = "Addition")
    public AdditionResponse addition(
            @WebParam(partName = "AdditionInputPart", name = "AdditionRequest", targetNamespace = "http://com.ram/services/demo") AdditionRequest additionInputPart)
            throws AdditionFaultMessage {
       
        BigInteger value1 = additionInputPart.getValue1();
        BigInteger value2 = additionInputPart.getValue2();
        BigInteger result =  value1.add(value2);
        System.out.println(result);
        AdditionResponse obj = new AdditionResponse();
        obj.setResult(result);
       
        return obj;
    }
}


 5)=>Configure this implementation class in spring configuration file

ApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:wsa="http://cxf.apache.org/ws/addressing"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://cxf.apache.org/jaxws
    http://cxf.apache.org/schemas/jaxws.xsd">

    <context:annotation-config />
   
    <bean id="demoService" class="com.iton.serviceimpl.ArithmeticServiceImpl"/>
   
    <jaxws:endpoint id="Demo" implementor="#demoService"
        address="/DemoService" xmlns:tns="http://com.ram/services/demo"
        serviceName="tns:DemoService" endpointName="tns:demoServicePort"
        wsdlLocation="wsdl/DemoService.wsdl">
    </jaxws:endpoint> 
</beans>


6)Configure CXFServlet in web.xml file

<web-app>
<display-name>SoapTopToBottomExample</display-name>
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>WEB-INF/applicationContext.xml</param-value>
 </context-param>
<!-- <listener>
   <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener -->
       <listener>
               <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>

       <servlet>
               <servlet-name>CXFServlet</servlet-name>
               <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
               <load-on-startup>1</load-on-startup>
       </servlet>
      
       <servlet-mapping>
               <servlet-name>CXFServlet</servlet-name>
               <url-pattern>/*</url-pattern>
       </servlet-mapping>
</web-app>



7)Deploy the project into web server.For example It will display the web service wsdl url as follows.

=>http://localhost:7777/SoapBasicExampleTopToBottom