Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What am I doing wrong in this jersey Java class?

Here is the class :-

 package com.bablo.rest;

 import javax.websocket.server.PathParam;
 import javax.ws.rs.Path;

 @Path("/")
 public class Library {
   @Produces("text/plain") 
   @Path("/books/{name}")
   public String getBook(@PathParam("name") String name){
     System.out.println(name);
      return "My Name is Anthony Goncalves";
  }
}

Its giving this as error

A sub-resource locator, public java.lang.String com.bablo.rest.Library.geBook(java.lang.String), can not have an entity parameter. Try to move the parameter to the corresponding resource method.

and

Missing dependency for method public java.lang.String com.bablo.rest.Library.getBook(java.lang.String) at parameter at index 0

I am invoking this webservice through the Browser like this

     http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo

Also I am doing curl:

     curl -X GET http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo
like image 749
John Doe Avatar asked Dec 08 '22 06:12

John Doe


2 Answers

You need to add tag either @POST or @GET above your method.

like image 109
Gilbert PeMo Avatar answered Dec 11 '22 10:12

Gilbert PeMo


I believe you meant to use

javax.ws.rs.PathParam

rather than

javax.websocket.server.PathParam
like image 40
Sotirios Delimanolis Avatar answered Dec 11 '22 10:12

Sotirios Delimanolis