Hello All
In this post I am talking about creating a simple JAX-WS web service using Jdeveloper 12.1.3 .
JAX-WS is a Java API for XML Web Services and we can create a JAX-WS easily with Jdeveloper IDE
Idea is to create a web service that shows Employees list with their name , designation, salary and department name so for this I am going to use POJO Java Class
Let's implement it
Creating JAX-WS WebService
- Create a Java Desktop Application
- Give a name to application
- Create a Java Class in project
- Here I am creating a Java Bean class to hold Employee Details variables
- Create another class to hold Employees data and make use of bean class to add all information
- Now to create WebService add @WebService annotation just before class name and import javax.jws.WebService package
- Click on yellow bulb icon and select Configure project for web services and in dialog select with support for JAX-WS Annotations
Java Code of EmpBean Class
publicclassEmpBean{
publicEmpBean(){
super();
}
/**Constructior to add new Employee detail
* @param name
* @param desig
* @param salary
* @param dept
*/
publicEmpBean(String name, String desig, Integer salary, String dept){
super();
this.name= name;
this.designation= desig;
this.salary= salary;
this.departments= dept;
}
//Employees Details Variables
private String name;
private String designation;
private Integer salary;
private String departments;
//Accessors
publicvoidsetName(String name){
this.name= name;
}
public String getName(){
return name;
}
publicvoidsetDesignation(String designation){
this.designation= designation;
}
public String getDesignation(){
return designation;
}
publicvoidsetSalary(Integer salary){
this.salary= salary;
}
public Integer getSalary(){
return salary;
}
publicvoidsetDepartments(String departments){
this.departments= departments;
}
public String getDepartments(){
return departments;
}
}
Java Code of Employees Class
importjava.util.ArrayList;
importjava.util.List;
publicclassEmployees{
publicEmployees(){
super();
}
//List to store Employees
private List<EmpBean> empList =new ArrayList<EmpBean>();
publicvoidsetEmpList(List<EmpBean> empList){
this.empList= empList;
}
public List<EmpBean>getEmpList(){
//Add items in list onlt if it is empty
if(empList.size()==0){
empList.add(new EmpBean("Ashish Awasthi","Software Engineer",10000,"Project"));
empList.add(new EmpBean("Shanto Mathew","Software Engineer",10000,"Product"));
empList.add(new EmpBean("Gourav Raj","Project Manager",30000,"Project"));
empList.add(new EmpBean("Bharat Lal","Team Lead",20000,"Product"));
}
return empList;
}
}
Click on Ok and your project is configured for WebServices and a Web.xml file is created
Testing WebService
- Right click on WebService class and select Test WebService
- This option starts integrated weblogic server and initiate HTTP Analyzer after deploying WebService. Here you can see I have selected getEmpList method and click on Send Request button and it shows result in right window
Sample ADF Application - Download
Cheers :) Happy Learning