com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

JAX-WS Employee Management Service Sample

This page walks you through developing, deploying and testing a sample JAX-WS employee management service using Developer Studio. It includes the following sections:

Sample Scenario

This sample is about how to store and distribute employee information as a service for a company. In this sample service, information is stored in a HashMap. It is possible to register an employee, get information using the employee ID and update or modify information.

Implementing the service

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


     
  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. 


     
  4. Click Finish. The project structure is created with a simple hello operation. 


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

     

    EmployeeManagementService.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");
    
        }
    
    }
    Employee.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;
        }
    }
    Message.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.

Testing the service

You can test the sample service using SoapUI.

  1. Create a new SoapUI project pointing to the WSDL URL. 
  2. Test the operations for registering an employee, update/modify and get information, as shown below:

     

     

     
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.