@GET @Path("cookies/{cookieName}") @Produces("text/plain") public String getCookies( @Context HttpHeaders headers, @PathParam("cookieName") String cookieName) { final Map<String, Cookie> cookies = headers.getCookies(); try { cookies.put("notAllowed", new Cookie("notAllowed", "value")); throw new WebApplicationException( Response.serverError().entity("could add cookie notAllowed").build()); } catch (UnsupportedOperationException uoe) { // not allowed } try { cookies.put("xyz", new Cookie("notAllowed", "value")); throw new WebApplicationException(Response.serverError().entity("could add xyz").build()); } catch (UnsupportedOperationException uoe) { // not allowed } final Cookie cookie = cookies.get(cookieName); if (cookie == null) { return null; } return cookie.toString(); }
/** {@inheritDoc} */ public Client cookie(Cookie cookie) { possiblyAddHeader(HttpHeaders.COOKIE, cookie.toString()); return this; }