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.
Related
We're using Websphere to host a series of applications for us:
We have an API that's hosted at the root, written in Java
We have an Angular application hosted at /admin
We have another Angular application hosted at /marketing
My concern is about deep-linking. If a user is at /marketing/products/1, and they refresh their browser or share the link, I need the server to send that route to the correct Angular application so it can be generated correctly.
In a simpler setup, where the Angular application is living at the root, I would use the Java application's web.xml file to redirect traffic to "/". But in my current scenario, I need traffic for the marketing site to go to "/marketing", not just to "/". Just like a deep-link from the admin site would need to go to "/admin".
Furthermore, the base URLs for these Angular applications are subject to change, and we also plan to add additional Angular sites to this same server. So I'm really looking for a solution that can work dynamically and have the server redirect to the first "slug" in the URL rather than matching specific directories.
Any ideas? (And please excuse and correct any misconceptions I've demonstrated above -- I currently know very little about WebSphere)
I can see a couple possible ways forward.
You could still use the error-page directive in web.xml, but specify the URL of a servlet in your application that could do the inspection manually and issue a redirect as appropriate. How the list of context roots is provided to your app will differ based on how it's packaged, but it could be done using files, environment variables, or JNDI entries in server.xml.
If the URLs could be changed, the Angular apps could be changed to use HashLocationStrategy in their routers which would sidestep the error page. It doesn't seem likely that that's the case but I'll put it here to get it out of the way.
You could consider splitting each Angular app into its own .war file and configuring the context root in the webApplication element in server.xml. Then redirecting to / in web.xml would work since that / is relative to the context-root.
We ended up combining those separate Angular applications into 1 so that WebSphere could direct everything to "/" and Angular routing could handle everything from there.
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.
Say I have a Java HTTP server which serves REST APIs like GET/PUT/POST etc based on Jetty. I want to create a HTML interface for this server so that I can turn on/off certain features, control settings, surface server metrics etc through it.
Is there any such Java library I can use for this purpose?
I can see 2 main directions to go:
Jetty has a built-in servlet-jsp engine support that you can use for your dynamic configuration HTML pages. You can make your configuration in jsp supported forms and dispatch their processing to servlets to make the configuration model change.
An other way is to extend your REST API with the configuration relevant part and interact with it from javascript from config HTML pages.
You do not need to deploy further jars neither for 1 nor for 2.
1. is built in
2. is already deployed by you because you are using a REST implementation already
If you have a complex configuration logic with more HTML pages you might consider using JSF instead of JSP.
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.
i am writing a standalone java app. the app's properties should be configurable from a webpage deployed with the app. how do i achieve this ?
Thanks in advance
note: the app has an embedded HTTP client/server module. it should only run from command prompt
I don't think that's a good idea. Webpage forms are designed to work with a server, not with a standalone client app. You could have the app run its own web server, but that would mean the app has to be running for the configuration page to work, and it's also a rather contrived setup just to do some configuration.
It might be possible for the webpage to contain JavaScript that writes to a local file - I don't know enough about the JavaScript security model to say.
But why not have the configuration dialog as part of the app's GUI? That's the normal and expected behaviour - you'd need a pretty compelling reason to deviate from it.
JMX might be the answer that you're looking for. If you expose all of your configurable properties through MBeans, then adding a web page on top of that exposing these properties is just configuration.
You can launch a standalone Java app using JNLP files (Java WebStart). If you want the user to be able to configure the application before its launched, you can have the JNLP file dynamically generated, then pass properties as environment variables through the JNLP file.
You can configure your standalone Java app to read configurable properties from a properties file (say conf.properties) on the server.
You may have a UI webpage (html/jsp) with all the field to be configured. When the page is submitted a JSP/Servlet may write/update the contents of conf.properties on the server.
UPDATE: The above solution will work assuming only an admin user wants to update the properties file.
In case anybody should be able to update it, then concurrency issue has to be taken into account.
In that scenario, you have to implement a mechanism similar to how weblogic10 updates config.xml using Admin Console.
i.e. You will have 2 conf.properties files confA & confB (initially in sync). The standalone app will always read from confB. The UI will have 2 buttons say Lock & Release configurations. When an edit is made (locked & released), it will be written to confA and at the same time changes of confA has to be replicated to confB.