java - Efficient way to expose generated files in the server? -
i'm working on application running on jboss5.1, jee5, jsf2, spring3.0, icefaces2.0, html , jquery1.8.
i have requirement of generating files on fly customers download. when file generated, i'm streaming file content bytes on jsf page , using <ice:outputresource>
show link download. works fine smaller size files. file size increases, not solution i'm running outofmemoryerror
issues because application jvm has bear burden of taking file content heap , funnel through application.
what provide generated files direct links can served web contained through http. have constraint of doing in secure environment user authenticated before can generate , see link. so, plan generate file web-inf directory , delete file user downloads, making web-inf contain files being viewed customers. i'm not sure how jboss server handles these files in terms of caching , if affects server performance. also, appreciate if there alternative approaches problem.
i believe described problem clearly, if not please let me know. in advance time , assistance.
ps - can create files outside web-inf , still make them secure.
- use preconfigured folder outside webapp on server. mentioned earlier in comments, not idea generate them inside web-inf
- create servlet serve content of requested file user preconfigured folder
- you can protect servlet if needed
- the servlet can delete file delivered user
- alternatively, can map external folder webapp , let jboss serve them static content (but need protect access if required)
p.s. may still "scheduled" cleanup in case generated file never downloaded.
servlet serving content (answer comment)
i not see problems security when having external folder in case. external folder accessible in application.
let's have directory generate files (filesrootdir) - /var/myapp/storage/tmp.
- create servlet in webapp knows location of filesrootdir
- let's servlet mapped following url (/mywebapp/downloads/file)
- to keep simple servlet receives parameter relative path generated file (path)
- taking above
- the app generates file here /var/myapp/storage/tmp/dir1/document.csv
- and generates link /mywebapp/downloads/file?path=/dir1/document.csv, user can download file
- when user decides download file, request handled servlet.
- the servlet receives location of requested file - /dir1/document.csv
- constructs absolute path concatenating filesrootdir , path parameter - /var/myapp/storage/tmp/dir1/document.csv
- reads , outputs content of file user
i believe can apply same security constraints servlet have in app, because part of application.
Comments
Post a Comment