I'm using a java framework, Tapestry5. I have millions of pages and I'd like to generate my sitemaps with a nightly cron job rather than dynamically generate them on the fly. The problem I'm facing is I don't seem to know how to place the xml sitemaps dynamically in a directory that can be read publicly. Currently I have a manually written xml sitemap that points to dynamically written ones. The manually written sitemap is placed in the Web Pages / webapp directory along side the robots.txt file. How do I place a file there with java?
It's generally a bad idea to write to areas within your WAR directory. Fortunately, all the popular web and app servers (except perhaps some cloud hosting environments like Google App Engine) have the ability to configure an arbitrary directory on the file system as the path corresponding to particular URL patterns. This gives you the freedom to put the sitemap files anywhere you want.
Related
I have a web application built on the JVM. In this application the users are able to upload files. I read the contents of the file and do "something" with it.
In addition to this, I would like to give option to the users to put in a directory path. This directory path will be read by the application and the directory will be scanned for all relevant files (.CSV). And each will be processed.
Questions
Will the web-application be able to scan the directory located on the users machine? Or the directory path need to be in a network to which the web-app has access to?
I will be using the Commons IO package to scan the directory for files and process the files, is there a better approach?
You cannot access file system of user machine from pure web application. This task can be implemented using trusted applet or java application executed via java web start or trusted flash component or other native component (browser plugin).
Applets are almost obsolete and require JVM on client side. Java web start still requires JVM. All signed components (java based, flash, native code) require user approval.
I think that better and more modern way is to use a great feature of HTML 5 that allows not navigation to specific location on disk (that was possible since HTML 1.0) but also selecting a full directory.
Take a look on the following discussion for details: Does HTML5 allow drag-drop upload of folders or a folder tree?
I am creating a series of websites that will share a common java code base but will each have a different look and feel, as well as make slightly different calls to a database. Each site will have a unique URL (www.siteA.com, www.siteB.com).
The necessary database information is stored in properties files that appear to be loaded when the applications are deployed (to a JBoss 4.2.3 server). The CSS and images are in static folders.
What I want:
The user enters www.siteA.com
The "unbranded" site is initialized
Java (or whatever needs to) checks the URL to see which files to load
siteA.properties and siteA.css are loaded from the siteA resources folder
siteA's customized site is served to the client
If www.siteB.com is entered, all of its info would be loaded. When I want to add a new Site C, I will just create a siteC resources folder, put the SiteC versions of properties and CSS in it, and the underlying common code should take care of noticing that www.siteC.com was entered and grab from the new folder. All of this should happen without having to redeploy any of the elements common to all the sites.
I think I've mostly figured out how to get the CSS/images side of this working, but I can't get the properties files loaded this way.
Is this even possible? I haven't even been able to find a high-level discussion of the process.
Why don't you look up the HOST http header and output the relevant information for each server using a PHP script. You can output common content using file from an HTML file stored somewhere on the server.
I have developed a command-line (read: no GUI) Java application which crunches through numbers based on a given dataset and a series of parameters; and spits out a series of HTML files as resultant reports. These reports hold a large amount of data in tables, so in order to give the users a easy and quick overview of the results, I utilized the JUNG2 library and created a nice graph.
Here's where it gets interesting; since I would like the graph to be interactive it should be deployed after the application has run and files are generated, whenever the user wants to view the reports. I decided to go with an applet based deployment, however I am not too happy with the current setup due to the following reasons:
I want to make the software as simple to use as possible (my users won't be tech-savvy, and even tech-intimidated in most cases). I would really like to distribute one JAR only, which forced me to put the applet with everything else it needs in a package in the same JAR as the main application.
The applet and the main application need to communicate the results, so I create a xML-based report which is used to hold information. As long as the files are on a local machine and are not moved around it all works fine. Unfortunately I also need the files to be moved around. A user should be able to take the "results" folder to a USB stick, go anywhere plug the stick to another computer and be able to use the report as he/she likes.
For the time being the applets are implemented with the following html code:
<applet code="package.myapp.visualization.GraphApplet.class"
codebase="file:/home/user/myApp"
archive="myApp-0.2.6-r28.jar"
width="750" height="750">
<param name=input value="results/test_name/results.fxml">
</applet>
As you can see this applet will not work if the parent folder is moved to another location.
As far as I know I have a couple of alternatives:
a) Change codebase to point to an URL on our webserver where I could put the jar file. This however creates the problem with permissions, as the applet will not be able to read the results file. Alternative is to upload the results file to the server when the user wants to visualize the graph, although I am not sure if that's a good option due to server security and also if it could be made so that upload happens automatically without bothering the user.
b) I can use a relative path on the codebase attribute, but then the whole folder hierarchy needs to be intact upon copy. This could be a last resort, if I cant come up with a better way to do it.
c) change the deployment method (would like to avoid this alternative to not spend more time on the development phase)
Any ideas? Am I missing something? How could I tackle this problem?
Thanks,
I'm not sure I entirely understand your use-case, but from what I do understand, I would suggest this:
Dump the applet for an application launched using Java Web Start. Have the JNLP file declare a file association for the fxml file type. When the user double clicks an fxml file, it will be passed as an argument to the main(String[]) of the JWS application.
A sand-boxed JWS application can gain access to resources on the local file system using the JNLP API. Here is my demo. of the JNLP API file services.
i have a java based web application, i have the source code as well as the war file, the application uses mySql and need some web server like tomcat all to be added to some package that can be directly installed on window and linux machines directly..
i need to setup DB, WebServer, and app in one go. Would be great if it can create services for all as well.
is it possible???
i mean the user should just give the location to store and everything should get stored in one go, is it feasible? and if yes please guide me how to do so...
In short: Yes, it is.
Projects like XAMPP are already following that approach. All relevant software components are inside a single ZIP file which you can extract to an arbitrary location on the user's harddisk. All configuration then uses relative paths when referencing files.
So essentially, you will have to put in a little effort in advance to make the "installation" as easy as possible. Maybe you can simply build upon a project like XAMPP and use the infrastructure already provided?
Consider the following example structure
- Project
- www
- files
+ documents
+ html
+ images
+ scripts
- WEB-INF
* web.xml
The documents folder needs to be a symlink or in some other way external from the war file because users will add and remove documents (through a mapped network drive).
I'd like to deploy the webapp as a war-file but I don't know how to do that and take the above into account. Could you give some pointers?
/Adam
If it's static content, maybe you'd be better off fronting your app server with a web server and putting the static content there. You relieve the app server of having to serve up static data and save a network roundtrip to boot.
I agree with #duffymo.myopenid.com that fronting your app server with a web server that serves static content for certain URL prefixes is a good, clean solution.
If this isn't feasible in your environment or if you decide that you'd rather handle it in the web application itself, you could write a servlet that effectively does the same thing. For example, create a servlet that is mapped to the URL pattern /documents/*. This servlet could parse the URL (/documents/some/file.png) to determine a relative filename (some/file.png). It could then read and return the corresponding contents found in an external directory (/staticDocs/some/file.png).
Why not store the documents etc. in a database, then have the web-app access the database and allow users to pull files that way? Does it have to be a mapped network drive?
Otherwise if it's a matter of knowing what is there, you could always construct the jnlp file dynamically and pass file lists, etc. in as arguments (if they are server side).
Guess we need to know a little more about what you are trying to accomplish.
Basically, it's a webapp that aggregates information from various sources and generates documents. It's a requirement that users have the ability to create and upload documents manually from the network without being logged in to the webapp.
Putting the document location path as a context variable is definately doable. I guess it's the easiest way. /Adam
Unfortunately, for you .war files are .zip files at heart and .zip files do not support symbolic links. If you are ONLY deploying to a windows machine you may have luck using a shortcut file. However, I'm not sure if the app-server will like that (... probably not.)
I would recommend adding a configuration parameter to the application that allows the document folder's full path to be specified there. The default path should be relative ("./www/files/documents") so that the app works out of the box without additional configuration.
Many java web servers support "exploded war files" where you just unzip your .war file into the deployment directory. With tomcat you copy this to $CATALINA_HOME/webapps and you're done.
This should work for you.
What about creating an environment variable on your server that points to the directory the files are stored in? The environment variable may work better than a setting inside your WAR file because you could deploy your application in a new environment (maybe moving from DEV to PROD) without changing your WAR file.
From your java code, you can reference this environment setting with:
String docPath= System.getProperty("DOC_PATH");
In Apache Tomcat it may sometimes be appropriate to achieve reuse via the tomcat RewriteValve like this:
META-INF/context.xml:
<Context>
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
</Context>
WEB-INF/rewrite.config:
RewriteRule (.*)/login(/.*\.)(png|jpg|js|css) $1$2$3
Now the /appContext/login/ path will use the same images/js/css as /appContext/
Of course as with all regular expression based solutions to ANY problem, keeping the complexity of the expression low is important for performance.
Sounds like you need a web Content Management System (CMS).