On Mar 26, 2010, at 2:35 PM, Marc Hadley wrote:
> You only need to use the GenericEntity incantation if your method's
> return type is Response or something generic like Object. If you
> change the return type to List<AlertData> then you should be OK.
>
Yes, and the filter can add the cache control header. See the JavaDoc
for ContainerResponse.
Paul.
> Marc.
>
> On Mar 25, 2010, at 11:52 PM, Suchitha Koneru (sukoneru) wrote:
>
>> Thanks Paul for the suggestion. I need more clarity in terms of the
>> response filter. If I create a response filter, do I still have to
>> return a "Response" object or can the api return a list
>> (List<AlertData>) ?
>>
>> -----Original Message-----
>> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
>> Sent: Wednesday, March 24, 2010 1:44 AM
>> To: users_at_jersey.dev.java.net
>> Subject: Re: [Jersey] setting headers
>>
>> Hi,
>>
>> You do not need to use an input stream for the second case you can
>> do:
>>
>> return Response.ok(new GenericEntity<List<AlertData>>(list) {},
>> "application/xml").
>> cacheControl(cacheControl).build();
>>
>> but your general point still holds, and i know the above sucks
>> because
>> we failed to make Response generic.
>>
>> You can use a filter:
>>
>>
>> https://jersey.dev.java.net/nonav/apidocs/1.2-SNAPSHOT/jersey/com/sun/je
>> rsey/api/container/filter/package-summary.html
>>
>> If you want to set the cache control header for all resources you can
>> use a response filter. If you want to set the cache control header
>> for
>> specific resources say by declaring your own annotation, e.g.
>> @CacheControl, on a resource method you can use a resource filter
>> that
>> only applies a response filter if @CacheControl is present on a
>> resource method.
>>
>> Paul.
>>
>>
>> On Mar 24, 2010, at 5:37 AM, Suchitha Koneru (sukoneru) wrote:
>>
>>> Hello Jersey Users,
>>> We are using Jersey version 1.1.1-ea . Can we set
>>> headers on response of an API without returning a response object as
>>> shown below. We want to make sure that consumer of restful services
>>> does not cache the content.
>>>
>>> @GET
>>> @Produces ("application/xml")
>>> @Path ("/getNewAlertData/{customerId}/{alertId}")
>>> public List<AlertData>
>>> getNewAlertData(@PathParam("customerId") int
>>> customerId,_at_PathParam("alertId") longalertId) {
>>> List<AlertData> list = null;
>>>
>>>
>>> try {
>>>
>>>
>>> AlertReportSessionBeanLocal sessionBean =
>>> (AlertReportSessionBeanLocal)
>>> JNDIServiceLocator.getInstance().getJndiService("alerts/
>>> AlertReportSessionBean/local");
>>> list = sessionBean.getNewAlertData(customerId,
>>> alertId);
>>>
>>> CacheControl cacheControl = new CacheControl();
>>> cacheControl.setMaxAge(0);
>>>
>>> Response.ResponseBuilder builder = Response.ok();
>>> builder.cacheControl(cacheControl);
>>>
>>>
>>> } catch (Exception NamingException) {
>>> NamingException.printStackTrace();
>>> throw new NotFoundException("Invalid request");
>>> }
>>>
>>> return list;
>>> }
>>>
>>>
>>> We tried the above code and it did not work. We do not want to
>>> change the signature of the API and the code such that it returns a
>>> response object
>>>
>>> i.e.
>>>
>>> public Response getNewAlertData(@PathParam("customerId") int
>>> customerId,_at_PathParam("alertId") long alertId) {
>>>
>>> try {
>>>
>>>
>>>
>>> AlertReportSessionBeanLocal sessionBean =
>>> (AlertReportSessionBeanLocal)
>>> JNDIServiceLocator.getInstance().getJndiService("alerts/
>>> AlertReportSessionBean/local");
>>> list = sessionBean.getNewAlertData(customerId,
>>> alertId);
>>>
>>> InputStream is = getStream(list);
>>>
>>> CacheControl cacheControl = new CacheControl();
>>> cacheControl.setMaxAge(0);
>>>
>>> Response.ResponseBuilder builder = Response.ok(is, "application/
>>> xml");
>>> builder.cacheControl(cacheControl);
>>>
>>>
>>> } catch (Exception NamingException) {
>>> NamingException.printStackTrace();
>>> throw new NotFoundException("Invalid request");
>>> }
>>>
>>> return builder.build();
>>>
>>>
>>> }
>>>
>>> Is there a way to achieve this without returning a response
>>> object ? Can we set headers at the service level rather than at
>>> the API level , so that
>>> All the apis in the restful service can use the same headers. Could
>>> you please let me know,
>>>
>>> Thanks,
>>> Suchitha
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>