Return-Path: X-Original-To: apmail-cxf-users-archive@www.apache.org Delivered-To: apmail-cxf-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B727F105DA for ; Wed, 15 Jan 2014 16:40:13 +0000 (UTC) Received: (qmail 69291 invoked by uid 500); 15 Jan 2014 16:40:10 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 69203 invoked by uid 500); 15 Jan 2014 16:40:09 -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 69192 invoked by uid 99); 15 Jan 2014 16:40:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jan 2014 16:40:08 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [209.85.212.176] (HELO mail-wi0-f176.google.com) (209.85.212.176) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jan 2014 16:40:00 +0000 Received: by mail-wi0-f176.google.com with SMTP id hi8so984855wib.3 for ; Wed, 15 Jan 2014 08:39:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-type:message-id:mime-version :subject:date:references:to:in-reply-to; bh=sA0RZhRVOIlUjLKKEtgFoebupg7NoQIy1G9THmIiMdA=; b=SFRUC2b6j9WVzPslU6sn401FPBpAS3p7C4mfwUFvzTPSNvyENGdg1vxIGBYhYGtqvf EsohPuHnvAbmV6KzS4eRvBrCbmWlyVpqEgg6LSo6tOErlpF2O9nsTKj0faJoG8FFvE0B BAM2KBgddc3tNSn5l/GmMKa1oFVrY18W+XgTINRzFDccG9sGi3uGAfP6uQHZ/t/6E7tX oB2UrYXOb5s/ofVMck6+z2WGuEJs2aXlaxiM0dK70L1eCW8pOvnJQ64xJv23u4oeMCM2 GSw6v2UbYqW0SrM0gS9ExD+chHwxdfuMpXfvRM6LuTS7rr+jtWk8XlmP+54gMZJeVs7n QHNw== X-Gm-Message-State: ALoCoQmXqP+Nss1+5yq20PJ6GaLARQmZPUNFC8MNccUQGy4hfMrSJzFfp9k7MuFWBmEuJeAxAbbi X-Received: by 10.180.8.194 with SMTP id t2mr3255221wia.41.1389803978104; Wed, 15 Jan 2014 08:39:38 -0800 (PST) Received: from [192.168.0.145] ([109.231.208.226]) by mx.google.com with ESMTPSA id j3sm7433040wiy.3.2014.01.15.08.39.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 08:39:37 -0800 (PST) From: Henry Clout Content-Type: multipart/alternative; boundary="Apple-Mail=_3F1003DB-DCEA-485E-830F-9A42BE469DBA" Message-Id: <6FA5AF6F-37BE-4C25-B68A-DA4298439274@kuluvalley.com> Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) Subject: Re: Accessing temporary file name of attachments Date: Wed, 15 Jan 2014 16:39:29 +0000 References: <2B0C5377-A082-4B36-AED6-3A884A42F906@kuluvalley.com> <8318ED09-0787-4AFB-A6ED-E036D0CC8A72@apache.org> <52D2DC9A.20609@gmail.com> <52D67DCE.2080506@gmail.com> <6BC22B88-6B3E-48EF-BCD6-6E163CECDF2E@kuluvalley.com> <52D697DE.9090309@gmail.com> To: users@cxf.apache.org In-Reply-To: <52D697DE.9090309@gmail.com> X-Mailer: Apple Mail (2.1827) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail=_3F1003DB-DCEA-485E-830F-9A42BE469DBA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Hi Sergey. I don't think we'd want to create the file in its final destination = because: i) The destination base directory and path vary from service method to = service method, and are also a function of the request parameters. I = wouldn't have thought there would be sufficient information in the = interface you're proposing to figure this out, and even if there were = I'm not sure it sounds like a good idea to pull this out of the service = methods. ii) We don't really want to copy a file directly to the target until the = request has been validated. Other processes operate over the target = directory which require the input to have been validated. However, let's say the interface were something like (caveat: I don't = know if this is possible!) : import java.io.File; import org.apache.cxf.jaxrs.ext.multipart.Attachment; public interface TempFileGenerator { /** * Return a file which will be used as the destination for the = payload * for the given attachment. * @param attachment * @return */ File generateTempFile(Attachment attachment); } Then an implementation which would achieve what we were after would be: public class MyTempFileGenerator implements TempFileGenerator { private File tempBasePath; =09 @Override public File generateTempFile(Attachment attachment) { return new File(tempBasePath, = attachment.getContentId()); } } So our service implementation could then figure out where the temp file = is (if not in memory) based on the Attachment object. This is what I = meant when I mentioned that that the service implementation should be = able to figure out the temp file location. If this is what you were proposing for the temp file interface (or = something comparable), then it would work for the use case I was = describing. Cheers, Henry On 15 Jan 2014, at 14:14, Sergey Beryozkin wrote: > Hi Henry > On 15/01/14 13:53, Henry Clout wrote: >> Hi Sergey. >>=20 >> For us at least this wouldn't really address our problem. Our flow = is: >>=20 >> - Content is uploaded to CXF. >> - Our service method performs some validation on the input. >> - If all is ok, the content is moved to the correct place. >>=20 >> In our case, the correct place is a location on a NAS. The CXF temp = file location is also on the NAS So to go via an InputStream, we have = pull the data from the NAS across the network into memory, then transfer = it out again over the network back to the NAS. Even on a gigabit = network, this is a significant slowdown for large files vs a file = rename, which is what transferTo amounts to if the CXF temp directory is = placed on the NAS. >>=20 >> Dealing exclusively with InputStreams prevents any kind of file move = style optimisation. I agree that this is an application specific = optimisation, but I guess I thought it would be useful if CXF could = allow this kind of functionality via some sort of interface to those = that would benefit from it. My gut feeling was that it wasn't just us = who are using CXF to transfer large files, so someone else may benefit = from this functionality. >>=20 >> As it happens, we've worked around this by using Spring multipart = parsing within CXF: >>=20 >> @POST >> @Path("/kulus/{guid}/media") >> public void addMediaToKulu(@PathParam("guid") String guid) = throws IOException { >> MultipartFile multipartFile =3D null; >> if = (commonsMultipartResolver.isMultipart(httpServletRequest)) { >> MultipartHttpServletRequest = multipartHttpServletRequest =3D = commonsMultipartResolver.resolveMultipart(httpServletRequest); >> Iterator fileNamesIterator =3D = multipartHttpServletRequest.getFileNames(); >> if (fileNamesIterator.hasNext()) { >> String firstFileName =3D = fileNamesIterator.next(); >> multipartFile =3D = multipartHttpServletRequest.getFile(firstFileName); >> } >> } >> // We call multipartFile.transferTo(file) later on ... >> } >>=20 >> At the end of the day, maybe this workaround is sufficient rather = than changing the core CXF code. I guess if you think this = functionality wouldn't be useful to others, then I'm happy to accept = that :-) >>=20 > What I'm not getting is this: >=20 > Suppose CXF will let developers customize the way, or rather, where = temp files are created and I guess with the option to be notified when a = temp file needs to be closed. In your case you'd register a handler = which would ensure that if a temporarily file is needed then it would be = created immediately in the right place. >=20 > So now you have an InputStream, possible completely in the memory and = may be backed up by a temp file in the right location. >=20 > Can you please explain again why that won't be sufficient in your case = ? >=20 > Thanks, Sergey --Apple-Mail=_3F1003DB-DCEA-485E-830F-9A42BE469DBA--