Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Ensure cookie is added to request when Cookie object name matches annotation name #3754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down