I have created a simple java restAPi in eclipse as dynamic web project. I am attempting to POST from the POSTMAN to the same endpoint(that I am doing GET) but I get 405 response code.
The web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>JsonJavaApi</display-name>
<servlet>
<servlet-name>Book API</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>test</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Book API</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
The Book class:
public class Book {
public String author;
public String name;
public Book(String author, String name) {
super();
this.author=author;
this.name=name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Book() {
super();
}
}
The restapi code:
@Path("/jason")
public class JavajsonRestApi {
@GET
@Path("/json")
@Produces(MediaType.APPLICATION_JSON)
public Book getJson() {
Book book = new Book();
book.setAuthor("eswar");
book.setName("eswar");
return book;
}
}
The endpoint :
As I understand it, the permission to post is not given to this end point but how to do I give it such that the client side can post from the body itself, this helps get rid of the 405 error?
Any help is appreciated.