You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Roberto Rossi <im...@gmail.com> on 2009/05/27 22:54:50 UTC

velocity context problem

Hi everyone.
I'd like to share a very strange behaviour of the velocity context
using the velocity bridge.
I'm using Jetspeed 2.1.2 with Tomcat 6 and Velocity 1.5 (Velocity Tools 1.3).
I found that in case of many concurrent requests to a psml page made
by many fragments of velocity portlets the velocity templates are not
receiving correct objects.

My portlets (at the end of their execution) call context.put("object",
object) but the template is not receiving the correct object and
inside the variable $object there is another object
(put before in the context by some other portlet using the same key).
With just 1 request there are no problems, but using a repeated wget
command in background (like this: for i in `seq 0 500`; do wget
"http://www.sample.com/jetspeed/portal/page.psml"; done) and asking
for the same psml page the objects to velocity templates are often
wrong .

The velocity context shouldn't be empty for every portlet fragment?
I checked all my objects before putting them in the context (logging
their properties) and they are all right.
Any ideas about this problem? Maybe I'm wrong in my portlet
development approach?
I cannot found the reason for this issue, but I think it is very
urgent (if we can confirm that it's a bug).
-----------------------------------

This is my portlet code writing approach:

import ...

public class MyVelocityPortlet extends GenericVelocityPortlet {
       // some private variables

      public void doView(javax.portlet.RenderRequest request,
javax.portlet.RenderResponse response)
throws javax.portlet.PortletException, java.io.IOException
{
                            PortletContext portletContext = null;
PortletRequestDispatcher portletRequestDispatcher = null;

                            // obtaining the velocity context
context = getContext(request);

                            // portlet relevant code
                            ...

                            // putting object to context (in this case a menu)
                            context.put("object", object);

                             /* go to template */
response.setContentType("text/html");
portletContext = (PortletContext) this.getPortletContext();

portletRequestDispatcher = (PortletRequestDispatcher)
portletContext.getRequestDispatcher("view.vm");
portletRequestDispatcher.include(request,response);
      }
}


ROb

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity context problem

Posted by Roberto Rossi <ro...@cone.it>.
I used wget only to simulate many concurrent requests but I tested the
velocity objects problems using my Firefox and reading catalina logs.

Reading the wrong generated html I can find that velocity templates are
receiving wrong objects.
In my psml page I have 3 portlets for rendering 3 menus. 
The first one at the beginning of the page called "main" inside a $menu
object, the second one just one row below called "submain" inside
another $menu object (but in another portlet and another template) and
the third one at the bottom of the page called "internal" inside another
$menu object.
Navigating this page with no load all the templates can render the right
menu and thet can find the exact $menu object passed from the portlet,
but when I started the wget command the $menu seems to contain
completely  random objects (even from portlet of the page requested
using wget).

As you can see from my posted code the portlet is giving a $object to
the template... (in the real example is context.put("menu", menu) ) and
the template should receive the exact $menu object given from the
portlet. This is always right except when there are many concurrent
requests.

Re: velocity context problem

Posted by Roberto Rossi <ro...@cone.it>.
Sorry I used my other email address... I'm always Roberto Rossi :-) .

Re: velocity context problem

Posted by Mansour Al Akeel <ma...@gmail.com>.
Roberto:

May be it will help if you can tell when the objects are failing to be
attached to the context. Here's an example script that will let us know. 
I didn't test this script. I need it to stop when the problem occurs.
Then we can move from there.

for i in `seq 0 500` ;
do
    /usr/bin/wget url  #use the full path to wget to avoid an alias (ie,  --spider or -b )

    grep theText > /dev/null
    if [ "$?"  = "1" ] ; 
    then
        echo "Failed at i=" $i ;
        break;
    fi
done





On Wed May 27,2009 10:54 pm, Roberto Rossi wrote:
> Hi everyone.
> I'd like to share a very strange behaviour of the velocity context
> using the velocity bridge.
> I'm using Jetspeed 2.1.2 with Tomcat 6 and Velocity 1.5 (Velocity Tools 1.3).
> I found that in case of many concurrent requests to a psml page made
> by many fragments of velocity portlets the velocity templates are not
> receiving correct objects.
> 
> My portlets (at the end of their execution) call context.put("object",
> object) but the template is not receiving the correct object and
> inside the variable $object there is another object
> (put before in the context by some other portlet using the same key).
> With just 1 request there are no problems, but using a repeated wget
> command in background (like this: for i in `seq 0 500`; do wget
> "http://www.sample.com/jetspeed/portal/page.psml"; done) and asking
> for the same psml page the objects to velocity templates are often
> wrong .
> 
> The velocity context shouldn't be empty for every portlet fragment?
> I checked all my objects before putting them in the context (logging
> their properties) and they are all right.
> Any ideas about this problem? Maybe I'm wrong in my portlet
> development approach?
> I cannot found the reason for this issue, but I think it is very
> urgent (if we can confirm that it's a bug).
> -----------------------------------
> 
> This is my portlet code writing approach:
> 
> import ...
> 
> public class MyVelocityPortlet extends GenericVelocityPortlet {
>        // some private variables
> 
>       public void doView(javax.portlet.RenderRequest request,
> javax.portlet.RenderResponse response)
> throws javax.portlet.PortletException, java.io.IOException
> {
>                             PortletContext portletContext = null;
> PortletRequestDispatcher portletRequestDispatcher = null;
> 
>                             // obtaining the velocity context
> context = getContext(request);
> 
>                             // portlet relevant code
>                             ...
> 
>                             // putting object to context (in this case a menu)
>                             context.put("object", object);
> 
>                              /* go to template */
> response.setContentType("text/html");
> portletContext = (PortletContext) this.getPortletContext();
> 
> portletRequestDispatcher = (PortletRequestDispatcher)
> portletContext.getRequestDispatcher("view.vm");
> portletRequestDispatcher.include(request,response);
>       }
> }
> 
> 
> ROb
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org