}
// Failed, create a default implementation using the Pool Service.
PoolService pool = (PoolService)
TurbineServices.getInstance().getService(PoolService.SERVICE_NAME);
TurbineRunData data = (TurbineRunData)
pool.getInstance(DefaultTurbineRunData.class);
// Cache some information that will be used elsewhere.
data.setRequest(req);
data.setResponse(res);
// Let the implementation to create messages on demand.
// data.setMessages(new FormMessages());
// data.context = this.getServletContext();
// Don't set this because if we want to output via
// res.getOutputStream() then we will get an
// IllegalStateException (already called getWriter()). The
// solution is to only do this if data.getOut() is called and
// data.out is null. -jss
// data.setOut(data.getResponse().getWriter());
// Allow Turbine to work with both 2.2 (and 2.1) and 2.0
// Servlet API.
String contextPath = null;
Class jsdkClass = HttpServletRequest.class;
try
{
java.lang.reflect.Method meth =
jsdkClass.getDeclaredMethod("getContextPath", null);
contextPath = (String) meth.invoke(req, null);
}
catch (Exception ex)
{
// Ignore a NoSuchMethodException because it means we are
// using Servlet API 2.0. Make sure scriptName is not
// null.
contextPath = "";
}
String scriptName = contextPath + data.getRequest().getServletPath();
// Sets the default cookie parser.
data.setCookieParser(new DefaultCookieParser());
// Contains all of the GET/POST parameters.
data.setParameterParser(new DefaultParameterParser());
// Get the HttpSession object.
data.setSession( data.getRequest().getSession(true) );
// Set the servlet configuration in RunData for use in loading
// other servlets.
data.setServletConfig(config);
// Now set the ServerData.
data.setServerData( new ServerData( data.getRequest().getServerName(),
data.getRequest().getServerPort(),
data.getRequest().getScheme(),
scriptName,
contextPath ) );
return (RunData) data;
}