You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2005/05/03 09:10:24 UTC

svn commit: r167876 - in /incubator/beehive/trunk/netui: src/pageflow/org/apache/beehive/netui/pageflow/ src/pageflow/org/apache/beehive/netui/pageflow/internal/ src/tags-html/org/apache/beehive/netui/tags/internal/ test/webapps/drt/coreWeb/miniTests/linkNav/ test/webapps/drt/coreWeb/miniTests/pageFlowUtils/ test/webapps/drt/testRecorder/tests/

Author: rich
Date: Tue May  3 00:10:23 2005
New Revision: 167876

URL: http://svn.apache.org/viewcvs?rev=167876&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/BEEHIVE-595 : PageFlowUtils getActionURI() does not handle qualified action paths correctly

tests: bvt in netui (WinXP)
BB: self (linux)


Modified:
    incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
    incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
    incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalUtils.java
    incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/linkNav/Begin.jsp
    incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/pageFlowUtils/index.jsp
    incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/PageFlowUtils.xml

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java?rev=167876&r1=167875&r2=167876&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java (original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java Tue May  3 00:10:23 2005
@@ -1955,7 +1955,8 @@
      * Create a raw action URI, which can be modified before being sent through the registered URL rewriting chain
      * using {@link org.apache.beehive.netui.core.urls.URLRewriterService#rewriteURL}.
      *
-     * @param actionName the action name to convert into a MutableURI.
+     * @param actionName the action name to convert into a MutableURI; may be qualified with a path from the webapp
+     *            root, in which case the parent directory from the current request is <i>not</i> used.
      * @return a MutableURI for the given action, suitable for URL rewriting.
      * @throws URISyntaxException    if there is a problem converting the action URI (derived
      *                               from processing the given action name) into a MutableURI.
@@ -1981,7 +1982,8 @@
     /**
      * Create a fully-rewritten URI given an action and parameters.
      *
-     * @param actionName the action name to convert into a fully-rewritten URI.
+     * @param actionName the action name to convert into a fully-rewritten URI; may be qualified with a path from the
+     *            webapp root, in which case the parent directory from the current request is <i>not</i> used.
      * @param parameters the additional parameters to include in the URI query.
      * @param asValidXml flag indicating that the query of the uri should be written
      *                   using the &quot;&amp;amp;&quot; entity, rather than the character, '&amp;'

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java?rev=167876&r1=167875&r2=167876&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java (original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java Tue May  3 00:10:23 2005
@@ -1263,12 +1263,13 @@
 
     /**
      * Create a raw action URI, which can be modified before being sent through the registered URL rewriting chain
-     * using {@link URLRewriterService#rewriteURL}.
+     * using {@link URLRewriterService#rewriteURL}.  Use {@link #getRewrittenActionURI} to get a fully-rewritten URI.
      *
      * @param servletContext the current ServletContext.
      * @param request the current HttpServletRequest.
      * @param response the current HttpServletResponse.
-     * @param actionName the action name to convert into a MutableURI.
+     * @param actionName the action name to convert into a MutableURI; may be qualified with a path from the webapp
+     *            root, in which case the parent directory from the current request is <i>not</i> used.
      * @return a MutableURI for the given action, suitable for URL rewriting.
      * @throws URISyntaxException if there is a problem converting the action URI (derived from processing the given
      *             action name) into a MutableURI.
@@ -1277,22 +1278,33 @@
                                            HttpServletResponse response, String actionName )
             throws URISyntaxException
     {
-        String qualifiedAction = InternalUtils.qualifyAction( servletContext, actionName );
-        String actionUrl = InternalUtils.createActionURL( request, qualifiedAction );
+        if ( actionName.length() < 1 ) throw new IllegalArgumentException( "actionName must be non-empty" );
+        
+        InternalStringBuilder actionURI = new InternalStringBuilder( request.getContextPath() );
+        
+        if ( actionName.charAt( 0 ) != '/' )
+        {
+            actionURI.append( getModulePath( request ) );
+            actionURI.append( '/' );
+        }
+        
+        actionURI.append( actionName );
+        if ( ! actionName.endsWith( ACTION_EXTENSION ) ) actionURI.append( ACTION_EXTENSION );
+        
         FreezableMutableURI uri = new FreezableMutableURI();
         uri.setEncoding( response.getCharacterEncoding() );
-        uri.setURI( actionUrl, true );
-
+        uri.setURI( actionURI.toString(), true );
         return uri;
     }
-
+    
     /**
      * Create a fully-rewritten URI given an action name and parameters.
      *
      * @param servletContext the current ServletContext.
      * @param request the current HttpServletRequest.
      * @param response the current HttpServletResponse.
-     * @param actionName the action name to convert into a fully-rewritten URI.
+     * @param actionName the action name to convert into a fully-rewritten URI; may be qualified with a path from the
+     *            webapp root, in which case the parent directory from the current request is <i>not</i> used.
      * @param params the additional parameters to include in the URI query.
      * @param fragment the fragment (anchor or location) for this url.
      * @param forXML flag indicating that the query of the uri should be written
@@ -1306,23 +1318,11 @@
                                                 String fragment, boolean forXML )
             throws URISyntaxException
     {
-        String qualifiedAction = InternalUtils.qualifyAction( servletContext, actionName );
-        String actionUrl = InternalUtils.createActionURL( request, qualifiedAction );
-        FreezableMutableURI uri = new FreezableMutableURI();
-        uri.setEncoding( response.getCharacterEncoding() );
-        uri.setURI( actionUrl, true );
-
-        if ( params != null )
-        {
-            uri.addParameters( params, false );
-        }
-
-        if ( fragment != null )
-        {
-            uri.setFragment( uri.encode( fragment ) );
-        }
+        MutableURI uri = getActionURI( servletContext, request, response, actionName );
+        if ( params != null ) uri.addParameters( params, false );
+        if ( fragment != null ) uri.setFragment( uri.encode( fragment ) );
 
-        boolean needsToBeSecure = needsToBeSecure( servletContext, request, actionUrl, true );
+        boolean needsToBeSecure = needsToBeSecure( servletContext, request, uri.getPath(), true );
         URLRewriterService.rewriteURL( servletContext, request, response, uri, URLType.ACTION, needsToBeSecure );
         String key = getURLTemplateKey( URLType.ACTION, needsToBeSecure );
         URIContext uriContext = URIContextFactory.getInstance( forXML );

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalUtils.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalUtils.java?rev=167876&r1=167875&r2=167876&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalUtils.java (original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalUtils.java Tue May  3 00:10:23 2005
@@ -731,10 +731,14 @@
         return ( ( HttpServletRequest ) request ).getSession( create );
     }
 
+    /**
+     * Simply adds the context path and parent directory, based on the current request URI.
+     */ 
     public static String createActionURL( HttpServletRequest servletRequest, String qualifiedAction )
     {
         String pageURI = getDecodedURI( servletRequest );
         int lastSlash = pageURI.lastIndexOf( '/' );
+        
         if ( lastSlash != -1 )
         {
             InternalStringBuilder value = new InternalStringBuilder( qualifiedAction.length() + lastSlash );
@@ -749,6 +753,7 @@
     public static String createActionPath( ServletRequest request, String qualifiedAction )
     {
         ModuleConfig appConfig = ( ModuleConfig ) request.getAttribute( Globals.MODULE_KEY );
+        
         if ( appConfig != null )
         {
             InternalStringBuilder value = new InternalStringBuilder( qualifiedAction.length() + 16 );
@@ -765,50 +770,15 @@
         assert action != null;
         InternalStringBuilder sb = null;
 
-        // Use our servlet mapping, if one is specified
-        String servletMapping = ( String ) servletContext.getAttribute( Globals.SERVLET_KEY );
-        if ( servletMapping != null )
-        {
-            String queryString = null;
-            int question = action.indexOf( '?' );
-            if ( question >= 0 )
-            {
-                queryString = action.substring( question );
-            }
-
-            String actionMapping = getActionMappingName( action );
-            sb = new InternalStringBuilder( actionMapping.length() + servletMapping.length() + question + 1 );
-            if ( servletMapping.startsWith( "*." ) )
-            {
-                sb.append( actionMapping );
-                sb.append( servletMapping.substring( 1 ) );
-            }
-            else if ( servletMapping.endsWith( "/*" ) )
-            {
-                sb.append( servletMapping.substring( 0, servletMapping.length() - 2 ) );
-                sb.append( actionMapping );
-            }
-            else if ( servletMapping.equals( "/" ) )
-            {
-                sb.append( actionMapping );
-            }
-            if ( queryString != null )
-            {
-                sb.append( queryString );
-            }
-        }
-
-        // Otherwise, assume extension mapping is in use and extension is
-        // already included in the action property
-        else
-        {
-            sb = new InternalStringBuilder(action.length() + 1 );
-            if ( !action.startsWith( "/" ) )
-            {
-                sb.append( '/' );
-            }
-            sb.append( action );
-        }
+        String queryString = null;
+        int question = action.indexOf( '?' );
+        if ( question >= 0 ) queryString = action.substring( question );
+
+        String actionMapping = getActionMappingName( action );
+        sb = new InternalStringBuilder( action.length() + ACTION_EXTENSION_LEN + 1 );
+        sb.append( actionMapping );
+        sb.append( ACTION_EXTENSION );
+        if ( queryString != null ) sb.append( queryString );
 
         return sb.toString();
     }

Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java?rev=167876&r1=167875&r2=167876&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java (original)
+++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java Tue May  3 00:10:23 2005
@@ -63,6 +63,7 @@
         HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
         HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
         boolean forXML = TagRenderingBase.Factory.isXHTML(request);
+        if (action.length() > 0 && action.charAt(0) == '/') action = action.substring(1);
         return PageFlowUtils.getRewrittenActionURI(servletContext, request, response, action, params, location, forXML);
     }
 

Modified: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/linkNav/Begin.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/linkNav/Begin.jsp?rev=167876&r1=167875&r2=167876&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/linkNav/Begin.jsp (original)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/linkNav/Begin.jsp Tue May  3 00:10:23 2005
@@ -4,7 +4,7 @@
 <title>Link Submit</title>
 </head>
 <body>
-<netui:anchor action="/linkOne" >Link One</netui:anchor>
+<netui:anchor action="linkOne" >Link One</netui:anchor>
 <netui:anchor action="/linkTwo" >Link Two</netui:anchor>
 <br />
 Last Action: <netui:span value="${pageFlow.action}"/>

Modified: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/pageFlowUtils/index.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/pageFlowUtils/index.jsp?rev=167876&r1=167875&r2=167876&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/pageFlowUtils/index.jsp (original)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/pageFlowUtils/index.jsp Tue May  3 00:10:23 2005
@@ -141,12 +141,15 @@
         <code>getActionURI( cxt, request, response, "begin" )</code>:
             <%= PageFlowUtils.getActionURI( cxt, request, response, "begin" ).getURIString( null ) %><br>
 
+        <code>getActionURI( cxt, request, response, "/relative/to/webapp/root" )</code>:
+            <%= PageFlowUtils.getActionURI( cxt, request, response, "/relative/to/webapp/root" ).getURIString( null ) %><br>
+
         <% java.util.HashMap params = new java.util.HashMap(); params.put( "foo", "bar" ); %>
         <code>PageFlowUtils.getRewrittenActionURI( cxt, request, response, "begin", params, "frag", true )</code>:
             <%= PageFlowUtils.getRewrittenActionURI( cxt, request, response, "begin", params, "frag", true ) %><br>
 
         <code>PageFlowUtils.getRewrittenResourceURI( cxt, request, response, "index.jsp", params, "frag", true )</code>:
-            <%= PageFlowUtils.getRewrittenActionURI( cxt, request, response, "index.jsp", params, "frag", true ) %><br>
+            <%= PageFlowUtils.getRewrittenResourceURI( cxt, request, response, "index.jsp", params, "frag", true ) %><br>
 
         <br>
         <br>

Modified: incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/PageFlowUtils.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/PageFlowUtils.xml?rev=167876&r1=167875&r2=167876&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/PageFlowUtils.xml (original)
+++ incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/PageFlowUtils.xml Tue May  3 00:10:23 2005
@@ -199,12 +199,15 @@
         <code>getActionURI( cxt, request, response, "begin" )</code>:
             /coreWeb/miniTests/pageFlowUtils/begin.do<br>
 
+        <code>getActionURI( cxt, request, response, "/relative/to/webapp/root" )</code>:
+            /coreWeb/relative/to/webapp/root.do<br>
+
         
         <code>PageFlowUtils.getRewrittenActionURI( cxt, request, response, "begin", params, "frag", true )</code>:
             /coreWeb/miniTests/pageFlowUtils/begin.do?foo=bar#frag<br>
 
         <code>PageFlowUtils.getRewrittenResourceURI( cxt, request, response, "index.jsp", params, "frag", true )</code>:
-            /coreWeb/miniTests/pageFlowUtils/index.jsp.do?foo=bar#frag<br>
+            /coreWeb/miniTests/pageFlowUtils/index.jsp?foo=bar#frag<br>
 
         <br>
         <br>
@@ -510,12 +513,15 @@
         <code>getActionURI( cxt, request, response, "begin" )</code>:
             /coreWeb/miniTests/pageFlowUtils/begin.do<br>
 
+        <code>getActionURI( cxt, request, response, "/relative/to/webapp/root" )</code>:
+            /coreWeb/relative/to/webapp/root.do<br>
+
         
         <code>PageFlowUtils.getRewrittenActionURI( cxt, request, response, "begin", params, "frag", true )</code>:
             /coreWeb/miniTests/pageFlowUtils/begin.do?foo=bar#frag<br>
 
         <code>PageFlowUtils.getRewrittenResourceURI( cxt, request, response, "index.jsp", params, "frag", true )</code>:
-            /coreWeb/miniTests/pageFlowUtils/index.jsp.do?foo=bar#frag<br>
+            /coreWeb/miniTests/pageFlowUtils/index.jsp?foo=bar#frag<br>
 
         <br>
         <br>