Search code examples
tomcatfastcgi

How to setup fastCGI with Apache tomcat to run C++?


I have my java application running along with Apache Tomcat and jdbc is used for DB. However in some of the db transactions there are few dlls that are to be invoked. For this I've decided to use fastcgi.

So now I have a C++ program that invokes a dll. FastCGI along with Apache Tomcat should be able to be run this C++ program on a Windows machine? How can this be done? I am not able to get any pointers on Google for this particular fastCGI + Tomcat Apache + C++ + windows combination of setup. Please help!


Solution

  • Apache Tomcat is a Java application server. It's deliberately limited in scope. It supports CGI for some reason; but it does not support FastCGI. That's why you did not find any pointers: it's not possible using Tomcat as distributed.

    You could try one of these approaches:

    • convert your FastCGI wrapper into a plain executable, and invoke that from Java;
    • use SWIG to wrap your C++ library in a Java native (JNI) wrapper, that allows you to load it directly into your Java application and call it, but this is tricky with Tomcat because it doesn't allow web applications to load native libraries unless installed by the admin in Tomcat's common libraries directory;
    • modify your Java web app to implement the FastCGI network protocol to communicate with the FastCGI process that hosts your DLLs;
    • run another server in front of Tomcat that supports both Tomcat (AJP) and FastCGI forwarding, for example Apache httpd, lighttpd or nginx.