You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Stefan Funk <st...@daasi.de> on 2012/03/01 23:47:11 UTC

Caching MTOM attachments and working with cached DataHandler

Hi dear list,

I am using MTOM to transfer data to my service, and it works just fine. I
now would like to cache the attachment so I am able to work with a cached
input stream, to rewind the stream and use it as often as I like (for I am
writing the data to different databases one after another, so I need the
data more than once, but I do not want to keep everything in memory).

I do set in my beans.xml the following:

<jaxws:properties>
	<entry key="mtom-enabled" value="true" />
	<entry key="attachment-directory" value="/data/tmp/" />
	<entry key="attachment-memory-threshold" value="0" />
</jaxws:properties>

I also tried to set -Dorg.apache.cxf.io.CachedOutputStream.Threshold=0
-Dorg.apache.cxf.io.CachedOutputStream.OutputDirectory=/data/tmp/ at Tomcat
start.

/data/tmp is writable for my tomcat-user, but there is no data written to
/data/tmp/ when the service is getting data from the client. My CXF version
is 2.5.2.

Am I misconfiguring something? Maybe I get a cached input stream
automatically if I get the caching running? Maybe someone has an short
answer to this or just point to some existing post (I didn't find...).

Thank you very much and good night!
Stefan.

--
View this message in context: http://cxf.547215.n5.nabble.com/Caching-MTOM-attachments-and-working-with-cached-DataHandler-tp5529487p5529487.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Caching MTOM attachments and working with cached DataHandler

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday, April 25, 2012 04:36:46 AM Stefan Funk wrote:
> Found a bug?
> 
> If I do a realease like this:
> 
> void release(DataSource ds) throws IOException {
>   AttachmentDataSource ads = getAttachmentDataSource(ds);
>   if (ads != null) {
>    // tell attachment to hold the temporary file;
>    ads.release();
>   }
>  }
> 
> and the ads.isCached() is false, I get an exception... would that be to
> catch in the AttachmentDataSource class?

I guess a n NPE guard there would be OK.   Feel free to file a bug.  That 
said, the release() call is really meant to only be paired with a hold() 
call that would make sure the cache is there.   If hold() wasn't called, 
then release doesn't really make sense.

Dan


> Stefan.
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Caching-MTOM-attachments-and-working-with
> -cached-DataHandler-tp5529487p5664591.html Sent from the cxf-user mailing
> list archive at Nabble.com.
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Caching MTOM attachments and working with cached DataHandler

Posted by Stefan Funk <st...@daasi.de>.
Found a bug?

If I do a realease like this:

void release(DataSource ds) throws IOException {
  AttachmentDataSource ads = getAttachmentDataSource(ds);
  if (ads != null) {
   // tell attachment to hold the temporary file;
   ads.release();
  }
 }

and the ads.isCached() is false, I get an exception... would that be to
catch in the AttachmentDataSource class?
Stefan.

--
View this message in context: http://cxf.547215.n5.nabble.com/Caching-MTOM-attachments-and-working-with-cached-DataHandler-tp5529487p5664591.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Caching MTOM attachments and working with cached DataHandler

Posted by Stefan Funk <st...@daasi.de>.
Hi there.

So I am gladly responsing to myself :-) I found the solution just yesterday
in another blog post:

You just have to hold the DataSource (ds) using ds.hold(), to prevent the
CXF to remove the cached file. So you can use the stream over and over again
(without resetting it), and it is deleted from the cache temp dir only after
you released it via ds.release().

Simple! Here the URL to the post I found:
http://ext2xhb.wordpress.com/2011/06/08/using-cxf-attachment-safely/

Thanks!
Stefan.

--
View this message in context: http://cxf.547215.n5.nabble.com/Caching-MTOM-attachments-and-working-with-cached-DataHandler-tp5529487p5664385.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Caching MTOM attachments and working with cached DataHandler

Posted by Stefan Funk <st...@daasi.de>.
Hi there,

now I am coming back to this. Caching is now working, but do I get a cached
Stream out of my DataHandler then so that I can reset the stream and process
it again?

I just want to process that stream more then once to write it to several
databases and filesystems, and other processes. I tried working with TEE-
and Copy-Streams, but that is not really working nicely...

Thanks a lot for any input on this.
Stefan.

--
View this message in context: http://cxf.547215.n5.nabble.com/Caching-MTOM-attachments-and-working-with-cached-DataHandler-tp5529487p5662127.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Caching MTOM attachments and working with cached DataHandler

Posted by Stefan Funk <st...@daasi.de>.
...and if that does work, I have got a rewindabe stream to work with?

Bon appetit (it's nearly dinner time :-) ... )
f.

--
View this message in context: http://cxf.547215.n5.nabble.com/Caching-MTOM-attachments-and-working-with-cached-DataHandler-tp5529487p5535643.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Caching MTOM attachments and working with cached DataHandler

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 01/03/12 22:47, Stefan Funk wrote:
> Hi dear list,
>
> I am using MTOM to transfer data to my service, and it works just fine. I
> now would like to cache the attachment so I am able to work with a cached
> input stream, to rewind the stream and use it as often as I like (for I am
> writing the data to different databases one after another, so I need the
> data more than once, but I do not want to keep everything in memory).
>
> I do set in my beans.xml the following:
>
> <jaxws:properties>
> 	<entry key="mtom-enabled" value="true" />
> 	<entry key="attachment-directory" value="/data/tmp/" />
> 	<entry key="attachment-memory-threshold" value="0" />
> </jaxws:properties>
>
> I also tried to set -Dorg.apache.cxf.io.CachedOutputStream.Threshold=0
> -Dorg.apache.cxf.io.CachedOutputStream.OutputDirectory=/data/tmp/ at Tomcat
> start.
>
> /data/tmp is writable for my tomcat-user, but there is no data written to
> /data/tmp/ when the service is getting data from the client. My CXF version
> is 2.5.2.
>
> Am I misconfiguring something? Maybe I get a cached input stream
> automatically if I get the caching running? Maybe someone has an short
> answer to this or just point to some existing post (I didn't find...).
>

I looked at the source, CachedOutputStream defaults to a 64K threshold 
if the configuration value is <= 0, so setting it to '1' or some other 
small value should do for all the parts

Cheers, Sergey

> Thank you very much and good night!
> Stefan.
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Caching-MTOM-attachments-and-working-with-cached-DataHandler-tp5529487p5529487.html
> Sent from the cxf-user mailing list archive at Nabble.com.