Search code examples
javajax-rsresteasy

Resteasy Client: @CookieParam replicates its value on every request


I have a Resteasy Client Implementation with an Interface that uses @CookieParam. The first Clientrequests adds the cookie as expected, the second adds the same value again, instead of checking if it already exists and doing some kind of replacement of the value. The same does the third and so on. This never ends and the cookie gets bigger on every request.

What would be the solution if the cookie value should be added only once?

My interace of the provided server service (which is not under my controll) looks like this. I've just written it to make it possible to use Reast Easy Proxyclient in my client implementation:

@POST
@Path("/my-resource")
@Produces(CustomMediaType.APPLICATION_JSON_UTF_8)
@Consumes(CustomMediaType.APPLICATION_JSON_UTF_8)
Response createResource(@CookieParam("my-cookie") String cookie, Request request);

Solution

  • Simply add the cookie only if 'my-cookie' is null. Then you will not duplicate the same cookie.