-1

I just started JAX-RS (Jersey) for my RESTful web API. Tomcat runs normally but root url returns 404 again and root/api a blank page when accessed on my web browser.

The set-up was the same as my previous question. After the previous question was solved I successfully accessed the root url (http://localhost:8080/com.G8.ws) and http://localhost:8080/com.G8.ws/api/v1/status.

package com.G8.ws;


import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/v1/status")
public class V1_status {

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String returnTitle(){
        return "<p>RESTful Web API using JAX/RS</p>";
    }

}

On the browser from the eclipse, http://localhost:8080/com.G8.ws/api is not even accessible through Tomcat ("The webpage cannot be found"), and all other two pages give 404 error.

What might be the reason? I did not change anything after I saved last time.

Community
  • 1
  • 1
jsh6303
  • 2,010
  • 3
  • 24
  • 50

1 Answers1

0

Why do you think there should be anything at /api?

You do not have any @Path routes defined to anything other than /v1/status on the class.

Any methods without any routes defined default to the route on the class.

Explaining in detail how to use JAX-RS annotations and configure Jersey is completely out of scope for StackOverflow. Your questions and comments make it really clear that you have not read the documentation and do not know how to correctly apply the annotations and configure Jersey.

You need to stop, go back and read the JAX-RS documentation from beginning to end and then start again.

Community
  • 1
  • 1
  • The "/api*" is defined in the servlet. Still if I access "/v1/status" I get the 404 error. – jsh6303 Oct 05 '15 at 16:51
  • read for comprehension, you are not doing it correctly, there is no `@Path` annotation for `/api` you think you know what you are doing and you have not read the JAX-RS documenation –  Oct 05 '15 at 16:52
  • I accessed /api/v1/status last time successfully and I was trying to find out why this time it does not. – jsh6303 Oct 05 '15 at 16:56
  • there is no provider configured at `/api` so there is nothing there, **go read the documentation on Jersey on how to configure it correctly** –  Oct 05 '15 at 16:58
  • But the point is, even if I change the servlet url pattern from `/api/*` to `/*` the same error still occurs. – jsh6303 Oct 05 '15 at 17:00
  • you have not read on how to configure Jersey, you assume you know what you are doing and you do not, you do not configure the servlet stuff in the `web.xml` to do what you want. **Go read the Jersey documentation for yourself instead of relying on people to spoon feed you solutions you do not comprehend because you did not do the work** –  Oct 05 '15 at 17:12