DWR

Make it easier to plug in a ScriptSessionListener

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Normal Normal
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: 3.0.1
  • Component/s: Core, Reverse Ajax
  • Documentation Required:
    No
  • Description:
    Hide
    Plugging in a ScriptSessionListener is currently quite difficult and involves looking up the ScriptSessionManager and calling addScriptSessionListener. This code also needs to execute after DWR initializes so users are forced to extend the DWR servlet or use another servlet to execute this code.

    It would be nice to use DWR's dependency injection mechinism to do this...perhaps something like:

    <init-param>
       <param-name>org.directwebremoting.event.ScriptSessionListener[0]</param-name>
       <param-value>foo.bar.MyFirstScriptSessionListener</param-value>
    </init-param>
    <init-param>
       <param-name>org.directwebremoting.event.ScriptSessionListener[1]</param-name>
       <param-value>foo.bar.MySecondScriptSessionListener</param-value>
    </init-param>
    Show
    Plugging in a ScriptSessionListener is currently quite difficult and involves looking up the ScriptSessionManager and calling addScriptSessionListener. This code also needs to execute after DWR initializes so users are forced to extend the DWR servlet or use another servlet to execute this code. It would be nice to use DWR's dependency injection mechinism to do this...perhaps something like: <init-param>    <param-name>org.directwebremoting.event.ScriptSessionListener[0]</param-name>    <param-value>foo.bar.MyFirstScriptSessionListener</param-value> </init-param> <init-param>    <param-name>org.directwebremoting.event.ScriptSessionListener[1]</param-name>    <param-value>foo.bar.MySecondScriptSessionListener</param-value> </init-param>

Activity

Hide
Jose Noheda added a comment - 21/May/09 12:22 PM

I think a <dwr:script-session-listener /> is feasible. Let me know if you're interested

Show
Jose Noheda added a comment - 21/May/09 12:22 PM I think a <dwr:script-session-listener /> is feasible. Let me know if you're interested
Hide
Lance Semmens added a comment - 21/May/09 1:46 PM

Perhaps we can use a dependency injection similar to Spring MVC (for example LocaleResolver)
ie add every bean defined that implements ScriptSessionListener

This would mean we don't need a new tag for each type.

We could use this to mechanism inject Container, ScriptSessionManager, etc etc and it would be quite intuitive to someone who's used to using DWR dependency injection from web.xml.

Show
Lance Semmens added a comment - 21/May/09 1:46 PM Perhaps we can use a dependency injection similar to Spring MVC (for example LocaleResolver) ie add every bean defined that implements ScriptSessionListener This would mean we don't need a new tag for each type. We could use this to mechanism inject Container, ScriptSessionManager, etc etc and it would be quite intuitive to someone who's used to using DWR dependency injection from web.xml.
Hide
Jose Noheda added a comment - 21/May/09 2:11 PM

DwrController accepts init-params in the same way the Servlet does so once this issue is resolved we will accept (without extra effort) something like:

<dwr:controller debug="true">
<dwr:param name="org.directwebremoting.event.ScriptSessionListener" value="foo.Bar" />
</dwr:controller>

The usefulness of <dwr:script-session-listener ref="myBean" /> would be to configure the listener as a bean and inherit all the goodies that Spring provides in this area. Similar to the <dwr:converter /> tag. Of course, this solution does not scale well. It just comes handy for specific use cases.

Show
Jose Noheda added a comment - 21/May/09 2:11 PM DwrController accepts init-params in the same way the Servlet does so once this issue is resolved we will accept (without extra effort) something like: <dwr:controller debug="true"> <dwr:param name="org.directwebremoting.event.ScriptSessionListener" value="foo.Bar" /> </dwr:controller> The usefulness of <dwr:script-session-listener ref="myBean" /> would be to configure the listener as a bean and inherit all the goodies that Spring provides in this area. Similar to the <dwr:converter /> tag. Of course, this solution does not scale well. It just comes handy for specific use cases.
Hide
Lance Semmens added a comment - 21/May/09 3:21 PM

Yes... which is exactly what I was saying.

Instead of <dwr:script-session-listener ref="myBean" />
I was suggesting <bean class="foo.bar.MyScriptSessionListener" />

And DWR / Spring integration sees that there's a bean in the application context that implements ScriptSessionListener and plugs it in the right spot... no extra tag needed. This could be used for all pluggable classes in DWR.

Show
Lance Semmens added a comment - 21/May/09 3:21 PM Yes... which is exactly what I was saying. Instead of <dwr:script-session-listener ref="myBean" /> I was suggesting <bean class="foo.bar.MyScriptSessionListener" /> And DWR / Spring integration sees that there's a bean in the application context that implements ScriptSessionListener and plugs it in the right spot... no extra tag needed. This could be used for all pluggable classes in DWR.
Hide
Jose Noheda added a comment - 21/May/09 4:03 PM

Sorry, you're right. I should have started by saying that's a feature that I don't like too much (magic all around)

So, for a listener like <bean class="foo.BarListener" /> no work is needed because it should be covered by a param of DWRController.

For a complex listener we could have the new tag (<dwr:script-session.../>) or not.

Pros (of the new tag):

  • The configuration is easier to understand
  • It's more akin to the current way of doing things
  • Beans can be defined in a different context than DWR (in a parent context for example)

Cons:

  • It "pollutes" the XML
  • It does not scale with the number of components.

The work to implement both alternatives seems similar. The tag requires a new method in the namespace handler. Otherwise we would probably need a BeanPostProcessor. It's just a guess but I think the later would be a bit slower. And, of course, it has to take care of the initialization order (ensure that DWR has been at least instantiated).

Show
Jose Noheda added a comment - 21/May/09 4:03 PM Sorry, you're right. I should have started by saying that's a feature that I don't like too much (magic all around) So, for a listener like <bean class="foo.BarListener" /> no work is needed because it should be covered by a param of DWRController. For a complex listener we could have the new tag (<dwr:script-session.../>) or not. Pros (of the new tag):
  • The configuration is easier to understand
  • It's more akin to the current way of doing things
  • Beans can be defined in a different context than DWR (in a parent context for example)
Cons:
  • It "pollutes" the XML
  • It does not scale with the number of components.
The work to implement both alternatives seems similar. The tag requires a new method in the namespace handler. Otherwise we would probably need a BeanPostProcessor. It's just a guess but I think the later would be a bit slower. And, of course, it has to take care of the initialization order (ensure that DWR has been at least instantiated).
Hide
Lance Semmens added a comment - 21/May/09 6:14 PM

Perhaps this is cleaner

<dwr:controller debug="true">
<dwr:param name="org.directwebremoting.event.ScriptSessionListener" value-ref="myScriptSessionListener" />
</dwr:controller>

<bean id="myScriptSessionListener" class="foo.bar.MyScriptSessionListener">
<property name="..." value="..." />
</bean>

Show
Lance Semmens added a comment - 21/May/09 6:14 PM Perhaps this is cleaner <dwr:controller debug="true"> <dwr:param name="org.directwebremoting.event.ScriptSessionListener" value-ref="myScriptSessionListener" /> </dwr:controller> <bean id="myScriptSessionListener" class="foo.bar.MyScriptSessionListener"> <property name="..." value="..." /> </bean>

People

Dates

  • Created:
    19/May/09 11:15 AM
    Updated:
    13/Apr/11 12:04 PM