cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: Storing response before dispatch
Date Mon, 18 Jun 2012 09:04:47 GMT
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

Mime
View raw message