https://github.com/eracle/servlet-cli-wrapper
Java Servlet that wraps a generic cli command
https://github.com/eracle/servlet-cli-wrapper
Last synced: 3 months ago
JSON representation
Java Servlet that wraps a generic cli command
- Host: GitHub
- URL: https://github.com/eracle/servlet-cli-wrapper
- Owner: eracle
- License: apache-2.0
- Created: 2013-11-07T17:40:59.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-09-28T23:16:47.000Z (over 8 years ago)
- Last Synced: 2025-01-14T02:44:24.751Z (5 months ago)
- Language: Java
- Size: 597 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
servlet-cli-wrapper
===================Tomcat Servlet which performs as a wrapper of a generic bash command.
It can be useful for wrapping an already compiled program by redirecting its stdio and stdout through an http conversation.
Features:
=============
- Allows the co-existence of different listening urls assigned to different commands;
- The War file do not needs to be recompiled in case of changing of the wrapped commands, for instance, adding/removing new ones;
- Log4j is used for also logging the errors (stderr) generated by the sub-process created for the execution of the command.Implementation details:
=============
- The bash commands are configured through the web.xml file;
- Tomcat7 automatically notices if the web.xml file is modified and it reloads the new servlet context;
- The Servlet reads the content of the http post, after that, the command is executed by starting a new process, the content red is passed to the standard input (stdin) of the process and finally the stdout of the command is returned as an http post response by the servlet;
- Commons IO - Apache is used for the I/O communications with the sub process created;
- UTF-8 encoding is used for log the stderr of the sub-process created.Use:
=============
- Clone the repository;
- Download from the web the Commons IO - Apache Commons library, log4j 2 and importing it on the web project; (sorry not mavenized yet)
- Customize the web.xml file as preferred; (bash command to execute, http url_to_listen)
- Export as a war file;
- Deploying it on a servlet engine (I experienced with tomcat7);
- Run the servlet engine;
- Test it with curl:
curl --data-binary @input_file http://localhost:8080/view/url_to_list/- Enjoy.
Problems:
==============
With apache tomcat7 I observed an issue with the "apt-get install" installation of Ubuntu.
With Ubuntu, the Tomcat7 daemon process use as a user the tomcat7 one, and it has not the rights to execute some customized bash commands due to apache tomcat7 security restrictions.
The issue was solved by downloading the binary distribution from the ASF official web site and using jsvc apache utility to set it up to a system service daemon. jsvc allows to rewrite the configuration constraints like the execution linux user.
As a generic suggestion: put the absolute path of the bash command in the web.xml, not the relative one.Todo:
==============
- Extend to the http GET calls as well;
- Showing in every log call the specific bash command that generated it;
- Mavenizing it.(or Gradle)