rest - HTTP CacheControl with Jersey and json implementation -
i want add cachecontrol intormation service use json binding. found add cachecontrol response rest service sound this:
@get @path("cacheheadertest") @produces({"*/*"}) def testcache():javax.ws.rs.core.response { val rb:response.responsebuilder = javax.ws.rs.core.response.ok("chached test message") val cc = new cachecontrol() cc.setmaxage(60) cc.setnocache(false) rb.cachecontrol(cc).build() }
but have rest service produce json messages , jersey library transform automaticcally java object java xml/json.
@get @path("jsontestcache") @produces(array(mediatype.application_json, mediatype.application_xml)) def myjsontestservice(@headerparam("x-tokenid") tokenid: string, @queryparam("clientid") clientid: string):com.test.myresultclass = { val response= new com.test.myresultclass [...] response }
how can add cache control response of myjsontestservice service? need use filter , append cachecontrol once response has been created jersey? million flavio
you still need return response object.
def somejson() : response = { val builder = response.ok(new com.test.myresultclass); val cc = new cachecontrol() cc.setmaxage(60) cc.setnocache(false) builder.cachecontrol(cc).build() }
jersey's interceptors automatically convert class json object.
Comments
Post a Comment