I have code in which one parameter (cookie) can be passed to any of the paths, and I want to process it in the same way:
@Path("/some/path")
public class JaxRsService {
public void doStuff(@CookieParam("cookie") Cookie cookie) {
handleCookie(cookie);
}
public void doStuff2(@CookieParam("cookie") Cookie cookie) {
handleCookie(cookie);
}
public void doStuff3(@CookieParam("cookie") Cookie cookie) {
handleCookie(cookie);
}
}
Is there any way to account for this from each method? I tried to create a setter, but setters are only called at build time, so the cookie is not available.
@Path("/some/path")
public class JaxRsService {
@CookieParam("cookie")
public void setCookie(Cookie cookie) {
cookie
}
}
Similarly, there is an annotation @PostContruct, but it only works at build time.
Adding a cookie as a class variable works fine, but I still have to call the method in every request:
@Path("/some/path")
public class JaxRsService {
@CookieParam("cookie")
Cookie cookie;
public void doStuff() {
handleCookie();
}
public void doStuff2() {
handleCookie();
}
public void doStuff3() {
handleCookie();
}
}
Is there a good way to handle this?
source
share