diff --git a/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java b/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java index 2992115c44..ea215e7051 100644 --- a/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java +++ b/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java @@ -262,14 +262,15 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg } } else { if (!(value instanceof Cookie)) { - cookies.add(new Cookie(name, value.toString())); + c = new Cookie(name, value.toString()); } else { c = (Cookie) value; if (!name.equals(((Cookie) value).getName())) { // is this the right thing to do? or should I fail? or ignore the difference? - cookies.add(new Cookie(name, c.getValue(), c.getPath(), c.getDomain(), c.getVersion())); + c = new Cookie(name, c.getValue(), c.getPath(), c.getDomain(), c.getVersion()); } } + cookies.add(c); } } else if ((ann = anns.get((MatrixParam.class))) != null) { if (value instanceof Collection) { diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java index 86b1254308..e1970d2a52 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java @@ -41,6 +41,7 @@ package org.glassfish.jersey.client.proxy; import javax.ws.rs.core.Context; +import javax.ws.rs.core.Cookie; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; @@ -82,6 +83,11 @@ public String getByNameCookie(String name) { return name; } + @Override + public String getByNameCookie(Cookie cookie) { + return cookie.getValue(); + } + @Override public String getByNameHeader(String name) { return name; diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java index 9d7a07ff83..6e57ac1bdd 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java @@ -57,6 +57,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; +import javax.ws.rs.core.Cookie; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; @@ -92,6 +93,11 @@ public interface MyResourceIfc { @Produces(MediaType.TEXT_PLAIN) String getByNameCookie(@CookieParam("cookie-name") String name); + @Path("cookie-object") + @GET + @Produces(MediaType.TEXT_PLAIN) + String getByNameCookie(@CookieParam("cookie-name") Cookie cookie); + @Path("header") @GET @Produces(MediaType.TEXT_PLAIN) diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java index f7ccfcf85f..3da452958a 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java @@ -137,6 +137,16 @@ public void testCookieParam() { assertEquals("jiri", resource.getByNameCookie("jiri")); } + @Test + public void testCookieParamAsCookie() { + assertEquals("cocobey", resource.getByNameCookie(new Cookie("cookie-name", "cocobey"))); + } + + @Test + public void testCookieParamAsCookieWithWrongName() { + assertEquals("cocobey", resource.getByNameCookie(new Cookie("wrong-name", "cocobey"))); + } + @Test public void testHeaderParam() { assertEquals("jiri", resource.getByNameHeader("jiri"));