DWR

Allow embedded Jetty, DWR and my own beans in one Spring context

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 2.0.rc2
  • Fix Version/s: 4.0
  • Component/s: Spring
  • Description:
    Hide
    Hi,

    I need to use Embedded Jetty, DWR and my own beans in one Spring context. In order to do it I need to execute this steps:

    1. Describe Jetty classes as Spring beans without using WebAppContext and WEB-INF/web.xml because in this case DwrServlet will be injected by Jetty code but I need to inject DwrServlet from Spring context.

    2. Configure DwrServlet from Spring context.

    First task can be implemented like this:

        <bean id="jetty" class="org.mortbay.jetty.Server" init-method="start" destroy-method="stop">
            <property name="connectors">
                <list>
                    <bean class="org.mortbay.jetty.nio.SelectChannelConnector">
                        <property name="port" value="8080"/>
                    </bean>
                </list>
            </property>
            <property name="handlers">
                <list>
                    <bean class="org.mortbay.jetty.handler.ResourceHandler">
                        <property name="resourceBase" value="web"/>
                    </bean>
                    <bean class="org.mortbay.jetty.servlet.Context">
                        <constructor-arg><null/></constructor-arg>
                        <constructor-arg>
                            <bean class="org.mortbay.jetty.servlet.SessionHandler"/>
                        </constructor-arg>
                        <constructor-arg><null/></constructor-arg>
                        <constructor-arg>
                            <bean class="org.mortbay.jetty.servlet.ServletHandler">
                                <property name="servlets">
                                    <list>
                                        <bean class="org.mortbay.jetty.servlet.ServletHolder">
                                            <constructor-arg ref="dwrServlet"/>
                                            <property name="name" value="dwr"/>
                                            <property name="initParameters">
                                                <map>
                                                    <entry key="debug" value="true"/>
                                                    <entry key="pollAndCometEnabled" value="true"/>
                                                    <entry key="continuationsEnabled" value="false"/>
                                                </map>
                 
                                            </property>
                                        </bean>
                                    </list>
                                </property>
                                <property name="servletMappings">
                                    <list>
                                        <bean class="org.mortbay.jetty.servlet.ServletMapping">
                                            <property name="servletName" value="dwr"/>
                                            <property name="pathSpec" value="/dwr/*"/>
                                        </bean>
                                    </list>
                                </property>
                            </bean>
                        </constructor-arg>
                        <constructor-arg><null/></constructor-arg>
                        <property name="contextPath" value="/"/>
                    </bean>
                </list>
            </property>
        </bean>

    The best entry point for second task is DwrSpringServlet and SpringConfigurator classes. SpringConfigurator class can be used without any changes, but it is impossible to use DwrSpringServlet as is due to this error:

    ERROR DwrSpringServlet - init failed
    java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
            at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
            at org.directwebremoting.spring.DwrSpringServlet.init(DwrSpringServlet.java:88)
            at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:442)
    ....

    DwrSpringServlet.java:88 is:

    WebApplicationContext webappContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

    To resolve this problem I define DwrSpringServlet as implements BeanFactoryAware by example of DwrController and remove retrieving the configurators from Spring because I have not bean with hardcoded name DwrNamespaceHandler.DEFAULT_SPRING_CONFIGURATOR_ID. Patch is attached.

    So, I can define next part of Spring context which will be looks like:

        <bean id="dwrServlet" class="org.directwebremoting.spring.DwrSpringServlet">
            <property name="configurators">
                <list>
                    <bean class="org.directwebremoting.spring.SpringConfigurator">
                    ...
                    </bean>
                </list>
            </property>
        </bean>

    Another option is DwrServlet modification to support configuration from any Configurator interface instead of hardcoded Spring dependency in DwrSpringServlet.

    Is it possible to support this configuration way in next DWR version out of box (and maybe include this example)?
    Show
    Hi, I need to use Embedded Jetty, DWR and my own beans in one Spring context. In order to do it I need to execute this steps: 1. Describe Jetty classes as Spring beans without using WebAppContext and WEB-INF/web.xml because in this case DwrServlet will be injected by Jetty code but I need to inject DwrServlet from Spring context. 2. Configure DwrServlet from Spring context. First task can be implemented like this:     <bean id="jetty" class="org.mortbay.jetty.Server" init-method="start" destroy-method="stop">         <property name="connectors">             <list>                 <bean class="org.mortbay.jetty.nio.SelectChannelConnector">                     <property name="port" value="8080"/>                 </bean>             </list>         </property>         <property name="handlers">             <list>                 <bean class="org.mortbay.jetty.handler.ResourceHandler">                     <property name="resourceBase" value="web"/>                 </bean>                 <bean class="org.mortbay.jetty.servlet.Context">                     <constructor-arg><null/></constructor-arg>                     <constructor-arg>                         <bean class="org.mortbay.jetty.servlet.SessionHandler"/>                     </constructor-arg>                     <constructor-arg><null/></constructor-arg>                     <constructor-arg>                         <bean class="org.mortbay.jetty.servlet.ServletHandler">                             <property name="servlets">                                 <list>                                     <bean class="org.mortbay.jetty.servlet.ServletHolder">                                         <constructor-arg ref="dwrServlet"/>                                         <property name="name" value="dwr"/>                                         <property name="initParameters">                                             <map>                                                 <entry key="debug" value="true"/>                                                 <entry key="pollAndCometEnabled" value="true"/>                                                 <entry key="continuationsEnabled" value="false"/>                                             </map>                                                       </property>                                     </bean>                                 </list>                             </property>                             <property name="servletMappings">                                 <list>                                     <bean class="org.mortbay.jetty.servlet.ServletMapping">                                         <property name="servletName" value="dwr"/>                                         <property name="pathSpec" value="/dwr/*"/>                                     </bean>                                 </list>                             </property>                         </bean>                     </constructor-arg>                     <constructor-arg><null/></constructor-arg>                     <property name="contextPath" value="/"/>                 </bean>             </list>         </property>     </bean> The best entry point for second task is DwrSpringServlet and SpringConfigurator classes. SpringConfigurator class can be used without any changes, but it is impossible to use DwrSpringServlet as is due to this error: ERROR DwrSpringServlet - init failed java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?         at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)         at org.directwebremoting.spring.DwrSpringServlet.init(DwrSpringServlet.java:88)         at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:442) .... DwrSpringServlet.java:88 is: WebApplicationContext webappContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); To resolve this problem I define DwrSpringServlet as implements BeanFactoryAware by example of DwrController and remove retrieving the configurators from Spring because I have not bean with hardcoded name DwrNamespaceHandler.DEFAULT_SPRING_CONFIGURATOR_ID. Patch is attached. So, I can define next part of Spring context which will be looks like:     <bean id="dwrServlet" class="org.directwebremoting.spring.DwrSpringServlet">         <property name="configurators">             <list>                 <bean class="org.directwebremoting.spring.SpringConfigurator">                 ...                 </bean>             </list>         </property>     </bean> Another option is DwrServlet modification to support configuration from any Configurator interface instead of hardcoded Spring dependency in DwrSpringServlet. Is it possible to support this configuration way in next DWR version out of box (and maybe include this example)?
  1. DwrServlet.patch
    (3 kB)
    Eugene Prokopiev
    14/Mar/07 5:37 AM
  2. embedded-jetty-spring.patch
    (3 kB)
    Joe Walker
    14/Mar/07 11:30 AM

