Thanks for all of the great advice, Jens hit my need on the head. I am working specifically with an set of API's from Paymenttech. They have a really easy syncronous api (that basically sends an XML-RPC over HTTP req) and an Async that keeps a socket open. Thanks, -Aaron Held Jens Riboe wrote: Here is how I have implemented an automatic reloading progress page, during credit-card payment and other long running tasks.1) action: PaymentSubmit 2) action: PaymentProgress 3) interface: reloadInfo 4) view: progress.jsp 5) cfg: xwork.xml PaymentSubmit receives the form data and launches a thread. The thread runs the payment operation, but the action return "progress". When the payment thread is done, it updates the payment object in the HttpSession. PaymentProgress checks the payment object in the HttpSession. As long as the payment is not complete, it returns "progress". After payment completion it returns "success". This action exports a reloadInfo object with url and interval for the progress jsp to use. The code below have been simplified and stripped, to make the idea (hopefully) clear. --------------------------------------------------------- action: PaymentSubmit --------------------------------------------------------- public class PaymentSubmit extends ActionSupport implements BusinessAware, CardProcessorAware, ServletRequestAware, Runnable { private CardProcessor cardProcessor; private HttpSession session; private Business business; public String execute() throws Exception { Payment payment = getPayment(); payment.paymentStart(); business.addPayment(payment); new Thread(this).start(); return "progress"; } public void run() { Payment payment = getPayment(); try { User user = payment.getUser(); cardProcessor.setPartner( user.getPartner() ); String msg = cardProcessor.performPayment(user.getCard(), payment.getAmount()); synchronized (payment) { payment.paymentComplete(msg==null, msg); } } catch (Exception e) { synchronized (payment) { payment.paymentComplete(false, e.toString()); } } } public void setBusiness(Business business) {this.business = business;} public void setServletRequest(HttpServletRequest request) {this.session = request.getSession();} public void setCardProcessor(CardProcessor cardProcessor) {this.cardProcessor = cardProcessor;} public Payment getPayment() {return (Payment) session.getAttribute("payment");} } --------------------------------------------------------- action: PaymentProgress --------------------------------------------------------- public class PaymentProgress extends ActionSupport implements BusinessAware, ServletRequestAware { private HttpSession session; private Business business; public String execute() throws Exception { Payment payment = getPayment(); synchronized (payment) { if (payment.isComplete()) { business.updatePayment(payment); return Action.SUCCESS; } else { return "progress"; } } } public void setBusiness(Business business) {this.business = business;} public void setServletRequest(HttpServletRequest request) {this.session = request.getSession();} public Payment getPayment() {return (Payment) session.getAttribute("payment");} public ReloadInfo getReloadInfo() { return new ReloadInfo() { public String getProgressName() {return "payment";} public String getActionName() {return ActionContext.getContext().getName() + ".cmd";} public int getInterval() {return 1;} }; } } --------------------------------------------------------- interface: reloadInfo --------------------------------------------------------- public interface ReloadInfo { String getProgressName(); String getActionName(); int getInterval(); } --------------------------------------------------------- view: progress.jsp I'm using JSP 2.0 / JSTL 1.1 Read the WW2 Cookbook entry below, to get the trick working http://wiki.opensymphony.com/space/Using+WebWork2+and+XWork1+with+JSP+2.0+an d+JSTL+1.1 --------------------------------------------------------- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <fmt:bundle basename="messages.${reloadInfo.progressName}Progress"> <html> <head> <meta HTTP-EQUIV="Refresh" CONTENT="${reloadInfo.interval}; URL="" value='/${reloadInfo.actionName}'/>"> <title><fmt:message key="title"/></title> <style type='text/css'> @import url(<c:url value="/style.css"/>); table.progress {border: solid 1px red; width: 8cm;} tr.progress {} td.progress {background-color: orange; text-align: left;} table.box {background-color: transparent;} tr.box {} td.box {background-color:red; width:3mm; height:3mm;} </style> </head> <body> <h1><fmt:message key="heading"/></h1> <p><fmt:message key="instruction"/></p> <c:set var="numReloads" scope="session" value="${numReloads + 1}"/> <table class="progress" cellspacing="0" cellpadding="2"> <tr class="progress"><td class="progress"> <table class="box" border="0" cellspacing="2" cellpadding="0"><tr class="box"> <c:forEach begin="1" end="${numReloads}"> <td class="box"> </td> </c:forEach> </tr></table> </td></tr> </table> </body> </html> </fmt:bundle> --------------------------------------------------------- cfg: xwork.xml --------------------------------------------------------- <action name="paymentSubmit" class="com.whatever.actions.payment.PaymentSubmit"> <result name="progress" type="redirect">/paymentProgress.cmd</result> <result name="input" type="view">/view/paymentForm.jsp</result> . . . </action> <action name="paymentProgress" class="com.whatever.actions.payment.PaymentProgress" > <result name="progress" type="view">/view/progress.jsp</result> <result name="success" type="view">. . .</result> . . . </action> -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Aaron Held Sent: Wednesday, March 03, 2004 6:08 PM To: [EMAIL PROTECTED] Subject: Re: [OS-webwork] Long running tasks Jason Carreira wrote:Nope, no support out of the box... If you wanted, it would be easy enough to create an asynch ActionProxy using threads or JMS, and/or to create a JMSDispatcher to consume JMS messages and translate them to Action executions... JasonThanks, Threads will do. I'll look into ActionProxy, but it seems easier to understand if I have three seperate pages. startLongAction Page -> Refresh And Wait Page -> Show user results Page. -Aaron ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork |
- [OS-webwork] Long running tasks Aaron Held
- RE: [OS-webwork] Long running tasks Jason Carreira
- Re: [OS-webwork] Long running tasks Aaron Held
- RE: [OS-webwork] Long running tasks Jens Riboe
- RE: Re: [OS-webwork] Long running tas... Aaron Held
- RE: Re: [OS-webwork] Long running tasks Wayland Chan
- RE: [OS-webwork] Long running tasks Ben Hall
- RE: [OS-webwork] Long running tasks Jason Carreira
- Re: [OS-webwork] Long running tasks Aaron Held
- RE: RE: [OS-webwork] Long running tasks Wayland Chan
- RE: RE: [OS-webwork] Long running tasks Jens Riboe
- RE: RE: [OS-webwork] Long running tasks Jason Carreira
- RE: [OS-webwork] Long running tasks Jason Carreira
- Re: [OS-webwork] Long running tasks Mike Cannon-Brookes
- RE: RE: RE: [OS-webwork] Long running tasks Wayland Chan