aspose file tools*
The moose likes Web Services and the fly likes Conceptual Doubt regarding Web Services Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Conceptual Doubt regarding Web Services" Watch "Conceptual Doubt regarding Web Services" New topic
Author

Conceptual Doubt regarding Web Services

Gerardo Sepulveda
Greenhorn

Joined: Dec 25, 2009
Posts: 8
Hello everyone,

I'm relatively new to Web Service design, and right now I'm working on a project which requires a Web Service, and its interaction with another element (a 'Server' class which should always be connected to another system). The webservice works great by itself, and same thing with the server, the problem is how to communicate with each other. Let me try to clarify what I want to acheive:

. ___________________________________________
((Internet)) ---------> | Java Web Service (1) --RMI---> Comm. Server (2) | <----------> Another Server
. ------------------------------------------------------------

"I get a post from the internet, my Java Web Service (1) receives the post and should execute a method [sendMessage(String msg, String destination) or similar] on Comm. Server (2) which ALWAYS has an active connection to "Another Server".

So I need the following in order for my application to run correctly:
1. Launch Comm. Server (2) (so it can establish a connection to "Another Server" and remain always active)
2. A way of calling the method "sendMessage(msg,destination)" that resides on Comm. Server (2) from within Java Web Service (1).

The only solution I have come up with is communicate the two components using RMI, but I don't know if this is the correct way (and I'm having tons of problems getting the client RMI (the Web Service) to work).

Can anyone advise if you think I'm on the right track, of if you know/think there's a better way to acheive this same behavior? The main issue is that I ABSOLUTELY NEED the Server to be always running and I think I can't acheive this from within a "Dynamic Web Project", right?

Thank you guys in advance.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
First of all, would it be an issue if the server (2) goes offline - that is, do you need to guarantee message delivery to server(2)?
That is, if server (2) goes down and you receive a message to server (1), how do you handle that?

Second, you do not say much about the requests sent from (1) to (2) - do you need to wait for a response or is sending the information enough?
Some additional options, using different messaging modes, are:
- JMS.
- (One-way) RPC.
Some alternatives are: JSON-RPC, XML-RPC (without SOAP), Spring Remoting with/without a binary protocol such as Hessian etc.
- Server (1) places messages in a queue and server(2) consumes them.
Example of queues: JBoss HornetQ, ActiveMQ etc. See respective queue for available protocols.

RMI is not a bad choice, but does require some work to work properly/efficiently.
There are more, but this should hopefully give you some more ideas.
Best wishes!
Gerardo Sepulveda
Greenhorn

Joined: Dec 25, 2009
Posts: 8
Hi Ivan,

Thank your for your response... Yes it would be an issue if server (2) goes offline, actually server (2) should be able to reconnect with the remote host if it goes down because of any error or exception, if a message is received on (1) while (2) is offline, it is safe to say that this message does not need to be delivered and (1) would display an error of "unsuccesful" or similar.

The Server (2) is an SMPP Server (Short Message Peer to Peer) which is always online and connected to the Cell Phone carrier in order to deliver SMS's... the SMPP protocol receives a "send message request" and responds a "message sent response" to aknowledge that the information was sent succesfully, this is managed internally by the API I'm using on server (2) so it doesn't require any action. If everything goes fine (1) would display "succesful" and if anything goes wrong it would display "unsuccesful".

Despite the fact that the protocol demands to wait for a response in order to "know" a message has been sent, I do not need to wait for any message sent from Server (2) to Server (1) [at least not at this time, I have another method on server (2) that takes care of this situation without any problems].

So I was thinking on calling from Web Service (1) the method "sendMessage(String msg, String destination)" which would do something like this:



Thanks for your suggestions, I've known java for a long time, but it is kind of my first dive into its technologies (Web Services, RMI, JMS, EJBs, etc) so I don't know them very well yet and wanted to hear someone's comments on the approach I'm taking. I'll take a look at the technologies you suggested and if anyone else has a comment I would aprecciate it.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
It sounds like you cannot use one-way messaging or asynchronous communication (without complicating things with callbacks).
So, my understanding is that you are on the right way with RMI or something similar. I have used RMI with fairly large loading, so it should be fine even if server (1) is busy.
Best wishes!
Gerardo Sepulveda
Greenhorn

Joined: Dec 25, 2009
Posts: 8
Hello Ivan,

I've followed the RMI path but I'm still figuring out how to have a unique instance of the server(2) and execute the method on that instance (right now, everytime the web service(1) is called, it's creating a second instance of the server(2)... which causes two alive connections to the remote server and I can't have this happening).

It seems to me that the Singleton pattern which is supossed to guarantee a unique instance of an object doesn't work "as is" when used with RMI. I suspect it has something to do with the fact that the RMI client(1) calls an instance of the remote Object Server(2) and then executes the method, hence it's creating another instance local to the WebService instead of executing the method in the remote one(2) like I need.

I'll let you know how I solved this issue, if you have any further suggestions they are absolutely welcomed

Regards
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I don't know if you use Spring or some other dependency injection framework. If so, have you considered letting the DI framework inject a singleton bean, managing the access to server (2), into your web service endpoint implementation class?
This should be possible with at least Spring, as far as I know.
Best wishes!
Gerardo Sepulveda
Greenhorn

Joined: Dec 25, 2009
Posts: 8
Hello,

Just to let you know I solved the "double instantiation" problem. There is no singleton pattern required to use here... the problem was precisely that I was trying to call an instance of the remote server, so it copied the instance locally (thus generating a new connection and another object).

The solution to this problem was to remove the singleton pattern I was trying to implement (and worked, before using it with RMI), and this assured that there'll only be one instance of the object.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Conceptual Doubt regarding Web Services