From ff78317b63b99df55ed7b391a3d0ed0ac1989f7e Mon Sep 17 00:00:00 2001 From: James Holmes Date: Wed, 1 Aug 2007 01:14:18 +0000 Subject: [PATCH] Log a warning if user specifies a namespace and action with the tag and the action is not found in the namespace. Right now this fails silently and the user gets an HTTP 404 typically. I've had this happen to me and it took a little while to realize I had the wrong namespace or action name. This warning should help users figure out the issue faster by giving them a heads up. git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@561619 13f79535-47bb-0310-9956-ffa450edef68 --- .../components/ServletUrlRenderer.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java index 36e4217c9..f4888acba 100644 --- a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java +++ b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java @@ -23,6 +23,8 @@ package org.apache.struts2.components; import java.io.IOException; import java.io.Writer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.struts2.StrutsException; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.views.util.UrlHelper; @@ -36,6 +38,11 @@ import com.opensymphony.xwork2.config.entities.ActionConfig; * */ public class ServletUrlRenderer implements UrlRenderer { + /** + * Provide a logging instance. + */ + private static final Log LOG = LogFactory.getLog(ServletUrlRenderer.class); + /** * {@inheritDoc} @@ -152,10 +159,14 @@ public class ServletUrlRenderer implements UrlRenderer { } } else if (action != null) { // Since we can't find an action alias in the configuration, we just - // assume - // the action attribute supplied is the path to be used as the uri - // this - // form is submitting to. + // assume the action attribute supplied is the path to be used as + // the URI this form is submitting to. + + // Warn user that the specified namespace/action combo + // was not found in the configuration. + if (namespace != null) { + LOG.warn("No configuration found for the specified action: '" + action + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value."); + } String result = UrlHelper.buildUrl(action, formComponent.request, formComponent.response, null); formComponent.addParameter("action", result); @@ -185,9 +196,7 @@ public class ServletUrlRenderer implements UrlRenderer { // WW-1284 // evaluate if client-side js is to be enabled. (if validation - // interceptor - // does allow validation eg. method is not filtered out) + // interceptor does allow validation eg. method is not filtered out) formComponent.evaluateClientSideJsEnablement(actionName, namespace, actionMethod); } - }