You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Sergiu Dumitriu <se...@gmail.com> on 2016/11/10 12:19:56 UTC

Re: svn commit: r1769055 - in /velocity/tools/trunk: velocity-tools-generic/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/ velocity-tools-view/src/main/java/o...

On 11/10/2016 03:01 AM, cbrisson@apache.org wrote:
> Author: cbrisson
> Date: Thu Nov 10 08:01:41 2016
> New Revision: 1769055
> 
> URL: http://svn.apache.org/viewvc?rev=1769055&view=rev
> Log:
> [tools] a tool should either be Serializable or forbid Session scope
> 
> Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
> URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java?rev=1769055&r1=1769054&r2=1769055&view=diff
> ==============================================================================
> --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java (original)
> +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java Thu Nov 10 08:01:41 2016
> @@ -31,6 +31,7 @@ import org.apache.velocity.context.Conte
>  import org.apache.velocity.tools.Scope;
>  import org.apache.velocity.tools.ToolContext;
>  import org.apache.velocity.tools.config.DefaultKey;
> +import org.apache.velocity.tools.config.InvalidScope;
>  
>  /**
>   * This tool exposes methods to evaluate the given
> @@ -103,7 +104,9 @@ import org.apache.velocity.tools.config.
>   * @author Nathan Bubna
>   * @version $Revision$ $Date$
>   */
> +
>  @DefaultKey("render")
> +@InvalidScope(Scope.SESSION)

Is it intended to have an IN-valid scope? What prevents it to be used in
a session?

