Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Open the Developer Studio Dashboard (click Developer Studio > Dashboard) and click JAX-WS Service Project.

    Image Added
     
  2. Click Create New JAX-WS Service and then click Next.
  3. Enter EmployeeManagementJAXWSProject as the project name, com.employee.management.jaxws.service as the package name and EmployeeManagementService as the class name. 

    Image Added
     
  4. Click FinishThe project structure is created with a simple hello operation. 

    Image Added
     
  5. Implement the service class and two beans classes for response messages, as shown below:

    Image Added 

    Code Block
    languagejava
    titleEmployeeManagementService.java
    package com.employee.management.jaxws.service;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    
    import com.employee.management.jaxws.beans.Employee;
    import com.employee.management.jaxws.beans.Message;
    
    @WebService(serviceName = "EmployeeManagementService")
    public class EmployeeManagementService {
    
        Map<String, Map<String, String>> employees = new HashMap<>();
    
        @WebMethod(operationName = "register")
        public Message register(@WebParam(name = "id") String id,
       		 @WebParam(name = "name") String name,
       		 @WebParam(name = "designation") String designation,
       		 @WebParam(name = "salary") String salary) {
    
       	 id = id.trim();
       	 if (!employees.containsKey(id)) {
       		 Map<String, String> info = new HashMap<>();
       		 info.put("name", name);
       		 info.put("designation", designation);
       		 info.put("salary", salary);
       		 employees.put(id, info);
    
       		 return new Message("Successfully Registered");
       	 }
       	 return new Message("Employee id already registered");
        }
    
        @WebMethod(operationName = "getEmployee")
        public Employee getEmployee(@WebParam(name = "id") String id) {
       	 id = id.trim();
       	 if (employees.containsKey(id)) {
       		 Map<String, String> info = new HashMap<>();
       		 info = employees.get(id);
       		 return new Employee(id, info.get("name"), info.get("designation"),
       				 info.get("salary"));
       	 }
       	 return new Employee();
    
        }
    
        @WebMethod(operationName = "changeSalary")
        public Message changeSalary(@WebParam(name = "id") String id,
       		 @WebParam(name = "salary") String salary) {
       	 id = id.trim();
       	 if (employees.containsKey(id)) {
       		 Map<String, String> info = new HashMap<>();
       		 info = employees.get(id);
       		 info.put("salary", salary);
       		 return new Message("Successfully updated");
       	 }
       	 return new Message("Employee id is not registered");
    
        }
    
        @WebMethod(operationName = "changeDesignation")
        public Message changeDesignation(@WebParam(name = "id") String id,
       		 @WebParam(name = "designation") String designation) {
       	 id = id.trim();
       	 if (employees.containsKey(id)) {
       		 Map<String, String> info = new HashMap<>();
       		 info = employees.get(id);
       		 info.put("designation", designation);
       		 return new Message("Successfully updated");
       	 }
       	 return new Message("Employee id is not registered");
    
        }
    
    }
    Code Block
    languagejava
    titleEmployee.java
    package com.employee.management.jaxws.beans;
    
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement(name = "Employee")
    public class Employee implements Response {
    
        private String id;
        private String name;
        private String designation;
    
        public Employee(String id, String name, String designation , String salary) {
       	 super();
       	 this.id = id;
       	 this.name = name;
       	 this.designation = designation ;
       	 this.salary = salary;
        }
    
        public Employee() {
       	 this.id = "NS";
       	 this.name = "NS";
       	 this.designation = "NS";
       	 this.salary = "NS";
        }
    
        private String salary;
    
        public String getId() {
       	 return id;
        }
    
        public void setId(String id) {
       	 this.id = id;
        }
    
        public String getName() {
       	 return name;
        }
    
        public void setName(String name) {
       	 this.name = name;
        }
    
        public String getDesignation() {
       	 return designation;
        }
    
        public void setDesignation(String designation) {
       	 this.designation = designation;
        }
    
        public String getSalary() {
       	 return salary;
        }
    
        public void setSalary(String salary) {
       	 this.salary = salary;
        }
    }
    Code Block
    languagejava
    titleMessage.java
    package com.employee.management.jaxws.beans;
    
    public class Message implements Response {
    
        private String message;
    
        public Message(String message) {
       	 super();
       	 this.message = message;
        }
        public String getMessage() {
       	 return message;
        }
    
        public void setMessage(String message) {
       	 this.message = message;
        }
    }
  6. Create a C-App project and deploy it to the Application Server.

...