blogger templates blogger widgets
This is part of a list of blog posts.
To browse the contents go to

JAX-RS: Sending/Receiving cookies

Server code,
@Path("/hello")
public class HelloResource {
    @GET
    public Response helloGet(@javax.ws.rs.CookieParam("username") String username) {
      return Response.ok("[GET] Hello "+username+" from JAX-RS on WebSphere Application server")
                 .cookie(new NewCookie("key","value"))
                 .build();
    }
}

Client code,
String lsUrl = "http://localhost:9080/RSServer/HelloApp/hello";
RestClient client = new RestClient();
Resource resource = client.resource(lsUrl);
ClientResponse result = resource.contentType(MediaType.TEXT_PLAIN).cookie(new Cookie("username", "John")).get();
System.out.println(result.getEntity(String.class));

To obtain a general map of parameter names and values for query and path parameters, use the following code:
@GET
public String get(@Context UriInfo ui) {
    MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
    MultivaluedMap<String, String> pathParams = ui.getPathParameters();
}

No comments:

Post a Comment