>  public class RenderTool extends SafeConfig
>  {
>      /**
> 

-- 
Sergiu Dumitriu
http://purl.org/net/sergiu/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


Re: svn commit: r1769055 - in /velocity/tools/trunk: velocity-tools-generic/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/ velocity-tools-view/src/main/java/o...

Posted by Nathan Bubna <nb...@gmail.com>.
On Thu, Nov 10, 2016 at 4:19 AM, Sergiu Dumitriu <se...@gmail.com>
wrote:

> On 11/10/2016 03:01 AM, cbrisson@apache.org wrote:
> > Author: cbrisson
> > Date: Thu Nov 10 08:01:41 2016
> > New Revision: 1769055
> >
> > URL: http://svn.apache.org/viewvc?rev=1769055&view=rev
> > Log:
> > [tools] a tool should either be Serializable or forbid Session scope
> >
> > Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/
> org/apache/velocity/tools/generic/RenderTool.java
> > URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-
> tools-generic/src/main/java/org/apache/velocity/tools/
> generic/RenderTool.java?rev=1769055&r1=1769054&r2=1769055&view=diff
> > ============================================================
> ==================
> > --- velocity/tools/trunk/velocity-tools-generic/src/main/java/
> org/apache/velocity/tools/generic/RenderTool.java (original)
> > +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/
> org/apache/velocity/tools/generic/RenderTool.java Thu Nov 10 08:01:41 2016
> > @@ -31,6 +31,7 @@ import org.apache.velocity.context.Conte
> >  import org.apache.velocity.tools.Scope;
> >  import org.apache.velocity.tools.ToolContext;
> >  import org.apache.velocity.tools.config.DefaultKey;
> > +import org.apache.velocity.tools.config.InvalidScope;
> >
> >  /**
> >   * This tool exposes methods to evaluate the given
> > @@ -103,7 +104,9 @@ import org.apache.velocity.tools.config.
> >   * @author Nathan Bubna
> >   * @version $Revision$ $Date$
> >   */
> > +
> >  @DefaultKey("render")
> > +@InvalidScope(Scope.SESSION)
>
> Is it intended to have an IN-valid scope? What prevents it to be used in
> a session?
>
>
Nothing prevents a user from manually inserting one into their session, but
this annotation bans them from configuring VelocityTools to automatically
insert fresh RenderTools into each session for them.


> >  public class RenderTool extends SafeConfig
> >  {
> >      /**
> >
>
> --
> Sergiu Dumitriu
> http://purl.org/net/sergiu/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
> For additional commands, e-mail: dev-help@velocity.apache.org
>
>

Re: svn commit: r1769055 - in /velocity/tools/trunk: velocity-tools-generic/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/ velocity-tools-view/src/main/java/o...

Posted by Sergiu Dumitriu <se...@gmail.com>.
Yep, thanks for clarifying. I was just puzzled because almost all of the
others had @ValidScope(Scope.Application). I guess this one can be used
both in Request and Application scopes, so it was easier to just exclude
the third one than to include these two.

On 11/10/2016 08:58 AM, Claude Brisson wrote:
> When you restart a J2EE container, it will try to serialize the sessions
> on disk to restore them when reloading. This can only works if
> everything in the session is serializable, including the session toolbox
> itself.
> 
> Since the RenderTool keeps references on a VelocityEngine, it cannot be
> serialized. Even if we make the engine as being a transcient field, the
> configure method won't be called upon reload.
> 
> One possible workaround would be to mark it transcient, and have a
> ServletContextListener call session tools configure method, but it could
> induce other side effects. I prefer to mark the RenderTool as invalid in
> the session, as it does not seems a very obvious use case to do so.
> 
> That's also why ValueParser cannot be in the session: a
> Map<String,Object> is not serializable, as Object is not.
> 
> I marked NumberTool, DateTool, ConversionTool and ResourceTool as
> serializable, since they relay on formats or locales which could
> potentially be session-specific.
> 
> Does it make more sense?
> 
>   Claude
> 
> 
>>> Date: Thu Nov 10 08:01:41 2016
>>> New Revision: 1769055
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1769055&view=rev
>>> Log:
>>> [tools] a tool should either be Serializable or forbid Session scope
>>>
>>> Modified:
>>> velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
>>>
>>> URL:
>>> http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java?rev=1769055&r1=1769054&r2=1769055&view=diff
>>>
>>> ==============================================================================
>>>
>>> ---
>>> velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
>>> (original)
>>> +++
>>> velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
>>> Thu Nov 10 08:01:41 2016
>>> @@ -31,6 +31,7 @@ import org.apache.velocity.context.Conte
>>>   import org.apache.velocity.tools.Scope;
>>>   import org.apache.velocity.tools.ToolContext;
>>>   import org.apache.velocity.tools.config.DefaultKey;
>>> +import org.apache.velocity.tools.config.InvalidScope;
>>>     /**
>>>    * This tool exposes methods to evaluate the given
>>> @@ -103,7 +104,9 @@ import org.apache.velocity.tools.config.
>>>    * @author Nathan Bubna
>>>    * @version $Revision$ $Date$
>>>    */
>>> +
>>>   @DefaultKey("render")
>>> +@InvalidScope(Scope.SESSION)
>> Is it intended to have an IN-valid scope? What prevents it to be used in
>> a session?
>>
>>>   public class RenderTool extends SafeConfig
>>>   {
>>>       /**
>>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
> For additional commands, e-mail: dev-help@velocity.apache.org
> 


-- 
Sergiu Dumitriu
http://purl.org/net/sergiu

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


Re: svn commit: r1769055 - in /velocity/tools/trunk: velocity-tools-generic/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/ velocity-tools-view/src/main/java/o...

Posted by Claude Brisson <cl...@renegat.net>.
When you restart a J2EE container, it will try to serialize the sessions 
on disk to restore them when reloading. This can only works if 
everything in the session is serializable, including the session toolbox 
itself.

Since the RenderTool keeps references on a VelocityEngine, it cannot be 
serialized. Even if we make the engine as being a transcient field, the 
configure method won't be called upon reload.

One possible workaround would be to mark it transcient, and have a 
ServletContextListener call session tools configure method, but it could 
induce other side effects. I prefer to mark the RenderTool as invalid in 
the session, as it does not seems a very obvious use case to do so.

That's also why ValueParser cannot be in the session: a 
Map<String,Object> is not serializable, as Object is not.

I marked NumberTool, DateTool, ConversionTool and ResourceTool as 
serializable, since they relay on formats or locales which could 
potentially be session-specific.

Does it make more sense?

   Claude


>> Date: Thu Nov 10 08:01:41 2016
>> New Revision: 1769055
>>
>> URL: http://svn.apache.org/viewvc?rev=1769055&view=rev
>> Log:
>> [tools] a tool should either be Serializable or forbid Session scope
>>
>> Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
>> URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java?rev=1769055&r1=1769054&r2=1769055&view=diff
>> ==============================================================================
>> --- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java (original)
>> +++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/RenderTool.java Thu Nov 10 08:01:41 2016
>> @@ -31,6 +31,7 @@ import org.apache.velocity.context.Conte
>>   import org.apache.velocity.tools.Scope;
>>   import org.apache.velocity.tools.ToolContext;
>>   import org.apache.velocity.tools.config.DefaultKey;
>> +import org.apache.velocity.tools.config.InvalidScope;
>>   
>>   /**
>>    * This tool exposes methods to evaluate the given
>> @@ -103,7 +104,9 @@ import org.apache.velocity.tools.config.
>>    * @author Nathan Bubna
>>    * @version $Revision$ $Date$
>>    */
>> +
>>   @DefaultKey("render")
>> +@InvalidScope(Scope.SESSION)
> Is it intended to have an IN-valid scope? What prevents it to be used in
> a session?
>
>>   public class RenderTool extends SafeConfig
>>   {
>>       /**
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org