Return-Path: Delivered-To: apmail-cxf-users-archive@www.apache.org Received: (qmail 16522 invoked from network); 28 Jul 2009 15:57:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Jul 2009 15:57:30 -0000 Received: (qmail 41541 invoked by uid 500); 28 Jul 2009 15:51:27 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 41454 invoked by uid 500); 28 Jul 2009 15:51:27 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 41444 invoked by uid 99); 28 Jul 2009 15:51:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jul 2009 15:51:27 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.40.44.209] (HELO smtprelay.hostedemail.com) (216.40.44.209) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jul 2009 15:51:16 +0000 Received: from filter.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtprelay01.hostedemail.com (Postfix) with SMTP id DB36173DC54 for ; Tue, 28 Jul 2009 15:50:55 +0000 (UTC) X-Spam-Summary: 50,0,0,6cd7c0b39d49b5a9,d41d8cd98f00b204,dkulp@apache.org,users@cxf.apache.org:dp-isp@csi.it,RULES_HIT:355:379:599:601:967:973:980:988:989:1260:1277:1311:1312:1313:1314:1345:1359:1437:1515:1516:1518:1519:1534:1543:1593:1594:1595:1596:1605:1711:1730:1747:1766:1792:2198:2199:2393:2525:2553:2560:2563:2682:2685:2693:2828:2857:2859:2900:2902:2914:2933:2937:2939:2942:2945:2947:2951:2954:3022:3027:3865:3866:3867:3868:3869:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:5007:6119:6261:7679:7901:7903:7904:8550:8828:8829:8957:8985:9025:9388:10004,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fu,MSBL:none,DNSBL:none,Custom_rules:0:0:0 X-Session-Marker: 64616E406B756C702E636F6D X-Filterd-Recvd-Size: 4849 Received: from server.dankulp.com (server1.dankulp.com [66.207.172.168]) (Authenticated sender: dan@kulp.com) by omf05.hostedemail.com (Postfix) with ESMTP for ; Tue, 28 Jul 2009 15:50:55 +0000 (UTC) Received: by server.dankulp.com (Postfix, from userid 5000) id 4DFCA507003B; Tue, 28 Jul 2009 11:50:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.2.1-gr1 (2007-05-02) on server.dankulp.com X-Spam-Level: X-Msg-File: /tmp/mailfilter.bNhbG1NAWp Received: from dilbert.localnet (c-24-91-141-225.hsd1.ma.comcast.net [24.91.141.225]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server.dankulp.com (Postfix) with ESMTPSA id 442985070038; Tue, 28 Jul 2009 11:50:52 -0400 (EDT) From: Daniel Kulp To: users@cxf.apache.org Subject: Re: Streaming large attachments by linking input and output stream avoiding temp files Date: Tue, 28 Jul 2009 11:50:47 -0400 User-Agent: KMail/1.11.4 (Linux/2.6.30-gentoo-r1; KDE/4.2.4; x86_64; ; ) Cc: "dp-isp" References: <24677330.post@talk.nabble.com> In-Reply-To: <24677330.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907281150.48105.dkulp@apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-3.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=unavailable version=3.2.1-gr1 Well, I THOUGHT this would have been easily doable, but when I checked, it turns out the attachments were not streaming properly in MTOM mode. :-( I've gone through and fixed a BUNCH of things related to the attachment handling and streaming and such so some of this is now possible. Now, with the latest code, when you get the DataSource, if at all possible, the input stream that is returned will properly be streaming off the wire instead of cached. Thus, you can copy directly from there to the output stream. There are cases where this WON'T work stream directly, notably when schema validation is turned on. In that case, to work around issues in JAXB, we buffer the content. Also, if there are multiple attachments, only the last one can really be streamed this way. The others get buffered. Dan On Mon July 27 2009 5:50:00 am dp-isp wrote: > Hello everybody, > > We have a CXF webservice that is a kind of "repository service" and a > webapp working as frontend for that repository. > Those two components are on separate hosts. > > We would need to realize a continuous stream of data when downloading > attachments from CXF webservice to the users' browser through the frontend > webapp. > > The webapp is basically a servlet that invokes the webservice, receives the > attachment datahandler and copies datahandler InputStream to servlet > response OutputStream (servlet code is at the end of this email). > > Our issue: is it possible to directly link datahandler InputStream to > servlet response OutputStream without re-building the whole attachment in > memoroy or in a temporary file? (as can be configured by setting > org.apache.cxf.io.CachedOutputStream.Threshold, > org.apache.cxf.io.CachedOutputStream.OutputDirectory) > > Going more into details, is there a way to send to CXF the output buffer to > write the attachment on? In such case we would send to CXF the sevlet's > output buffer. > > Alternatively, is there a way to manage CXF working asynchronously with > attachments, giving back control to the servlet before attachment downolad > completion? > > Many thanks, > Marco > > --- > > This is the servlet's involved code: > > ... > StreamingService_Service ss = new StreamingService_Service(new > URL(serviceURL)); > StreamingService port = ss.getServiceImplPort(new MTOMFeature()); > > Resume myFile = port.downloadMethod(fileName, fileType, usr, pwd, repo); > DataHandler handler = myFile.getResume(); > > response.setHeader("Pragma", "No-cache"); > response.setContentType("application/octet-stream"); > response.setHeader("content-disposition", "attachment; filename=" + > fileName + "." + fileType); > try { > InputStream is = handler.getInputStream(); > try { > OutputStream os = response.getOutputStream(); > try { > byte[] b = new byte[100000]; > int bytesRead = 0; > while ((bytesRead = is.read(b)) != -1) { > os.write(b, 0, bytesRead); > } > System.out.println("Download del file " + myFile.getCandidateName() + > "." + myFile.getResumeFileType() + " completato."); > } finally { > os.flush(); > os.close(); > } > } finally { > is.close(); > } > > } catch (Exception e) { > e.printStackTrace(); > } > ... -- Daniel Kulp dkulp@apache.org http://www.dankulp.com/blog