1 20 package org.enhydra.barracuda.core.helper.servlet; 21 22 import java.io.*; 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 26 import org.apache.log4j.*; 27 28 import org.enhydra.barracuda.core.helper.state.*; 29 import org.enhydra.barracuda.plankton.http.*; 30 31 32 37 public class ParamGateway extends HttpServlet { 38 39 protected static final Logger logger = Logger.getLogger(ParamGateway.class.getName()); 40 41 public static String PARAM_TARGET = "pt_"; 44 public static String PARAM_EXT = ".param_map"; 45 46 47 56 public void handleDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 57 if (logger.isDebugEnabled()) { 59 logger.debug("Persisting parameter information"); 60 ServletUtil.showParams(req, logger); 61 } 62 ParamPersister.persistReqParamState(req); 63 64 String cid = req.getParameter("pm_cid"); 66 67 resp.setHeader("Cache-Control","no-cache"); 70 resp.setDateHeader("Expires", System.currentTimeMillis()); 71 72 String src = req.getRequestURI(); 75 if (logger.isDebugEnabled()) logger.debug("Request URI:"+src); 76 int spos = src.indexOf(PARAM_TARGET); 77 int epos = src.indexOf(PARAM_EXT); 78 String base = src.substring(spos+PARAM_TARGET.length(), epos); 79 String param = src.substring(epos+PARAM_EXT.length()); 80 String target = URLRewriter.encodeURL(req, resp, base+param); 81 if (logger.isDebugEnabled()) logger.debug("Param Target:"+target); 82 resp.setContentType("text/html"); 83 PrintWriter out = resp.getWriter(); 84 85 out.println("<html>"); 86 out.println(" <head>"); 87 out.println(" <title></title>"); 88 out.println(" <script type=\"text/javascript\">window.onerror=new Function('return true');</script>"); 89 out.println(" </head>"); 90 out.print (" <body onload=\"p=document.layers?parentLayer:window.parent;p.jsrsLoaded('");out.print(cid);out.println("');\">"); 91 out.print (" <h3>Redirecting to real target...</h3><p>If you are not automatically redirected, please click <a HREF=\"");out.print(target);out.println("\" onclick=\"location.replace(this.href);return false;\">here</a></p>"); 92 out.print (" <form name=\"jsrs_Form\"><div style=\"visibility:hidden;\"><textarea name=\"jsrs_Payload\" rows=\"2\" cols=\"20\">");out.print(target);out.println("</textarea></div></form>"); 93 out.println(" </body>"); 94 out.println("</html>"); 95 96 resp.flushBuffer(); } 99 100 101 110 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 111 handleDefault(req, resp); 112 } 113 114 122 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 123 handleDefault(req, resp); 124 } 125 126 130 public void init() throws ServletException { 131 logger.info("initializing servlet"); 132 } 133 134 } 135 | Popular Tags |