JSF - loading a xhtml from outside - java

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.

Related

Securing subdirectory in Tomcat

So a bit of background I have a surface level understanding about Tomcat WAR/Java files but I am helping out the programming team as I am taking over managing our Linux servers.
We are utilizing Apache Tomcat 8.5 and we currently have a WAR file that has a database login xml file. We would like to pull out the xml file into its own directory but I want to secure it down to make sure it can only be accessed from the WAR files on the server and not directly by url.
(edit) XML outside of a war file not from within
I'm open to any idea and any form of implementation.

Java applet replacement technologies

I have a WEB-application which implements Java Applet technology. Java applet itself is opened from WEB-app and it is a FTP-client which semi-automatically(pre-configured IP, un, pw...) gets a file list from a FTP-server and user selects a file to transfer.
In Applet, the file is downloaded via FTP and then streamed through HTTPS to the WEB-app.
This functionality now needs a replacement as the Applet are no longer supported by majority of the browsers.
My own thought is that this function would be replace with JNLP. As JNLP cannot be embedded into "same session", the upload phase to WEB-app must be implemented differently.
I've been thinking that WEB-app would provide an one-time upload URL which would receive the file and then continue processing it.
What other possibilities I have and what would you recommend?
If you want less to no code changes, go with JNLP, otherwise, refactor the view (if your using MVC) to use modern java web technologies such as Servlets, JSPs or JSF.

How to host user-generated HTML pages from Java web app?

My Java web application needs to serve up many static HTML reports.
The reports are generated on-demand using a 3rd party application based on user's inputs. The reports will always be different from run to run, so they can't be cached. The reports include multiple HTML pages (including JS and CSS pages), and relative links between files.
What's the easiest way to serve up these reports to the front-end user?
The reports don't need to stick around -- they can be deleted after a set time or after the user logs out.
I'm using:
Tomcat 7
Spring framework
Here is a similar example:
Suppose the web app is an online IDE, and you'd like to occasionally generate and display Javadoc pages for the project.
I would personally use a web server, such as Apache, to do this, since my Java applications are always behind Apache. Here is an Apache example:
# Serve /path/to/html/files/ with static files stored at /var/path/to/files/
ProxyPass /path/to/html/files/ !
Alias /path/to/html/files/ /var/path/to/files/
# Proxy / to Java application at localhost:8080
ProxyPass / http://localhost:8080/
If you must use a pure Java solution, you could try to set up a file download servlet, such as this one by BalusC. Just be careful about handling file paths supplied in request urls, as the servlet can be vulnerable to directory traversal attack.

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

Linking external files from Java Web Server

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.

Categories

Resources