use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.
the class TestActionServlet method testProcessForwardConfigClassOverriddenSubConfigClass.
/**
* Test the case where the subconfig has already specified its own config
* class. If the code still attempts to create a new instance, an error
* will be thrown.
*/
public void testProcessForwardConfigClassOverriddenSubConfigClass() throws Exception {
moduleConfig.addForwardConfig(baseForward);
ForwardConfig customSub = new CustomForwardConfigArg("failure", "/failure.jsp");
customSub.setExtends("success");
moduleConfig.addForwardConfig(customSub);
try {
actionServlet.processForwardConfigClass(customSub, moduleConfig, null);
} catch (Exception e) {
fail("Exception should not be thrown");
}
}
use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.
the class TestPerformForward method testNullForwardPath.
public void testNullForwardPath() throws Exception {
ForwardConfig config = new ForwardConfig();
config.setPath(null);
try {
command.perform(saContext, config);
fail("Didn't throw an illegal argument exception on null forward path");
} catch (IllegalArgumentException ex) {
System.out.println("exception: " + ex.getMessage());
// Do nothing, the test passed
}
}
use of org.apache.struts.config.ForwardConfig in project sonarqube by SonarSource.
the class PerformForward method perform.
// ------------------------------------------------------- Protected Methods
/**
* <p>Perform the appropriate processing on the specified
* <code>ForwardConfig</code>.</p>
*
* @param context The context for this request
* @param forwardConfig The forward to be performed
*/
protected void perform(ActionContext context, ForwardConfig forwardConfig) throws Exception {
ServletActionContext sacontext = (ServletActionContext) context;
String uri = forwardConfig.getPath();
if (uri == null) {
ActionServlet servlet = sacontext.getActionServlet();
MessageResources resources = servlet.getInternal();
throw new IllegalArgumentException(resources.getMessage("forwardPathNull"));
}
HttpServletRequest request = sacontext.getRequest();
ServletContext servletContext = sacontext.getContext();
HttpServletResponse response = sacontext.getResponse();
// If the forward can be unaliased into an action, then use the path of the action
String actionIdPath = RequestUtils.actionIdURL(forwardConfig, sacontext.getRequest(), sacontext.getActionServlet());
if (actionIdPath != null) {
uri = actionIdPath;
ForwardConfig actionIdForwardConfig = new ForwardConfig(forwardConfig);
actionIdForwardConfig.setPath(actionIdPath);
forwardConfig = actionIdForwardConfig;
}
if (uri.startsWith("/")) {
uri = resolveModuleRelativePath(forwardConfig, servletContext, request);
}
if (response.isCommitted() && !forwardConfig.getRedirect()) {
handleAsInclude(uri, servletContext, request, response);
} else if (forwardConfig.getRedirect()) {
handleAsRedirect(uri, request, response);
} else {
handleAsForward(uri, servletContext, request, response);
}
}
use of org.apache.struts.config.ForwardConfig in project sonarqube by SonarSource.
the class RequestProcessor method processValidate.
/**
* <p>If this request was not cancelled, and the request's {@link
* ActionMapping} has not disabled validation, call the
* <code>validate</code> method of the specified {@link ActionForm}, and
* forward to the input path if there were any errors. Return
* <code>true</code> if we should continue processing, or
* <code>false</code> if we have already forwarded control back to the
* input form.</p>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param form The ActionForm instance we are populating
* @param mapping The ActionMapping we are using
* @return <code>true</code> to continue normal processing;
* <code>false</code> if a response has been created.
* @throws IOException if an input/output error occurs
* @throws ServletException if a servlet exception occurs
* @throws InvalidCancelException if a cancellation is attempted
* without the proper action configuration.
*/
protected boolean processValidate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws IOException, ServletException, InvalidCancelException {
if (form == null) {
return (true);
}
// Has validation been turned off for this mapping?
if (!mapping.getValidate()) {
return (true);
}
// error or a spoof.
if (request.getAttribute(Globals.CANCEL_KEY) != null) {
if (mapping.getCancellable()) {
if (log.isDebugEnabled()) {
log.debug(" Cancelled transaction, skipping validation");
}
return (true);
} else {
request.removeAttribute(Globals.CANCEL_KEY);
throw new InvalidCancelException();
}
}
// Call the form bean's validation method
if (log.isDebugEnabled()) {
log.debug(" Validating input form properties");
}
ActionMessages errors = form.validate(mapping, request);
if ((errors == null) || errors.isEmpty()) {
if (log.isTraceEnabled()) {
log.trace(" No errors detected, accepting input");
}
return (true);
}
// Special handling for multipart request
if (form.getMultipartRequestHandler() != null) {
if (log.isTraceEnabled()) {
log.trace(" Rolling back multipart request");
}
form.getMultipartRequestHandler().rollback();
}
// Was an input path (or forward) specified for this mapping?
String input = mapping.getInput();
if (input == null) {
if (log.isTraceEnabled()) {
log.trace(" Validation failed but no input form available");
}
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getInternal().getMessage("noInput", mapping.getPath()));
return (false);
}
// Save our error messages and return to the input form if possible
if (log.isDebugEnabled()) {
log.debug(" Validation failed, returning to '" + input + "'");
}
request.setAttribute(Globals.ERROR_KEY, errors);
if (moduleConfig.getControllerConfig().getInputForward()) {
ForwardConfig forward = mapping.findForward(input);
processForwardConfig(request, response, forward);
} else {
internalModuleRelativeForward(input, request, response);
}
return (false);
}
use of org.apache.struts.config.ForwardConfig in project sonarqube by SonarSource.
the class ActionServlet method processForwardConfigClass.
/**
* <p>Checks if the current forwardConfig is using the correct class based
* on the class of its configuration ancestor. If actionConfig is
* provided, then this method will process the forwardConfig as part
* of that actionConfig. If actionConfig is null, the forwardConfig
* will be processed as a global forward.</p>
*
* @param forwardConfig The forward to check.
* @param moduleConfig The config for the current module.
* @param actionConfig If applicable, the config for the current action.
* @return The forward config using the correct class as determined by the
* config's ancestor and its own overridden value.
* @throws UnavailableException if an instance of the forward config class
* cannot be created.
* @throws ServletException on class creation error
*/
protected ForwardConfig processForwardConfigClass(ForwardConfig forwardConfig, ModuleConfig moduleConfig, ActionConfig actionConfig) throws ServletException {
String ancestor = forwardConfig.getExtends();
if (ancestor == null) {
// Nothing to do, then
return forwardConfig;
}
// Make sure that this config is of the right class
ForwardConfig baseConfig = null;
if (actionConfig != null) {
// Look for this in the actionConfig
baseConfig = actionConfig.findForwardConfig(ancestor);
}
if (baseConfig == null) {
// Either this is a forwardConfig that inherits a global config,
// or actionConfig is null
baseConfig = moduleConfig.findForwardConfig(ancestor);
}
if (baseConfig == null) {
throw new UnavailableException("Unable to find " + "forward '" + ancestor + "' to extend.");
}
// Was our forwards's class overridden already?
if (forwardConfig.getClass().equals(ActionForward.class)) {
// Ensure that our forward is using the correct class
if (!baseConfig.getClass().equals(forwardConfig.getClass())) {
// Replace the config with an instance of the correct class
ForwardConfig newForwardConfig = null;
String baseConfigClassName = baseConfig.getClass().getName();
try {
newForwardConfig = (ForwardConfig) RequestUtils.applicationInstance(baseConfigClassName);
// copy the values
BeanUtils.copyProperties(newForwardConfig, forwardConfig);
} catch (Exception e) {
handleCreationException(baseConfigClassName, e);
}
// replace forwardConfig with newForwardConfig
if (actionConfig != null) {
actionConfig.removeForwardConfig(forwardConfig);
actionConfig.addForwardConfig(newForwardConfig);
} else {
// this is a global forward
moduleConfig.removeForwardConfig(forwardConfig);
moduleConfig.addForwardConfig(newForwardConfig);
}
forwardConfig = newForwardConfig;
}
}
return forwardConfig;
}
Aggregations