I am developing a REST Web Service
application but while using REST Client POSTMAN
the Body tab is showing disabled.
I have created a class named EmployeeController which handles the URI call as is shown below:
package com.Employee;
@Path("/response")
public class EmployeeController {
EmployeeService employeeService = new EmployeeService();
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAllEmployee(){
List<Employee> emp = employeeService.getAllEmployee();
return Response.status(Status.CREATED).entity(emp).build();
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addEmployee(Employee emp){
Employee e = employeeService.addEmployee(emp);
return Response.status(Status.CREATED).entity(emp).build();
}
}
The method getAllEmployee() retrieves all the details of the employees and the method addEmployee() add the employee.
Following changes have been made in web.xml
file:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>RestPathAnnotationExample</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.Employee</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
In POM.xml have added two maven dependencies: jersey-server and jersey-json.
Is there any issue in the code due to which the Body part in POSTMAN is disabled?