0

The code i am trying is showing Null pointer Exception because it is not extracting parameter value from path and i am not getting why? if any one could help me out with this ??

The path value extracted from pathparam i.e is name is extracted as null and why this is happening am not getting please help me out with the same.

I am not getting at all what the problem actually is I tried and I only got that parameter value for name is not getting extracted in path param, I checked out on the different sites still am not able to get the solution. I hope posting over here helps me to find a solution

My resource class is:

package resource; import javax.websocket.server.PathParam; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import dao.CustomerDao; import dao.CustomerDaoImpl; import entity.Customer; @Path("/customer") public class CustomerResource { CustomerDaoImpl dao = new CustomerDaoImpl(); @GET @Path("/greet") public String greet(){ return("Hello World"); } @GET @Path("/{name}") public String getCustomerByName(@PathParam("name") String name){ System.out.println("the name is : "+name); return dao.getCustomerByName(name).toString(); } } 

and service class is below:

package dao; import java.util.ArrayList; import java.util.List; import entity.Customer; public class CustomerDaoImpl implements CustomerDao { static private List<Customer> customerList = new ArrayList<Customer>(); static { customerList.add(new Customer("John",101,"7757945607")); customerList.add(new Customer("Joe", 102,"8857833518")); customerList.add(new Customer("James",103,"8177998482")); customerList.add(new Customer("Roy",104,"8149038984")); customerList.add(new Customer("Dev",105,"9503257180")); } @Override public Customer getCustomerByName(String name) { for (Customer c : customerList) { if (c.getCustomerName().equalsIgnoreCase(name)) { return c; } } return null; } } 

although i am using the correct path

http://localhost:8080/CustomerWebApp/rest/customer/Roy 
0

2 Answers 2

3

You are using the wrong PathParam. You should use javax.ws.rs.PathParam.

Sign up to request clarification or add additional context in comments.

Comments

1

yes PathParam you have to use provided by jar-rs specification . you have used wrong one javax.websocket.server.PathParam; for more Details how to use @PathParam and @path annotation plz refer:http://entityclass.in/rest/jaxRsAnnotationPath.htm

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.