Showing posts with label annotation in jersey. Show all posts
Showing posts with label annotation in jersey. Show all posts

Saturday, 11 April 2015

HeaderParam Annotation In Jersey


How to Get Value From Header in Jersey

If we want to send any information in header request then we get value of header by using HeaderParam annotation.There is a example how to use @HeaderParam Annotation in jesery


import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

@Path("/user")
public class UserHander {

    @POST
    public Response addUser(@HeaderParam("token") String token) {
        System.out.println("token=" + token);
        return Response.status(Status.OK).entity(token).build();
    }

}

QueryParam Annotation In Jersey



 @QueryParam Annotation In  Jersey

Example:


http://localhost:8080/JerseyDemo/rest/user/12?p=10


@Path("/user")
public class UserHander {

    @GET
    @Path("/{id}")
    public Response addUser(@PathParam("id") int id,@QueryParam("p") int page) {
        System.out.println("id=" + id+"page="+page);
        String str = "id is=" + id+"page="+page;
        return Response.status(Status.OK).entity(str).build();
    }

}

Output:

id is=12page=10