views:

223

answers:

6

We have a library with very complex logic implemented in C. It has a command line interface with not too complex string-based arguments. In order to access this, we would like to wrap the library so that it can be accessed with simple XML RPC or even straightforward HTTP POST calls.

Having some experience with Java, my first idea would be

  • Wrap the library in JNI/JNA
  • Use a thin WS stack and a servlet engine
  • Proxy requests through Apache to the servlet engine

I believe there should already be something simple that could be used, so I am posting this question here. A solution has the following requirements

  • It should be deployable to a current linux distribution, preferrably already available via package management
  • It should integrate with a standard web server (as in my example Apache)
  • Small changes to the library's interface should be manageable
  • End-to-end (HTTP-WS-library-WS-HTTP) the solution should not incur too much overhead, but reliability is very important

Alternatively to the JNI/JNA proposal, I think in the C# world it should not be too difficult to write a web service and call this unmanaged code module, but I hope someone can give me some pointers that are feasible in regards to the requirements.

A: 

Depends what technology you're comfortable with, what you already have installed and working on your servers, and what your load requirements are.

How about raw CGI? Assuming the C code is stateless between requests, you can do this without modifying the library at all. Write a simple script which pulls the request parameters out of the CGI environment, perhaps sanitises the input, calls the library via the command-line interface, and packages the result into whatever HTTP response you want. Then configure Apache to dispatch the relevant URL(s) to this script. Python, for example, has library support for XML-RPC, and so does every other scripting language used on the web.

Servlets sound like overkill, but for instance if you want multiple requests per CGI process instantiation, and don't feel like getting involved in Apache configuration, then it might be easiest to stick with what you know.

Steve Jessop
Thank you, this is a very straightforward and simple suggestion, which I (strangely enough) had not really considered. It should not be too complicated to do this. The CLI for the library is not yet complete, but I believe that direct API calls are (1) more stable and (2) much faster. However, I think this will be the first implementation we will be trying. Thank you.
Kariem
+1  A: 

I think you may also publish it as a SOAP based web service. gSoap can be used to provide the service interface out of the library. Have you explored gSOAP? See http://www.cs.fsu.edu/~engelen/soap.html

Regards, Kangkan

Kangkan
+2  A: 

If you're going with web services, perhaps Soaplab would be useful. It's basically a tool to wrap existing command line applications in SOAP web services. The web services it generates look a bit weird but it is quite a popular way to make something like this work.

wds
A: 

I'm doing a similar thing with C++ at the moment. In my case, I'm writing a PHP module to allow PHP scripts to access the logic in my C++ library.

I can then use whatever format I want to allow the rest of the world to see it - initially it will just be through a PHP web application but I'll also be developing an XML-RPC interface.

Andy Shellam
+1  A: 

Creating an apache module is quite easy and since your familiar with xmlrpc you should check out mod-xmlrpc2. You can easily add your C code to this apache module and have a running xmlrpc server in minutes

Bob.T.Terminal
I have voted up all good answers, but this is the route we actually took. Thank you, Bob.
Kariem
A: 

If you're going down the JNI route, check out SWIG. http://www.swig.org/Doc1.3/Java.html

Assuming you have headers to project bindings with, swig is pretty easy to work with.

Jason Stelzer