Alex Escudero

Greenhorn
+ Follow
since Sep 01, 2019
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alex Escudero

Yes, I understand that using web-app under Tomcat for opening local directories and running other programs on server machine is totally insecure, but in my case the client is supposed to be on the same machine where the server is running and I'm ready to take the risks. I was just pondering over the question if there any possibility to exploit web-app as a replacement for GUI java-program.

And why would you need a Swing GUI with many panes and layouts, just to cause other applications to run?



No, my application is supposed to do a little more than just cause other programs to run - the problem is that it's the only thing my web-app can't do at the moment. Also, it's not necessaryly ServletContextListener who does all those things.

So far, I just found only one possible workaround (though, not as elegant as I hoped for) - it's to create another java-program on the server. This program would play the part of an "executer" running as a daemon and listening some port for the instruction coming from the web-app. In this case web-app could delegate some tasks it can't do to the "executer".
4 years ago
I try to start another program (like cmd, notepad, explorer, etc...) from my web application on the same machine where Tomcat is running. For simplicity of an example, I created a ServletContextListener and put the following code in it to open mpv-player and play some media-file when the application context is being initialized. Similar code can be used in servlets and the "outer" program can be different of course.

So, when I run Tomcat from the console (or from IDEA while debugging), everything works fine: when my web-app is being initialized, mpv-player starts and plays the media. However, when I run Tomcat as a Windows service, everything changes: I can hear the sound of media playing, I can see the mpv-process started in Windows Task Manager, but the graphical interface of the program doesn't show up. Similar things happen when I try to 'exec' any other program (like notepad, explorer or whatever) - no exception is thrown, they just don't show up, but still created in the Task Manger.

Is there any chance to bring them into view? Imagine, I just want to click some link in my web-app to open Word, Excel or some local directory in the server machine (and it's obviously the same maching where the calling request is coming from).

P.S.
If you ask me what is the purpose of that? Well, I want to create a stand-alone java-program with GUI but don't want to sink myself into Swing routine with all those panes and layouts. Why not use web-app as a GUI-replacement for my java-program, since Tomcat is at hand all the time.



4 years ago
I have to implement a sort of blocking mechanism in my web app to temporarily restrict access to servlets and JSP when application goes on maintenance (during backup data loading, unlodaing, etc...). The first idea that came into my mind was to use ServletContext#setAttribute and ServletContext#getAttribute methods along with interceptor filter, who could check the current blocking status attribute value and forward incoming request to destination action servlets or redirect them to the maintenance page when needed.

However, this approach has its drawbacks: some servlets may change the status data from time to time, and since each request generates its own thread, there must be a lot of synchronization on ServletContext object involved to protect status attribute. When I say "protect", I mean "make is thread-safe". Just let me put it more clear: from the very moment one thread begins updating the status variable in ServletContext, all other threads that might intervene in the process must retreat and wait until the first thread is finished with updating, so that not to read the old version of the status that is currently being updated...

Generally, from what I read, ServletContext attributes are not welcomed to be used as "updatable" data, and mostly serve as a storage for context-scoped objects (such as DataSource, for example), that are loaded once when context is being initialized and then used for reading (thus, not likely to change in the future).

So, now I'm searching for the alternatives to share updatable context data. So far, I've taken a brief look at synchronized collections, concurrent maps, database transactions with proper isolation level... but still not sure, which would be the best strategy to chose?
4 years ago