Skip to content

Commit

Permalink
Ensure that JAX-RS Cookie parameter type is usable in Resource methods
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand authored and tmihalac committed Oct 27, 2022
1 parent 404941f commit c996ea2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
@@ -1,17 +1,26 @@
package org.jboss.resteasy.reactive.server.core.parameters;

import javax.ws.rs.core.Cookie;

import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;

public class CookieParamExtractor implements ParameterExtractor {

private final String name;
private final String parameterTypeName;

public CookieParamExtractor(String name) {
public CookieParamExtractor(String name, String parameterTypeName) {
this.name = name;
this.parameterTypeName = parameterTypeName;
}

@Override
public Object extractParameter(ResteasyReactiveRequestContext context) {
if (Cookie.class.getName().equals(parameterTypeName)) {
// we need to make sure we preserve the name because otherwise CookieHeaderDelegate will not be able to convert back to Cookie
Cookie cookie = context.getHttpHeaders().getCookies().get(name);
return cookie != null ? cookie.toString() : null;
}
return context.getCookieParameter(name);
}
}
Expand Up @@ -626,7 +626,7 @@ public ParameterExtractor parameterExtractor(Map<String, Integer> pathParameterI
case HEADER:
return new HeaderParamExtractor(name, single);
case COOKIE:
return new CookieParamExtractor(name);
return new CookieParamExtractor(name, javaType);
case FORM:
return new FormParamExtractor(name, single, encoded);
case PATH:
Expand Down
Expand Up @@ -9,6 +9,7 @@
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
Expand Down Expand Up @@ -53,12 +54,14 @@ public String params(@RestPath String p,
@RestHeader("") String paramEmpty,
@RestForm String f,
@RestMatrix String m,
@RestCookie String c) {
@RestCookie String c,
@RestCookie("c") Cookie cookie) {
return "params: p: " + p + ", q: " + q + ", h: " + h + ", xMyHeader: " + xMyHeader + ", testHeaderParam: "
+ testHeaderParam + ", paramEmpty: "
+ paramEmpty + ", f: " + f + ", m: " + m + ", c: "
+ c + ", q2: "
+ q2.orElse("empty") + ", q3: " + q3.orElse(-1);
+ paramEmpty + ", f: " + f + ", m: " + m
+ ", c: " + c
+ ", c2: " + cookie.getValue()
+ ", q2: " + q2.orElse("empty") + ", q3: " + q3.orElse(-1);
}

@Blocking
Expand Down
Expand Up @@ -433,7 +433,7 @@ public void testNewParams() {
.log().ifError()
.body(Matchers
.equalTo(
"params: p: pv, q: qv, h: 123, xMyHeader: test, testHeaderParam: test, paramEmpty: empty, f: fv, m: mv, c: cv, q2: empty, q3: 999"));
"params: p: pv, q: qv, h: 123, xMyHeader: test, testHeaderParam: test, paramEmpty: empty, f: fv, m: mv, c: cv, c2: cv, q2: empty, q3: 999"));
RestAssured.get("/new-params/myklass/myregex/sse")
.then()
.log().ifError()
Expand Down

0 comments on commit c996ea2

Please sign in to comment.