*/
@SuppressWarnings("unchecked")
protected boolean restoreRequest(Request request, Session session) {
// retrieve and remove the SavedRequest object from our session.
SavedRequest saved = (SavedRequest) session.getNote(Constants.FORM_REQUEST_NOTE);
session.removeNote(Constants.FORM_REQUEST_NOTE);
session.removeNote(Constants.FORM_PRINCIPAL_NOTE);
if (saved == null)
return (false);
// modify our current request to reflect the original one
request.clearCookies();
Iterator cookies = saved.getCookies();
while (cookies.hasNext()) {
request.addCookie((Cookie) cookies.next());
}
MimeHeaders rmh = request.getCoyoteRequest().getMimeHeaders();
rmh.recycle();
boolean cachable = "GET".equalsIgnoreCase(saved.getMethod()) || "HEAD".equalsIgnoreCase(saved.getMethod());
Iterator names = saved.getHeaderNames();
while (names.hasNext()) {
String name = (String) names.next();
// the browser isn't expecting this conditional response now. Assuming that it can quietly recover from an unexpected 412.
if (!("If-Modified-Since".equalsIgnoreCase(name) || (cachable && "If-None-Match".equalsIgnoreCase(name)))) {
Iterator values = saved.getHeaderValues(name);
while (values.hasNext()) {
rmh.addValue(name).setString((String) values.next());
}
}
}
request.clearLocales();
Iterator locales = saved.getLocales();
while (locales.hasNext()) {
request.addLocale((Locale) locales.next());
}
request.getCoyoteRequest().getParameters().recycle();
if ("POST".equalsIgnoreCase(saved.getMethod())) {
ByteChunk body = saved.getBody();
if (body != null) {
request.getCoyoteRequest().action(ActionCode.ACTION_REQ_SET_BODY_REPLAY, body);
// set the MIME content type.
MessageBytes contentType = MessageBytes.newInstance();
// if no content type specified, use default for POST.
String savedContentType = saved.getContentType();
if (savedContentType == null) {
savedContentType = "application/x-www-form-urlencoded";
}
contentType.setString(savedContentType);
request.getCoyoteRequest().setContentType(contentType);
}
}
request.getCoyoteRequest().method().setString(saved.getMethod());
request.getCoyoteRequest().queryString().setString(saved.getQueryString());
request.getCoyoteRequest().requestURI().setString(saved.getRequestURI());
return true;
}