1 56 57 58 package org.hamletsoft.enhydra.cactus.business; 59 60 import java.lang.reflect.*; 61 import javax.servlet.*; 62 import javax.servlet.http.*; 63 import java.net.*; 64 import junit.framework.*; 65 import org.apache.cactus.client.*; 66 import org.apache.cactus.server.*; 67 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 68 import com.lutris.appserver.server.Application; 69 import com.lutris.appserver.server.httpPresentation.HttpPresentationResponse; 70 import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest; 71 import org.hamletsoft.enhydra.cactus.business.*; 72 import org.apache.cactus.AbstractTestCase; 73 import org.apache.cactus.AbstractWebTestCase; 74 import javax.servlet.http.HttpServletRequest ; 75 import org.apache.cactus.ServletTestCase; 76 import java.net.MalformedURLException ; 77 import java.net.URL ; 78 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException; 79 import java.util.Hashtable ; 80 81 82 91 public class EnhydraAppTestCase extends AbstractWebTestCase { 92 99 public HttpPresentationComms comms; 100 107 public Application application; 108 115 public HttpPresentationRequest request; 116 123 public HttpPresentationResponse response; 124 125 130 public EnhydraAppTestCase (String theName) { 131 super(theName); 132 } 133 134 139 protected void runTest () throws Throwable { 140 runGenericTest(new EnhydraAppHttpClient()); 141 } 142 143 148 protected void runServerTest () throws Throwable { 149 try { 150 super.runServerTest(); 151 } catch (ClientPageRedirectException cpre) { 152 clientSideRedirect(cpre.getUrl()); 153 } 154 } 155 156 private void clientSideRedirect (String url) throws Throwable { 157 url = makeAbsolute(url, comms.request.getHttpServletRequest()); 158 hookForClientPageRedirect(url, getRedirectParameters(url)); 159 comms.response.setHeader("Location", url); 160 comms.response.setStatus(HttpPresentationResponse.SC_MOVED_TEMPORARILY, 161 "Redirected to new location."); 162 } 163 164 private String makeAbsolute (String location, HttpServletRequest request) { 165 URL url = null; 166 try { 167 url = new URL (location); 170 } catch (MalformedURLException e) { 171 String requrl = HttpUtils.getRequestURL(request).toString(); 172 try { 173 url = new URL (new URL (requrl), location); 174 } catch (MalformedURLException ignored) { 175 return location; } 177 } 178 return url.toString(); 179 } 180 181 189 protected Hashtable getRedirectParameters (String url) { 190 Hashtable ht = null; 191 if (url.indexOf("?") > -1) 192 ht = HttpUtils.parseQueryString(url.substring(url.indexOf("?") + 1)); 193 return ht; 194 } 195 196 203 protected void hookForClientPageRedirect (String url, Hashtable ht) { 204 ; 205 } 206 } 207 208 209 210 | Popular Tags |