Linking external files from Java Web Server - java

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.

Related

JSF - loading a xhtml from outside

Hey I'm beginning my journey with JSF and Java i have question in this subject.
Question:
Is it possible to load and use xhtml that is not actually stored inside a war file but somewhere outside? I'd like to store it in a database or eventually on a FTP server. Can i register it as a resource in JSF.
I am not sure about the Database part but there are some interesting approaches for connecting to NAS drives (which can serve as FTP location also).
If you are deploying as open WAR, Using links in the underlying OS allow you to map a location from the open directory to a mapped drive (NAS location) where you can FTP your xhtml pages.
If you are deploying on Weblogic (I am sure others have a similar feature) you can use the option in the web.xml to redirect all requests to an underlying NAS location.
I have used both the above approaches successfully with JSP and HTML so don't see any challenges with xhtml.

When the application server requires a restart, for which file type changes?

I am using Weblogic Application server currently, i would like to know the type of files which definitely requires a restart to function as desired.
As part of enterprise application usage, i know for js and jsp it does not require restart. What else can be, please help me in knowing. Thanks.
All files flagged as resources: images, not dinamic web pages, CSS, javascripts, *.xsd etc.
All other files used by your enterprise application need a weblogic restart.
For example: you have some *.properties files read during the startup of the server to create a singleton. Those files, read ONLY during the startup, need a full weblogic restart in order to be refreshed by your E.Application.
Generally, all files read at the startup and maintained in the server memory, need a full restart of the server.

IS there any way to add files to a deployed web application on tomcat server

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).

Process of webserver starting

This question is kind of related to our web application and it is bugging me from last few months. So we use linux server for database, application and we have our custom built java web server. If we do any change in source code of application, we build a new jar file and replace the existing jar file with new jar file. Now update to take place in live application, we just execute a HTML file which contains this kind of code :
<frameset rows="100%"?
<frame src="http://mydomain.com:8001/RESTART">
</frameset>
How does this opening of port make the application to use new jar file?
The webserver is instructed to give the /RESTART URL special treatment. This can either be through a mapping to a deployed servlet, or through a hardcoded binding to a web container action.
It is very common to have URLs with special meaning (usually protected by a password) allowing for remote maintainance, but there is no common rule set. You can see snapshots of the Tomcat Administration console at http://linux-sxs.org/internet_serving/c516.html
EDIT: I noticed you mentioned a "custom built web server". If this web server does not provide servlets or JSP's - in other words conforms to the Servlet API - you may consider raising the flag about switching to a web server which do.
The Servlet API is a de-facto industry standard which allows you to cherry-pick from a wide array of web servers from the smallest for embedded devices to the largest enterprise servers spreading over multiple physical machines, without changing your code. This means that the hard work of making your application scale has been done by others. In addition they probably even made the web server as fast as possible, and if not, you can pick another where they did.
You're sending an HTTP GET to whatever's listening on that port (presumably your web server). The servlet spec supports pre- and post-request filters, so the server may have one set up to capture this particular request and handle it in a special fashion.

Deliver files from a web server from outside the web app

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

Categories

Resources