Tuesday, October 27, 2015

Example for Path Parameters in RESTFul web services using JAX-RS

package per.sample.rest.service;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import per.sample.rest.exception.CustomException;


@Path("/hello")
public class HelloWorldService {
      @GET
   @Produces(MediaType.TEXT_PLAIN)
   @Path("/PathParam/{name}")
   public String sayPlainTextHello(@PathParam("name") String userName)  {
    if(userName == null || userName.isEmpty())
     throw new CustomException("Invalid input");
     return "Response for test PathParam Test method    :   "+userName ;
   }
  
  
 
}

No comments:

Post a Comment