1

My RESTEasy service does have a method using cookie parameters:

public interface SimpleService
{
  public String test(@CookieParam("param") String param);
}

Now I am trying to use my SimpleService with RESTEasy client framework and it's proxy factory from within my Servlet. However, how can I "forward" the cookie parameters correctly? Right now, I need to manually loop through the request's cookies array and provide the cookie's value manually to the test(..) function call. Reading RESTEasy client framework documentation on http://docs.jboss.org/resteasy/docs/2.3.0.GA/userguide/html/RESTEasy_Client_Framework.html reads:

@CookieParam works the mirror opposite of its server-side counterpart and creates a cookie header to send to the server. You do not need to use @CookieParam if you allocate your own javax.ws.rs.core.Cookie object and pass it as a parameter to a client proxy method. The client framework understands that you are passing a cookie to the server so no extra metadata is needed.

So I am curious what this means for my case? How to properly use RESTEasy client framework & cookie parameters in my servlet?

thanks!

anderswelt
  • 1,482
  • 1
  • 12
  • 23

1 Answers1

1

It's been a while since you asked, and you have probably solved the issue by now, but here's something for future reference:

If you are looking to access cookies sent from the server using the client framework, I think you are stuck with traversing headers (from the ClientResponse as you do today?).

However, if you are looking to understand how the @CookieParam works, using your current interface to make the client, it would be something like this:

SimpleService service = ProxyFactory.create(SimpleService.class, "the://url:to/your/service");
service.test("this text becomes a cookie called 'param' in the request");

That cookie will be available as a String input parameter to the server side implementation.

@Get
@Path("/test")
public String test(@CookieParam("param") cookie) {
    log(cookie); // would print: this text becomes a cookie called 'param' in the request
    return "seems legit";
}

Hope this helps either you, future readers or both!

Paaske
  • 4,345
  • 1
  • 21
  • 33