Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that JAX-RS Cookie parameter type is usable in Resource methods #28464

Merged
merged 1 commit into from Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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