Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Webservices - C++ and Java

 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Jeff
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Jeff Storey
    Ranch Hand
    Posts: 230
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Peer,

    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?

    Thanks,
    Jeff
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.]
     
    Jeff Storey
    Ranch Hand
    Posts: 230
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    grigoris philippoussis
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 unit test.
    [ February 01, 2008: Message edited by: Peer Reynders ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic