java - How do I return a cookie from a jax-rs / rest-easy enabled method that returns a pojo -
java - How do I return a cookie from a jax-rs / rest-easy enabled method that returns a pojo -
i have create alter javax-rs web app written else. used doing things long winded way, , javax-rs new me.the function looks this:
@post @path("mypath1/mypath2") @consumes("application/json") @produces("application/json") public mymethod(b myb, @context final httpservletresponse response) { mya = new a(); ... homecoming mya; }
a pojo, guess getting converted json @ point in process.
one thing should add together rest-easy framework involved. guess what's doing pojo json conversion.
i need check cookie , take action if found. want homecoming cookie if request did not have one. reading of cookie seems easy plenty - add together method signature:
@cookieparam("mycookiekey") string mycookievalue
my confusion examples see on web show methods returning response, 1 returns pojo - how cookie response? thought response.addcookie(...) [where response httpservletresponse passed method] in normal long-winded way, see on web way homecoming cookie in javax-rs little different, thought should maybe doing this:
newcookie newcookie = new newcookie("mycookiekey", "mycookievalue"); responsebuilder builder = response.ok(mya, mediatype.application_json); response r = builder.cookie(newcookie).build(); homecoming r;
but returning response, , whatever invokes method expecting object of type returned.
so guess question is, can still homecoming object of type method , yet have cookie returned client?
thanks,
paul
it's ok homecoming response instead of actual entity, because json it's converted same in both cases in http response, although in first case converted implicitly, while in 2nd manually. snippet correct, believe.
java jax-rs resteasy
Comments
Post a Comment