I'm very new to Java, I'm attempting to create a very simple Rest API to return a string via a GET method. I've been through countless tutorials, but each time I get the above error using my project
url - http://localhost:8080/orchestrator/api/service/status
I'm using the ApplicationConfig.java - ApplicationPath file to denote the mapping:
@javax.ws.rs.ApplicationPath("/api")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
addRestResourceClasses(resources);
return resources;
}
/**
* Do not modify addRestResourceClasses() method.
* It is automatically populated with
* all resources defined in the project.
* If required, comment out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(com.orchestrator.Services.class);
} }
Using Netbeans 12.6 with Tomcat via XAMPP v3.3.0; I have a web.xml but apparently I don't need it as I'm using the ApplicationConfig.java, but I'll post the one I made.
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>.com.sun.jerysey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.orchestrator.Services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
Services.java
@Path("/service")
public class Services {
@Context
private UriInfo context;
public Services() {
}
@Path("/status")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getHtml() {
//TODO return proper representation object
return "connected";
}
}
Project Structure: image of folder structure
What am I missing to return the "connected" text, I've also tried using postman as well to return, same result.
Regards