Drop Down

Sunday, December 8, 2019

EmployeeServiceConsumer

Consumer Steps:
--------------

1.Get the wsdl file from the Provider.
2.Test the service through SOAP UI.
3.Generate the artifacts.
C:>wsimport -d src -keep -verbose wsdl location
output: artifacts.
  1.Service class.
  2.Interface name
  3.request and response classes
  4.endpoint url.

4.Write webservice client code.

  1.create service class object
  2.call the port and it returns interface
  3.prepare the webservice request.
  4.call the getOrder API.
  5.call the getPrice API.



Step to develop client in eclipse.
1.Create java project.

2. create lib folder. copy all the jars(jaxws) in to lib folder.

3.generate artifacts using wsdl.
Goto Command prompt execute fillowing commnad

  E:\WorkSpace\webservice\JaxWsConsumer>wsimport -d src -keep -verbose http://localhost:2020/JaxWsOrderServiceProvider/online?wsdl

4. Write client application  code in main method based class.
   Steps to write logic in client class.

    1.create service class object
2.call the port and it returns interface
3.prepare the webservice request.
4.call the getOrder API.
5.call the getPrice API.




Sample example for SAOP using Apache CXF and Spring Boot.

cxf spring boot dependency
    cxf-spring-boot-starter-jars
application.properties
  cxf.jars.component-scan=true
  server.context-path=/helloapp

Steps:
1.Create maven project
2.Create End point class(service)
3.Create configuation class.
4.Test the application

======================================================================
================EmployeeServiceConsumer=======================
======================================================================

*) Parse wsdl to generate stub (artifacts) using wsimport



package test.Client;

import java.util.List;

import com.rameshit.employee.Employee;
import com.rameshit.employee.EmployeeService;
import com.rameshit.employee.EmployeeServiceImplService;

public class EmpServiceConsumer_Test
{

public static void main(String[] args)
{
//1.create service class object
EmployeeServiceImplService employeeServiceImplService = new EmployeeServiceImplService();

//2.call the port and it returns interface
EmployeeService employeeService =  employeeServiceImplService.getEmployeeServiceImplPort();

//3.prepare the webservice request. (Bean ka object bana ke access karo...)
Employee emp = new Employee();
/*emp.setCompany("Apple");
emp.setEmpid(0071);
emp.setFname("Amit Kumar");
emp.setLname("Manjhi");
emp.setLocation("Boston");
emp.setSalary(999999); */
//4.call the getOrder API.
//5.call the getPrice API.

emp = employeeService.getEmployeesInfo(505);
System.out.println("Company Name: "+emp.getCompany());
System.out.println("Employe Id: "+emp.getEmpid());
System.out.println("Employe First Name: "+emp.getFname());
System.out.println("Employe Last Name: "+emp.getLname());
System.out.println("Employe Location: "+emp.getLocation());
System.out.println("Employe Salary: "+emp.getSalary());

//---------
System.out.println("******************************************************");
List<Employee> employeeList = employeeService.getAllEmployee();
for(Employee emp_n : employeeList)
{
System.out.println("Company Name: "+emp_n.getCompany());
System.out.println("Employe Id: "+emp_n.getEmpid());
System.out.println("Employe First Name: "+emp_n.getFname());
System.out.println("Employe Last Name: "+emp_n.getLname());
System.out.println("Employe Location: "+emp_n.getLocation());
System.out.println("Employe Salary: "+emp_n.getSalary());
System.out.println();
System.out.println("**********"+emp_n.getFname()+"***************");
}

}

}



output:
Company Name: IBM
Employe Id: 555
Employe First Name: Amit
Employe Last Name: Kumar
Employe Location: Noida
Employe Salary: 98789
******************************************************
Company Name: Amazon
Employe Id: 4414
Employe First Name: Amit
Employe Last Name: Manjhi
Employe Location: Sillicon Vally
Employe Salary: 9878999

*************************Amit*****************************
Company Name: Amazon
Employe Id: 4414
Employe First Name: Amit
Employe Last Name: Manjhi
Employe Location: Sillicon Vally
Employe Salary: 9878999

*************************Amit*****************************
Company Name: Amazon
Employe Id: 4414
Employe First Name: Amit
Employe Last Name: Manjhi
Employe Location: Sillicon Vally
Employe Salary: 9878999

*************************Amit*****************************
Company Name: Amazon
Employe Id: 4414
Employe First Name: Amit
Employe Last Name: Manjhi
Employe Location: Sillicon Vally
Employe Salary: 9878999

*************************Amit*****************************
Company Name: Amazon
Employe Id: 4414
Employe First Name: Amit
Employe Last Name: Manjhi
Employe Location: Sillicon Vally
Employe Salary: 9878999

*************************Amit*****************************



=====================wsdl===============


















No comments:

Post a Comment

Java 8 Notes Pics