dcsimg
How do I handler timeout for this?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   blurr_lee
Posted On:   Friday, July 28, 2006 03:11 AM

// This method handles the payment public Payment processPayment(double amount, String net_account,int secureid, int bankacct, String currency, int merchid,String merchTransid, String merchacct, int testing) { //Create the parser CreateParser parser = new CreateParser(pHandler); String form = "https://www.neteller.com/gateway/netdirectv4.cfm"; String uri = form + "?amount=" + amount + "&net_account=" + net_account + "&secure_id=" + secureid+ "&bank_acct_num=" + bankacct + "&currency=" +currency + "&merchant_ID=" + merchid + "&merch_transid=" + merchTransid + "&merch_account=" + mer   More>>

// This method handles the payment
public Payment processPayment(double amount, String net_account,int secureid, int bankacct, String currency, int merchid,String merchTransid, String merchacct, int testing) {

//Create the parser
CreateParser parser = new CreateParser(pHandler);
String form = "https://www.neteller.com/gateway/netdirectv4.cfm";
String uri = form + "?amount=" + amount + "&net_account="
+ net_account + "&secure_id=" + secureid+ "&bank_acct_num=" + bankacct + "&currency=" +currency
+ "&merchant_ID=" + merchid + "&merch_transid="
+ merchTransid + "&merch_account=" + merchacct + "&test="
+ testing;

// PaymentHandler pHandler = new PaymentHandler();
pHandler.getPayment().setPayPostStr(form);

//apend the payment details to xml format
appendPaymentRequestToXML(amount, net_account, secureid, bankacct,currency, merchid, merchTransid, merchacct);

//send the uri to the Neteller gateway
parser.parse(uri);
//return the Payment object
return pHandler.getPayment();
}




Hi, the above is actually the method whereby I will send an uri request using the parser to the Neteller gateway. Neteller on the other hand will have to response to my request. Neteller will send the response back in XML string and I will then retrieve the values and store in the payment object. The PaymentHandler will be the class that retrieve the variables from the XML response string and store into the payment object. When the Neteller is timeout, this method will still keep on waiting for response.

Can anyone pls provide me with the source code on how should I handle the timeout problem?

Thanks.

   <<Less

Re: How do I handler timeout for this?

Posted By:   Robert_Lybarger  
Posted On:   Friday, July 28, 2006 07:52 PM

I'll repeat the other guy...format your code properly and preview it before you post it. I'm not going to bother reading the details of the code, but I am guessing you are asking this: "you are doing an operation that might not return a result... so you need a way to handle getting a result or not. The answer here is going to be a timer thread (in addition to whatever thread(s) you have setup to do the actual work).


In fact, the java API finally added a convenience class (TimerTask?) to take care of this, but creating your own isn't a big deal. If you do, I'd recommend this: (1) create an interface named MyTimerListener and have it declare a method called "timeExpired()". (2) create a new class which extends Thread and which takes (and stores) a MyTimerListener object in its constructor; its run() method should just be a sleep call... you pick how long it sleeps. (3) the class in which you are calling the working thread (that might or might not return) should implement MyTimerListener... its implementation of timeExpired() method should just call interrupt() on the working thread. (4) start a thread for your timer first then start the working thread as you are doing. The idea then is that, when your chosen time out has expired, your main thread gets notified and it just stops waiting around on the working thread.


It goes without saying that you should NOT join() on either of those threads from the main program thread. You should put the main program thread into a loop that sleeps a short while (fraction of a second) and checks to see if the working thread is still alive. if it is, do the loop again (sleep and then check). If not, interrupt the timer thread and deal with the output you are wanting to receive.

Re: How do I handler timeout for this?

Posted By:   Edward_Harned  
Posted On:   Friday, July 28, 2006 12:18 PM

Do you really think anyone can read that mess? Format your code.
About | Sitemap | Contact