Activity

Hide
Joe Walker added a comment - 13/Mar/07 7:20 PM

More detail and proposed patches: https://dwr.dev.java.net/issues/show_bug.cgi?id=136

Show
Joe Walker added a comment - 13/Mar/07 7:20 PM More detail and proposed patches: https://dwr.dev.java.net/issues/show_bug.cgi?id=136
Hide
Eugene Prokopiev added a comment - 14/Mar/07 5:37 AM

new DwrServlet patch

Show
Eugene Prokopiev added a comment - 14/Mar/07 5:37 AM new DwrServlet patch
Hide
Joe Walker added a comment - 14/Mar/07 11:31 AM

Updated patch that applies cleanly on 2.0 and doesn't kill the namespace handler

Show
Joe Walker added a comment - 14/Mar/07 11:31 AM Updated patch that applies cleanly on 2.0 and doesn't kill the namespace handler
Hide
Joe Walker added a comment - 14/Mar/07 11:32 AM

The patch that I've just attached actually applies. I want to get comment from the Spring guys before I apply it.

Show
Joe Walker added a comment - 14/Mar/07 11:32 AM The patch that I've just attached actually applies. I want to get comment from the Spring guys before I apply it.
Hide
David Marginian added a comment - 14/May/09 4:17 AM

Joe, do you remember what the status of this is?

Show
David Marginian added a comment - 14/May/09 4:17 AM Joe, do you remember what the status of this is?
Hide
David Marginian added a comment - 01/Dec/09 6:54 PM

Jose, thought you would be a good person to look at this.

Show
David Marginian added a comment - 01/Dec/09 6:54 PM Jose, thought you would be a good person to look at this.

People

Dates

  • Created:
    13/Mar/07 7:18 PM
    Updated:
    10/Dec/10 8:25 PM