ReverseAJAX + DWRSpringServlet + injecting ServerContext into Service

View: New views
4 Messages — Rating Filter:   Alert me  

ReverseAJAX + DWRSpringServlet + injecting ServerContext into Service

by DNC1234 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi -
I have managed to successfully implement reverse AJAX using DWR. Now the next logical step for me is to make the service creation using Spring. I know that in order to user Spring I have to use DWRSpringServlet. But I am confused as to how my service would get ServerContext injected into it. Without using Spring I am able to provide ServerContext to my service class by:

<init-param>
                <param-name>initApplicationScopeCreatorsAtStartup</param-name>
                <param-value>true</param-value>
</init-param>

for DWR Servlet. and I have the following entry in my dwr.xml:

<dwr>
         <allow>
                <create creator="new" javascript="alertService" scope="application">
                          
                </create>
                <convert converter="bean" match="test.AlertVO" />
        </allow>
</dwr>

and my service class has the following piece of code: -

public class AlertService {

        private static ServerContext serverContext;

        int count = 0;
        /**
         * Constructor
         */
        public AlertService() {
                if (serverContext == null) {
                        WebContext webContext = WebContextFactory.get();
                        ServletContext servletContext = webContext.getServletContext();
                        serverContext = ServerContextFactory.get(servletContext);
                       
                }

All of these are working correct for reverse Ajax when I am not using Spring. But I am unsure as to: -

A) How will I let Spring inject serverContext in my service class? Can I use DWRSpringServlet and set "initApplicationScopeCreatorsAtStartup" to "true" in web.xml?

B) How will I define the Service and the Converter in applicationContext.xml. Given the fact that I do not have any method to expose. rather the service method is invoked by JMS. Basically how do I need to modify my current dwr.xml entries for DWR Spring entries in applicationContext.xml?

If anyone needs more information, I am willing to provide the same. At this point in time, I am stuck without proper guidance.

Best Regards-
DNC

Re: Re[dwr-user] verseAJAX + DWRSpringServlet + injecting ServerContext into Service

by Lance Java :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have your spring bean implement the ServletContextAware interface (spring specific) to get a handle on the servlet context instead of using WebContextFactory.

2009/10/30 DNC1234 <devajyoti.c@...>

Hi -
I have managed to successfully implement reverse AJAX using DWR. Now the
next logical step for me is to make the service creation using Spring. I
know that in order to user Spring I have to use DWRSpringServlet. But I am
confused as to how my service would get ServerContext injected into it.
Without using Spring I am able to provide ServerContext to my service class
by:

<init-param>
               <param-name>initApplicationScopeCreatorsAtStartup</param-name>
               <param-value>true</param-value>
</init-param>

for DWR Servlet. and I have the following entry in my dwr.xml:

<dwr>
        <allow>
               <create creator="new" javascript="alertService" scope="application">

               </create>
               <convert converter="bean" match="test.AlertVO" />
       </allow>
</dwr>

and my service class has the following piece of code: -

public class AlertService {

       private static ServerContext serverContext;

       int count = 0;
       /**
        * Constructor
        */
       public AlertService() {
               if (serverContext == null) {
                       WebContext webContext = WebContextFactory.get();
                       ServletContext servletContext = webContext.getServletContext();
                       serverContext = ServerContextFactory.get(servletContext);

               }

All of these are working correct for reverse Ajax when I am not using
Spring. But I am unsure as to: -

A) How will I let Spring inject serverContext in my service class? Can I use
DWRSpringServlet and set "initApplicationScopeCreatorsAtStartup" to "true"
in web.xml?

B) How will I define the Service and the Converter in
applicationContext.xml. Given the fact that I do not have any method to
expose. rather the service method is invoked by JMS. Basically how do I need
to modify my current dwr.xml entries for DWR Spring entries in
applicationContext.xml?

If anyone needs more information, I am willing to provide the same. At this
point in time, I am stuck without proper guidance.

Best Regards-
DNC

--
View this message in context: http://old.nabble.com/ReverseAJAX-%2B-DWRSpringServlet-%2B-injecting-ServerContext-into-Service-tp26133676p26133676.html
Sent from the DWR - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



Re: Re[dwr-user] verseAJAX + DWRSpringServlet + injecting ServerContext into Service

by DNC1234 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes we can use ServletContextAware interface, but I do not want to directly use Spring APIs within my codebase. I would rather use spring configuration XML for DI and object instantiation. So far I am looking into possible solutions but haven't come across anything yet.

As for the converting the DWR.xml entries to applicationContext.xml, given the example I previously stated would there if any change with regards to bean and converter entries?

<dwr>
         <allow>
                <create creator="new" javascript="alertService" scope="application">
                        < paramname="class" value="test.AlertService"/ >
                </create>
                <convert converter="bean" match="test.AlertVO" />
        </allow>
</dwr>

Best Regards,
DNC


Lance Java wrote:
Have your spring bean implement the ServletContextAware interface (spring
specific) to get a handle on the servlet context instead of using
WebContextFactory.

Re: Re: Re[dwr-user] verseAJAX + DWRSpringServlet + injecting ServerContext into Service

by Lance Java :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok... WebContextFactory.get() will only work for threads that were initiated by a DWR call. So, when your object is instantiated by spring (at container startup) it will not work. However WebContextFactory.get() will work inside a remote DWR method call if that helps.

Take a look at the spring config section in the docs http://directwebremoting.org/dwr/server/integration/spring.html. Converters are configured withing the <dwr:configuration> section with tags that mimic dwr.xml and beans are exposed as DWR remoted services using <dwr:remote javascript="myBean"> inside your bean definitions.



2009/10/30 DNC1234 <devajyoti.c@...>

Yes we can use ServletContextAware interface, but I do not want to directly
use Spring APIs within my codebase. I would rather use spring configuration
XML for DI and object instantiation. So far I am looking into possible
solutions but haven't come across anything yet.

As for the converting the DWR.xml entries to applicationContext.xml, given
the example I previously stated would there if any change with regards to
bean and converter entries?

<dwr>
        <allow>
               <create creator="new" javascript="alertService" scope="application">
                       < paramname="class" value="test.AlertService"/ >
               </create>
               <convert converter="bean" match="test.AlertVO" />
       </allow>
</dwr>

Best Regards,
DNC



Lance Java wrote:
>
> Have your spring bean implement the ServletContextAware interface (spring
> specific) to get a handle on the servlet context instead of using
> WebContextFactory.
>
>


--
View this message in context: http://old.nabble.com/ReverseAJAX-%2B-DWRSpringServlet-%2B-injecting-ServerContext-into-Service-tp26133676p26135658.html
Sent from the DWR - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...