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.

  1. create servlet in webapp knows location of filesrootdir
  2. let's servlet mapped following url (/mywebapp/downloads/file)
  3. to keep simple servlet receives parameter relative path generated file (path)
  4. taking above
    1. the app generates file here /var/myapp/storage/tmp/dir1/document.csv
    2. and generates link /mywebapp/downloads/file?path=/dir1/document.csv, user can download file
  5. when user decides download file, request handled servlet.
    1. the servlet receives location of requested file - /dir1/document.csv
    2. constructs absolute path concatenating filesrootdir , path parameter - /var/myapp/storage/tmp/dir1/document.csv
    3. reads , outputs content of file user

i believe can apply same security constraints servlet have in app, because part of application.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -