Is there anyway to serve a file from a web server through the web, that is not within the web application.
I am using Tomcat and a Java servlets based application.
I don't want to put the files within the webapp because they are several 100GB and I will have to replace them every time I update the WAR if I put them inside it.
Apache web server can serve static files and delegate dynamic content requests to Tomcat.
You can simply map a URL to a servlet and the servlet can open the file from anywhere and read bytes from the fileinputsream and write them to the response output stream. You should add browser cache headers and also compress the data as you write it to the browser see http://onjava.com/pub/a/onjava/2003/11/19/filters.html
Related
I'm looking for a way to protect some static content hosted on Apache.
Those static files could be downloaded only by people based on rights that are defined in a database.
I am using Spring MVC for the web application.
I tried to forward the user to the relative path of the static content after I checked that the user has the appropriate rights. But it looks like forward in servlet can't forward to resource external to the Tomcat container. And I don't want to host the static content inside the web application folder.
I also tried to symlink a directory outside of the web application inside the web application folder. But again, it's not working.
The solutions I want to avoid is to redirect to the static content and then expose the actual URL of the resource on Apache which can then be access without any authorization.
I also don't want to use Tomcat to serve the static content with a servlet reading it blocks by blocks.
We have a Swing application which initiated from the Web application by clicking a link. The link is nothing but a JNLP url. There is a jar file hosted on our four servers under Apache. These are under a load balancer. Even though the same jar is hosted with the same time stamp but more or less every request to the JNLP the jar is gettign downloaded. Generally if there is no change in the jar the java Web start downloads only once and subsequent requests are works without downloading. What else the info it checks to compare with server version and local copy of jar?
Jar is hosted in Apache and by default apache looks at three things (timestamp+size+ETAG)
Since it is hosted in four apache servers the ETAG for each server is different and that is why it downloads whenever the request goes to one of these four servers. The fix is to remove the ETAG by overriding the apache configuration.
I'm working on a jsf2 web application and i need to upload files to a folder in my webcontent and keep them permanently, I used the technique that is mentioned in JSF FileUpload Directory and i could upload to wtp... folder's subfolder, but as BlueC said it get lost when tomcat restarts, is there any way to do that?
You can store the files in a Database using a BLOB field. It will depends of how you are implementing the persistence layer of your application but in the Java side usually you will implement this field as byte[]. So it will be comfortable for download or display the file.
You can upload the files to a certain directory/ default directory and then manually copy the files to a secured folder that is outside of the deployment directory and application server installation (yes you can do that).
I have a java servlet that upon a request crunches on data and produces an image. There can potentially be millions of images and once produced they don't need to be re-rendered so I'd like to cache them and avoid the render step as it is quite tedious.
I have the cacheing working fine but the problem is I need these rendered images to persist between deployments of my web application, i.e., I can't write them into the docbase or else they get destroyed upon redeployment.
What I've been doing is using the 'allowLinking' attribute of the Context as my web application is deployed as a war file (context is in META-INF/context.xml). This is somewhat tedious because I need to break the symbolic link before my application is undeployed or else the images in the link are destroyed, but it seems to work.
But this only works for Tomcat and when testing with JBoss (5.1) it doesn't seem to honor the symbolic link and doesn't allow linking to anything outside of the docbase. I'm thinking there has to be a more practical way to accomplish this that works for all Java Web Servers. What am I missing?
You could just configure a servlet that would serve the images from an external directory. This servlet would just have to extract the image file name or ID from the request, read the file from an external directory and write the bytes to the servlet response's output stream (with the appropriate content type set on the response).
Or you could add an Apache httpd server front-end which would serve the static images from some external directory, and delegate to your servlet container for the other URLs.
I am looking for suggestions on implementing this requirement:
The requirement is for users on a public website to be able to download files of any kind.
The webserver for the website resides on a DMZ, the server that stores the files is internal to our corporate network. The webserver would have to communicate with the file storage server to get the files. What would be the best way to implement this?
Map that file server as a network drive in the disk file system of the web server and then add another web application context to the servletcontainer configuration which references the network mapped path.
It's unclear what servletcontainer and platform you're running/targeting, so I can't give a more detailed answer. But if it were Tomcat, then it's a matter of adding the following <Context> element to Tomcat's /conf/server.xml, assuming that you've mapped the file server on /path/to/mount/share:
<Context path="/share" docBase="/path/to/mount/share" />
This way it's available by http://localhost:8080/share/
It looks like that you want a proxy-like component to serve backend files... Personally I wouldn't use an application server for such a task, instead use simply a webserver. Some options:
Network share: Create a network share just as BalusC proposed and configure your web server to use that share.
Reverse proxy: Deploy another web server on your file server and configure your front end to act as a reverse proxy (ie. to dispatch download requests to the internal web server)
That is to say I would rather use an (Apache, Nginx, etc.) web server based approach instead of a Java/J2EE based one. For me it seems a better fit... Hence I would consult my sysadmin:)