}
}
// Get all the mariner stuff from the request
ServletContext servletContext = getServletContext();
MarinerRequestContext requestContext;
Enumeration en;
requestContext = MarinerServletRequestContext.getCurrent(request);
if (requestContext == null) {
try {
requestContext = new MarinerServletRequestContext(
servletContext, request, response);
} catch (Exception ex) {
logger.error("servlet-context-creation-error");
throw new ServletException("Unable to create new " +
"MarinerServletRequestContext");
}
}
MarinerPageContext pageContext =
ContextInternals.getMarinerPageContext(requestContext);
// Get the name of the form from the vform parameter
String formSpecifier = (String) request.getParameter("vform");
if (formSpecifier == null) {
logger.error("form-name-missing");
requestContext.release();
throw new ServletException("No vform parameter passed.");
}
// Determine which URL to go to from which submission
// button was pressed to get here
String targetURL = null;
SessionFormData formData = pageContext.getFormDataManager().
getSessionFormData(formSpecifier);
if (request.getParameter(URLConstants.NEXT_FORM_FRAGMENT) != null) {
targetURL = formData.getFieldValue(URLConstants.NEXT_FORM_FRAGMENT);
} else if (request.getParameter(URLConstants.PREV_FORM_FRAGMENT) !=
null) {
targetURL = formData.getFieldValue(URLConstants.PREV_FORM_FRAGMENT);
} else if (request.getParameter(URLConstants.RESET_FORM_FRAGMENT) !=
null) {
targetURL = formData.getFieldValue(URLConstants.RESET_FORM_FRAGMENT);
} else {
targetURL = formData.getFieldValue(URLConstants.ACTION_FORM_FRAGMENT);
}
if (logger.isDebugEnabled()) {
logger.debug("Target URL is " + targetURL);
}
if (targetURL == null) {
requestContext.release();
throw new ServletException("No target URL for dispatch.");
}
// Strip the context path from the front of the target URL if it is
// there
targetURL = removeContextPath(targetURL, request);
// Strip the session id from the URL if there is one
targetURL = removeSession(targetURL);
// Make sure the target URL starts with a / (required by dispatcher).
if (!targetURL.startsWith("/")) {
targetURL = "/" + targetURL;
}
// Add the passed form parameters into the session
en = request.getParameterNames();
while (en.hasMoreElements()) {
String pName = (String) en.nextElement();
if (!(pName.equals(URLConstants.FORM_PARAMETER)) &&
!(pName.equals(URLConstants.NEXT_FORM_FRAGMENT)) &&
!(pName.equals(URLConstants.PREV_FORM_FRAGMENT)) &&
!(pName.equals(URLConstants.ACTION_FORM_FRAGMENT)) &&
!(pName.equals(URLConstants.
FORM_FRAGMENTATION_PARAMETER)) &&
!(pName.equals(URLConstants.RESET_FORM_FRAGMENT))) {
String pValue = (String) request.getParameter(pName);
if (logger.isDebugEnabled()) {
logger.debug("Writing attribute " + pName + "=" +
pValue + " to the session context.");
}
formData.setFieldValue(pName, pValue);
}
}
// Forward to the appropriate destination
if (logger.isDebugEnabled()) {
logger.debug("Dispatching to " + targetURL);
}
RequestDispatcher rd = servletContext.getRequestDispatcher(targetURL);
HttpServletResponse forwardResponse = response;
CachingResponseWrapper responseWrapper = null;
if (xdimeRequestProcessor != null) {
// The response from the forwarded request must be wrapped so that
// we can perform additional processing if raw XDIME is returned
responseWrapper = new CachingResponseWrapper(response);
forwardResponse = responseWrapper;
}
// Wrap the request - the wrapper removes IF headers which were causing
// the dispatcher to report that the resource hadn't changed. However
// we still need to process it to produce a different result!
MCSRequestWrapper requestWrapper = new MCSRequestWrapper(request);
// Dispatch the request to the "final destination"
rd.forward(requestWrapper, forwardResponse);
// Release the request context so that it is not detected as the
// enclosing request context when processing the XDIME. If it was, it
// would use the original requets URL
requestContext.release();
// See if we need to perform additional processing or not
if (xdimeRequestProcessor != null) {
if (xdimeRequestProcessor.isXDIME(
responseWrapper.getMimeTypeFromContentType())) {
// We have found raw XDIME which must be converted into the
// channelized response, probably because the container doesn't
// apply filters when invoking RequestDispatcher#forward - this
// because of an ambiguity in the 2.3 Servlet API spec
processXDIME(servletContext,
request,
responseWrapper,
targetURL);
} else {
// We have found an already channelized response so we simply
// ensure that the real response is populated from the wrapper
responseWrapper.writeTo(response);
}
}
requestContext.release();
}