2

Please see codes below. I can visit http://localhost:8080/messengerdemo/messages and interact with all the APIs but every time I access http://localhost:8080/messengerdemo/profiles I got a 404 not found error. What did I do wrong? I am a beginner and trying to learn jersey and REST API.

web.xml

  <servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>org.learn.rest.messengerdemo.resources</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Message resources

@Path("/messages")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class MessageResource {
   MessageService messageService = new MessageService();

   @GET
   public List<Message> getMessages() {
      return messageService.getAllMessages();
   }
}

Profile resources.

@Path("/profiles")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ProfileResource {

   private ProfileService profileservice = new ProfileService();

   @GET
   public List<Profile> getAllProfiles() {
      return profileservice.getAllProfiles();
   }
}
Opal
  • 81,889
  • 28
  • 189
  • 210
Ralf Zhang
  • 171
  • 1
  • 2
  • 4

1 Answers1

1

After deleting all the related class and recreated them. It all worked.

I guess it is because I didn't check if the Content-Type is set to be application/json within my REST client tool.

Opal
  • 81,889
  • 28
  • 189
  • 210
Ralf Zhang
  • 171
  • 1
  • 2
  • 4