File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Help with REST Web Service in Java and internal thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Help with REST Web Service in Java and internal thread" Watch "Help with REST Web Service in Java and internal thread" New topic
Author

Help with REST Web Service in Java and internal thread

Marcelo Tataje
Ranch Hand

Joined: Jan 31, 2011
Posts: 64

Hello everybody, I'm facing a very difficult requirement for an application that I'm developing.

The issue is that I have a restful web service and I use only two methods: POST and GET. In addition I have a Worker Thread which can be considered as a Daemon or a background thread. The flow of the application must be that some user sends a document to my REST using the POST Method, my POST Method gets the bytes of the message, process them into a DocumentBean and I put it on a Message broker. My worker thread is the java application which will be in charge of get the message from the broker and save it in an inbox path in the server. If all the flow is completed, the worker thread will set a boolean variable to true and if not, false and my post method is supposed to return an XML with tags <Response><code>200</code><message>OK</message></Response> and if it fails, it changes the code to 500 and message Error.

I've already tested the flow using a JUnit Test, what I don't have any idea is how my RestInterface will retrieve the status of the worker thread. Inside the POST method I'm converting the bytes to a Bean type and then I'm sending it to the Message Broker, then my worker thread do all the job, but how can I notify the rest that the process is complete to send the XML Response to the cliente?

Please I'll be really grateful if somebody could help me with this. Thank you very much for your time.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Hmmm... Well if you're going asynchronous through the message broker from the REST service,
then it will detach as soon as the message has been transmitted.

You would probably have to leave the service in a listening mode (a loop) and await the response
from the message processing service, so you could format the result and send it back.

Client -> REST -> JMS (Done)

Client -> REST -> JMS (Await some response, listen) -> Format response -> Client

WP
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
how my RestInterface will retrieve the status of the worker thread.


It seems to me that you want to retrieve the status of the "DocumentBean", not the Thread - after all, the Thread may be working on the next input bean from another requestl

Bill
 
Don't get me started about those stupid light bulbs.
 
subject: Help with REST Web Service in Java and internal thread