Well,

I can not use filter as in my case cache is authenticated cache and
security layer is a cxf interceptor.

However good news is, I am able to store the message following the
pattern of LoggingOutInterceptor for cxf code base.

Now I am stuck at a point where either I just want to send http status
304 or load message from cacahe.

I am doing following without any avail. Your insights will be appreciated.

OutputStream os = message.getContent(OutputStream.class);
            /*if (os == null) {
                LOG.debug("Outputstream with message was null");
        
            }*/
           byte[] content=this.cachePage.getBody();
           ByteArrayOutputStream baos=new ByteArrayOutputStream();
           baos.write(content, 0, content.length);
           LOG.debug("Setting up the content outputstream");
           message.setContent(OutputStream.class, baos);

However it does not provide any output at client end.

Thank you.
rn

On Mon, Jun 18, 2012 at 5:04 AM, Sergey Beryozkin <[email protected]> wrote:
> Hi
>
> On 15/06/12 04:00, rangeli nepal wrote:
>>
>> Good Evening Gentlemen,
>>
>> I am trying to store response before it gets dispatched so that it can
>> be used for caching. I am not sure how to do it.
>>
>> I am planning to implement ResponseHandler.
>>
>> 1. One way to get response content is to call response.getEntity().
>> However this just gives jaxb object that it is carrying.
>>
>
> That should work,
>
>
>> 2. Other way I can think of is
>>
>> final OutputStream os = message.getContent(OutputStream.class);
>>        if (os == null) {
>>                LOG.debug("Outputstream with message was null");
>>            return;
>>        }
>>        final CacheAndWriteOutputStream newOut = new
>> CacheAndWriteOutputStream(os);
>>        message.setContent(OutputStream.class, newOut);
>>        StringBuilder builder=new StringBuilder();
>>        newOut.writeCacheTo(builder, "UTF-8");
>>                //ObjectConverter objectConverter=new ObjectConverter();
>>                byte[] content=builder.toString().getBytes("UTF-8");
>>
>> However this is giving me empty content.
>>
> The runtime writes to the output stream after the response handler has been
> processed.
>
>
>> What I am missing ? and What is the standard way to do it.
>
>
> I think the 1st option will do, alternatively consider using ehcache or
> similar framework:
> http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-Serversidecaching
>
> Cheers, Sergey
>>
>>
>> Thank you.
>> Santos
>
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com

Reply via email to