I am quite new in programming, I am trying to create my first RESTfull API. I have created a server with Apache Tomcat/8.5.37 and I used jersey RESTfull web services. My problem is that class content (XML) is not printed on localhost:8080 using the path http://localhost:8080/JavaAPI/rest/hello
I created a tomcat server and used both JAX-RS 2.0 / Jersey 2.25.x and JAX-RS 2.1 / Jersey 2.26+ in the case of a versioning problem, none of them works. I just cannot think of what could be the problem.
package test;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Application;
@Path("/hello")
public class Hello {
@GET
@Produces(MediaType.TEXT_XML)
public String sayHello(){
String resource ="<? xml version='1.0' ?>" +
"<hello>, Hi, its XML</hello>";
return resource;
}
}
This is the configuration of REST service file:
<display-name>JavaAPI</display-name>
<servlet>
<servlet-name>JAVA 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>JAVA API</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
This is a screenshot of current jersey's library:
The expected outcome should be: , Hi, its XML to be printed on http://localhost:8080/JavaAPI/rest/hello and i get the follow 404 error : Type: Status Report
Message: Not Found
Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Reason why this might not be duplicated question: Firstly, i have copy / pasted their code along with jerseys older version 1.x and the issue still remained. In my experience i believe there is issue on versioning since i have been using Tomcat 8.5 and i also get the following response from server:
The guide that i have followed is : https://www.youtube.com/watch?v=5jQSat1cKMo&t=782s&list=LL2fRfBs2m2v1wyy_kKt8E9w&index=2