I'm somewhat new to web services, but I have some legacy C++ code that I'd like to deploy as a web service (interacts with a database and is already in place so I don't want to rewrite in Java). I understand that I can create a C++ SOAP service with gSOAP (and some other tools), but I was wondering if it is possible to then deploy that service to a server that can also run jsp pages. I'd like to be able to access the C++ web service from a jsp page on the same server. Is that possible? If so, can you give me a little guidance on how that works? Thanks.
I don't know what gSOAP is or does, but C code (and presumably C++) can be accessed from within Java code using JNI. So the WS might be a regular Java WS that just happens to access native code internally.
Thanks Ulf. That makes sense. Although in that case you still have the overhead of maintaining the JNI code (and the JNI calls themselves). Although minor, I was just wondering if there is any way in general to deploy a web service in C++ and then access it via Java (without JNI)? Thanks again.
Originally posted by Jeff Storey: I'd like to be able to access the C++ web service from a jsp page on the same server.
Are you talking about a(n)
Application server (the answer would be most likely: "no").
Physical server or server instance (then the answer would be most likely: "possibly". Followed immediately by the question "Why would you want to do that?").
Accessing a web service from the same server that it is deployed on really makes little sense. If you want to expose the functionality to a number of clients within your organization then a web service might be the way to go. But if the JSP and C++ code are going to be collocated anyway then JNI, jna, or similar tools/frameworks are a more appropriate solution - there is no need for a web service.
A couple of follow up questions...first, I did mean a physical server, not the same app server (although the same app server would be nice as you'll see in my description below).
Suppose I have a service I want to expose to different types of web clients, and the service is written in C++. I'd like to deploy that so it is available to the web clients (let's assume I want to deploy it in straight C++, not JNI, and clients can communicate with it in SOAP). I'd also like to build a website on the same physical server so people can use my client or build their own.
Ideally I'd like to have one application server running though to do this. Is it possible to deploy that service to the same application server I run my web pages on which then access that service?
Joined: Aug 19, 2005
Originally posted by Jeff Storey: Is it possible to deploy that service to the same application server I run my web pages on which then access that service?
Depends on the application server - I'm not aware that one exists that fits your requirements. The problem is that a web service requires a "plain HTTP server" to operate. The gSOAP runtime seems to include its own HTTP stack. If you use that and an application server you'll have two HTTP servers running on the same server but only one HTTP server can use the default on port 80. It would be preferable if you could get a "real HTTP server" to forward the SOAP request to gSOAP - that is what Apache mod_gsoap is for. So you would need an app server that uses the Apache HTTP server AND lets you install this mod. JSPs "only" require a Servlet engine so there really is no pressure for the Servlet engine (or Java Enterprise server) to expose a full-blown HTTP server feature set that is customary on the Apache HTTP server. In fact it isn't uncommon to put an Apache HTTP server in front of a Servlet engine (tomcat example - you'll have to find out if your application server allows you to do something similar as that may be one possible solution - though it would still mean that the application server is "talking" to an HTTP server that resides on the same machine when it accesses the web service - not the most efficient use of system resources). [In many cases the application server's HTTP front-end is never exposed to the wild because the application servers are running behind firewalls - their first line of defense are hardened HTTP servers that are deployed on separate machines in the DMZ which only forward sanctioned requests to the application servers.]
Joined: Apr 07, 2007
Thanks Peer, I appreciate all of your input. I think the simplest solution would be to wrap the C++ code and call it with JNI.
it would. but I'm pretty sure you're not supposed to call JNI straight from J2EE code (although it is of course possible). I think that you're supposed to go via JCA.
Joined: Aug 19, 2005
I think that you're supposed to go via JCA.
I imagine that you are correct; I couldn't (quickly) find any information that would say whether JNI or jna are "Java Enterprise server safe" - given the nature of the beast I doubt it. That would indeed imply that you have to encapsulate the access code in a JCA (J2EE Connector Architecture) connector. There are some more JCA related links in this post.
That C++ code better be substantial to be worth all the bother with either solution. Otherwise it may actually be more effective to re-write the code and use the opportunity to possibly refactor the logic and bring it under unittest. [ February 01, 2008: Message edited by: Peer Reynders ]