1 package org.apache.turbine.util; 2 3 18 19 import javax.servlet.ServletConfig ; 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpServletResponse ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import org.apache.turbine.services.pool.TurbinePool; 27 import org.apache.turbine.services.rundata.DefaultTurbineRunData; 28 import org.apache.turbine.services.rundata.TurbineRunData; 29 import org.apache.turbine.services.rundata.TurbineRunDataFacade; 30 import org.apache.turbine.util.parser.DefaultCookieParser; 31 import org.apache.turbine.util.parser.DefaultParameterParser; 32 33 46 public class RunDataFactory 47 { 48 49 private static Log log = LogFactory.getLog(RunDataFactory.class); 50 51 54 private static boolean tryRunDataService = true; 55 56 64 public static RunData getRunData(HttpServletRequest req, 65 HttpServletResponse res, 66 ServletConfig config) 67 throws TurbineException, 68 IllegalArgumentException 69 { 70 if (req == null || 78 res == null || 79 config == null) 80 { 81 throw new IllegalArgumentException ( 82 "RunDataFactory fatal error: HttpServletRequest, " + 83 "HttpServletResponse or ServletConfig were null."); 84 } 85 86 if (tryRunDataService) 95 { 96 try 97 { 98 return TurbineRunDataFacade.getRunData(req, res, config); 99 } 100 catch (Exception x) 101 { 102 log.info("No Run Data Service available, not trying again!"); 103 tryRunDataService = false; 104 } 105 } 106 107 TurbineRunData data = 109 (TurbineRunData) TurbinePool.getInstance(DefaultTurbineRunData.class); 110 111 data.setRequest(req); 113 data.setResponse(res); 114 115 118 120 126 128 String contextPath = req.getContextPath(); 129 130 String scriptName = contextPath + data.getRequest().getServletPath(); 131 132 data.setCookieParser(new DefaultCookieParser()); 134 135 data.setParameterParser(new DefaultParameterParser()); 137 138 data.setSession(data.getRequest().getSession(true)); 140 141 data.setServletConfig(config); 144 145 data.setServerData(new ServerData(data.getRequest().getServerName(), 147 data.getRequest().getServerPort(), 148 data.getRequest().getScheme(), 149 scriptName, 150 contextPath)); 151 return (RunData) data; 152 } 153 154 159 public static void putRunData(RunData data) 160 { 161 if (tryRunDataService) 163 { 164 try 165 { 166 TurbineRunDataFacade.putRunData(data); 167 return; 168 } 169 catch (Exception x) 170 { 171 } 172 } 173 174 TurbinePool.putInstance(data); 176 } 177 } 178 | Popular Tags |