1 7 package com.inversoft.verge.mvc.controller; 8 9 10 import java.io.IOException ; 11 import java.io.Writer ; 12 import java.net.URISyntaxException ; 13 14 import javax.servlet.RequestDispatcher ; 15 import javax.servlet.ServletException ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 19 import org.apache.log4j.Logger; 20 21 import com.inversoft.verge.mvc.MVCException; 22 23 24 32 public class DefaultLongTxnHandler implements LongTxnHandler { 33 34 37 private static final Logger logger = Logger.getLogger(DefaultLongTxnHandler.class); 38 39 42 public static final String RESULT_PARAMETER = 43 "com.inversoft.verge.mvc.controller.form.Result"; 44 45 46 49 public DefaultLongTxnHandler() { 50 super(); 51 } 52 53 60 public void handleStartLongTxn(HttpServletRequest request, 61 HttpServletResponse response, String url) 62 throws MVCException { 63 if (url != null) { 64 65 if (logger.isDebugEnabled()) { 66 logger.debug("Including long txn URL: " + url); 67 } 68 69 RequestDispatcher rd = request.getRequestDispatcher(url); 70 try { 71 rd.include(request, response); 72 response.flushBuffer(); 73 } catch (ServletException se) { 74 throw new MVCException(se); 75 } catch (IOException ioe) { 76 throw new MVCException(ioe); 77 } 78 } else { 79 logger.error("LongTxnEnabled but URL not specified. Consult the Verge" + 80 " docs to figure out how to configure the URLs."); 81 } 82 } 83 84 92 public void handleEndLongTxn(HttpServletRequest request, 93 HttpServletResponse response, String url, Result result) 94 throws MVCException { 95 if (url != null) { 96 97 request.setAttribute(RESULT_PARAMETER, result); 99 100 if (logger.isDebugEnabled()) { 101 logger.debug("Including long txn end URL: " + url); 102 } 103 104 RequestDispatcher rd = request.getRequestDispatcher(url); 105 try { 106 rd.include(request, response); 107 } catch (ServletException se) { 108 throw new MVCException(se); 109 } catch (IOException ioe) { 110 throw new MVCException(ioe); 111 } 112 } else { 113 try { 115 url = response.encodeRedirectURL(result.getGeneratedURL(request)); 116 } catch (URISyntaxException urie) { 117 throw new MVCException(urie); 118 } 119 120 if (logger.isDebugEnabled()) { 121 logger.debug("Manually writing out long txn end meta-refresh " + 122 "with URL: " + url); 123 } 124 125 try { 126 Writer writer = response.getWriter(); 127 writer.write("<head><meta http-equiv='REFRESH' content='0;url=" + 128 url + "'/></head></html>"); 129 response.flushBuffer(); 130 } catch (IOException ioe) { 131 throw new MVCException(ioe); 132 } 133 } 134 } 135 } | Popular Tags |