• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Need Design Help : Temp Directory and Context Path

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

In my web application i need to display some audio/video and image files to the user. I have a folder containing original media files which i don't want to deliver directly. Whenever i get a request for some audio/video/image, i use FFMPEG utility to convert the original files to the standard FLV format (with a watermark logo) and i save this converted and required to be temporary file to server temp directory -



which gives me something like - D:\tomcat7\work\Catalina\localhost\easycontext

I write my converted file on this path in a hope that this will be managed/cleaned automatically by Tomcat/Operating System. Please correct me here if my assumption is wrong.

I am quite a beginner with Tomcat. The way i am thinking of serving these files to the client is by the way of writing contex path in the server.xml.



and now if i run my tomcat server, i get an exception like -



I believe that there is a lot i am doing wrong. My requirement is very simple and i request you all to please guide me on this. What should be the best design for this? I do not want to manage the converted media folder myself and at the same time i read that mentioning context path in server.xml is not good. What should i do?


With thanks in Advance,
Regards,
Juggy.
 
Saloon Keeper
Posts: 24292
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Context paths are for web applications, not parts of an application. Based on what you're describing, you've got a servlet that does the data conversion and handling. Because a context root applies to the entire webapp, that part of the URL will always be constant. However, the lower-level part of the URL is mapped to that servlet using the servlet-mapping declaration in WEB-INF/web.xml and can be any valid URL local path. So that's where "http://myserver.com:8080/videoapp/media/file001.flv" becomes a request routed to com.mycompany.videoapp.servlets.VidServerServlet.

The java.io package has a tempfile component. It's used to permit creation and management of temporary files with synthesized names. Tomcat interacts with this component by overridding the default JVM value of the tempfile directory path and setting it to TOMCAT_HOME/temp. You can also use the tempfile services against a directory of your own choosing, however, for example using the directory path that you configured into the webapp. Other than that, however, Tomcat neither knows nor cares about the tempfiles, so it's up to you to actually determine when it's proper to delete them and to do so.

For a task of this nature, I would not be surprised to learn that some files might repeatedly requested and that therefore you'd want to be able to cut down on repeated conversions by caching the results. The Apache commons libraries have some useful functions that can help do that. Note that I'm using the term "Apache commons" loosely, though, since there's an actual Apache Commons and then there's Apache projects for common functions (Tomcat uses a lot of them itself).
 
Juggy Obhi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim, Thanks for your guidance. Great help! Esp. the tip for caching files i will look into this. Thanks. I hope the design is ok
 
Tell me how it all turns out. Here is a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic