Please disable your adblock and script blockers to view this page

Search this blog

Monday, 15 May 2017

Create POJO based JAX-WS WebService easily with Jdeveloper 12.1.3


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


  • Java Code of EmpBean Class

    public class EmpBean {
        public EmpBean() {
            super();
        }
    
        /**Constructior to add new Employee detail
         * @param name
         * @param desig
         * @param salary
         * @param dept
         */
        public EmpBean(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
        public void setName(String name) {
            this.name = name;
        }
    
        public String getName() {
            return name;
        }
    
        public void setDesignation(String designation) {
            this.designation = designation;
        }
    
        public String getDesignation() {
            return designation;
        }
    
        public void setSalary(Integer salary) {
            this.salary = salary;
        }
    
        public Integer getSalary() {
            return salary;
        }
    
        public void setDepartments(String departments) {
            this.departments = departments;
        }
    
        public String getDepartments() {
            return departments;
        }
    }
    

  • Create another class to hold Employees data and make use of bean class to add all information


  • Java Code of Employees Class

    import java.util.ArrayList;
    import java.util.List;
    
    public class Employees {
        public Employees() {
            super();
        }
        //List to store Employees
        private List<EmpBean> empList = new ArrayList<EmpBean>();
    
        public void setEmpList(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;
        }
    }
    

  • 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 



  • 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 initiates 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

Next in Series-

Populate data in ADF Table using Web Service Data Control

1 comment :

  1. Hi,

    Can you please clarify about Jdev 11.1.1.7 as this is the certified jdev version to do oracle fusion cloud apps, How we can consume SOAP /REST web services available on the cloud to develop our extension.

    Thanks in Advance

    ReplyDelete