Re: Setting attributes within ScriptSession + DefaultScriptSessionManager issue

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

Parent Message unknown Re: Setting attributes within ScriptSession + DefaultScriptSessionManager issue

by Lance Java :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Call addScriptSessionListener in MyScriptSessionManager's constructor instead.... the scriptSessionListener will do the work.
2009/11/5 DNC1234 <devajyoti.c@...>

Hi -

I was trying to extend DefaultScriptSessionManager class so as to add
attributes to "ScriptSession". My implementation was totally based upon
Lance Semmens implementation from a prior post:

public class MyScriptSessionManager extends DefaultScriptSessionManager {
    public String createScriptSession(RealWebContext webContext)
        String id = super.createScriptSession();
        ScriptSession scriptSession = getScriptSession(id);
        HttpSession session = webContext.getHttpSession();
        Object someUserSpecificObject =
        session.getAttribute("someUserSpecificObject");
        scriptSession.setAttribute("someUserSpecificObject",
        someUserSpecificObject);
        return id;
    }
 }

But then I ran into a strange problem, I downloaded DWR 2.0.5 & 3.rc1 and in
both the jar files, DefaultScriptSessionManager  class did not have method
"createScriptSession()" which I was planning to override. So I am kind of
stuck and unable to figure out how to provide the  above implementation to
set attributes in ScriptSession. I had downloaded both set of jar files from
DWR official site.

Did anyone run into this issue before? Or if things have changed and I am
not aware of?


Best Regards,
DNC



--
View this message in context: http://old.nabble.com/Setting-attributes-within-ScriptSession-%2B-DefaultScriptSessionManager-issue-tp26215810p26215810.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: Setting attributes within ScriptSession + DefaultScriptSessionManager issue

by DNC1234 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Since i am a newbie with DWR, I had to ask you this question. Based on your reply it seems I have to do something like this:

public class MyScriptSessionManager extends DefaultScriptSessionManager {
      public MyScriptSessionManager () {
             super.addScriptSessionListener(new MyScriptSessionListenerImpl());
      }
}

public class MyScriptSessionListenerImpl implements implements ScriptSessionListener {

        public void sessionCreated(ScriptSessionEvent arg0) {
        }

        public void sessionDestroyed(ScriptSessionEvent arg0) {
        }
}

But doing so, I have one problem. I am going to add some user information, that is stored in HttpSession, e.g.(UserName) when user logs in, to ScriptSession upon its creation. But within MyScriptSessionListener, I will have access to ScriptSession but not HttpSession and I would not be able to extract information from HttpSession and set it to ScriptSession. Any thoughts on that? And BTW has the APIs changed due to which the old solution was not applicable.


Lance Java wrote:
Call addScriptSessionListener in MyScriptSessionManager's constructor
instead.... the scriptSessionListener will do the work.
2009/11/5 DNC1234 <devajyoti.c@gmail.com>

>
> Hi -
>
> I was trying to extend DefaultScriptSessionManager class so as to add
> attributes to "ScriptSession". My implementation was totally based upon
> Lance Semmens implementation from a prior post:
>
> public class MyScriptSessionManager extends DefaultScriptSessionManager {
>     public String createScriptSession(RealWebContext webContext)
>         String id = super.createScriptSession();
>         ScriptSession scriptSession = getScriptSession(id);
>         HttpSession session = webContext.getHttpSession();
>         Object someUserSpecificObject =
>         session.getAttribute("someUserSpecificObject");
>         scriptSession.setAttribute("someUserSpecificObject",
>         someUserSpecificObject);
>         return id;
>     }
>  }
>
> But then I ran into a strange problem, I downloaded DWR 2.0.5 & 3.rc1 and
> in
> both the jar files, DefaultScriptSessionManager  class did not have method
> "createScriptSession()" which I was planning to override. So I am kind of
> stuck and unable to figure out how to provide the  above implementation to
> set attributes in ScriptSession. I had downloaded both set of jar files
> from
> DWR official site.
>
> Did anyone run into this issue before? Or if things have changed and I am
> not aware of?
>
>
> Best Regards,
> DNC
>
>
>
> --
> View this message in context:
> http://old.nabble.com/Setting-attributes-within-ScriptSession-%2B-DefaultScriptSessionManager-issue-tp26215810p26215810.html
> Sent from the DWR - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@dwr.dev.java.net
> For additional commands, e-mail: users-help@dwr.dev.java.net
>
>

Re: Setting attributes within ScriptSession + DefaultScriptSessionManager issue

by Lance Java :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The sessionCreated() and sessionDestroyed() destroyed events will be invoked every time a scriptSession is created and destroyed. This method will not be invoked in the ScriptSessionManager constructor. At this time you can call WebContextFactory.get().getHttpSession();
 
Cheers,
Lance.

2009/11/6 DNC1234 <devajyoti.c@...>

Since i am a newbie with DWR, I had to ask you this question. Based on your
reply it seems I have to do something like this:

public class MyScriptSessionManager extends DefaultScriptSessionManager {
     public MyScriptSessionManager () {
            super.addScriptSessionListener(new
MyScriptSessionListenerImpl());
     }
}

public class MyScriptSessionListenerImpl implements implements
ScriptSessionListener {

       public void sessionCreated(ScriptSessionEvent arg0) {
       }

       public void sessionDestroyed(ScriptSessionEvent arg0) {
       }
}

But doing so, I have one problem. I am going to add some user information,
that is stored in HttpSession, e.g.(UserName) when user logs in, to
ScriptSession upon its creation. But within MyScriptSessionListener, I will
have access to ScriptSession but not HttpSession and I would not be able to
extract information from HttpSession and set it to ScriptSession. Any
thoughts on that? And BTW has the APIs changed due to which the old solution
was not applicable.



Lance Java wrote:
>
> Call addScriptSessionListener in MyScriptSessionManager's constructor
> instead.... the scriptSessionListener will do the work.
> 2009/11/5 DNC1234 <devajyoti.c@...>
>
>>
>> Hi -
>>
>> I was trying to extend DefaultScriptSessionManager class so as to add
>> attributes to "ScriptSession". My implementation was totally based upon
>> Lance Semmens implementation from a prior post:
>>
>> public class MyScriptSessionManager extends DefaultScriptSessionManager {
>>     public String createScriptSession(RealWebContext webContext)
>>         String id = super.createScriptSession();
>>         ScriptSession scriptSession = getScriptSession(id);
>>         HttpSession session = webContext.getHttpSession();
>>         Object someUserSpecificObject =
>>         session.getAttribute("someUserSpecificObject");
>>         scriptSession.setAttribute("someUserSpecificObject",
>>         someUserSpecificObject);
>>         return id;
>>     }
>>  }
>>
>> But then I ran into a strange problem, I downloaded DWR 2.0.5 & 3.rc1 and
>> in
>> both the jar files, DefaultScriptSessionManager  class did not have
>> method
>> "createScriptSession()" which I was planning to override. So I am kind of
>> stuck and unable to figure out how to provide the  above implementation
>> to
>> set attributes in ScriptSession. I had downloaded both set of jar files
>> from
>> DWR official site.
>>
>> Did anyone run into this issue before? Or if things have changed and I am
>> not aware of?
>>
>>
>> Best Regards,
>> DNC
>>
>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Setting-attributes-within-ScriptSession-%2B-DefaultScriptSessionManager-issue-tp26215810p26215810.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@...
>>
>>
>
>

--
View this message in context: http://old.nabble.com/Re%3A-Setting-attributes-within-ScriptSession-%2B--DefaultScriptSessionManager-issue-tp26218716p26230838.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: Setting attributes within ScriptSession + DefaultScriptSessionManager issue

by DNC1234 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the information. Based on your solution, its imperative that I have to move from DWR 2.0.5 to 3.rc1. Doing so, I ended up having another issue. Since my DWR reverse ajax happens outside DWR thread, I had to use Spring to inject ServletContext into the class for helping DWR get access to ServerContext, something like: -

public class MessageConsumer implements ServletContextAware {

public void onMessage(..) {
         Collection sessions = ServerContextFactory.get(getServletContext())
                                        .getScriptSessionsByPage("abcd.jsp");
...
}

When I was using DWR 2.0.5 jar files this section of code worked correctly. But with the updated jar (3.rc1) I keep getting the following exception:
==========================================================================
[2009-11-09 09:31:13,686] org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - Error initializing ServerContext because this is not a DWR thread and there is more than one DWR servlet in the current classloader.
[2009-11-09 09:31:13,687] org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - This probably means that either DWR has not been properly initialized (in which case you should delay the current action until it has)
[2009-11-09 09:31:13,687] org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - or that there is more than 1 DWR servlet is configured in this classloader, in which case you should provide a ServletContext to the get() yourself.
===========================================================================

Also, the above piece of code is depicted as deprecated. If thats the case, what is the correct way to do this using DWR 3.x and what would be a solution to the exception thrown above.

Regards,
DNC


Lance Java wrote:
The sessionCreated() and sessionDestroyed() destroyed events will be invoked
every time a scriptSession is created and destroyed. This method will not be
invoked in the ScriptSessionManager constructor. At this time you can call
WebContextFactory.get().getHttpSession();

Cheers,
Lance.

2009/11/6 DNC1234 <devajyoti.c@gmail.com>

>
> Since i am a newbie with DWR, I had to ask you this question. Based on your
> reply it seems I have to do something like this:
>
> public class MyScriptSessionManager extends DefaultScriptSessionManager {
>      public MyScriptSessionManager () {
>             super.addScriptSessionListener(new
> MyScriptSessionListenerImpl());
>      }
> }
>
> public class MyScriptSessionListenerImpl implements implements
> ScriptSessionListener {
>
>        public void sessionCreated(ScriptSessionEvent arg0) {
>        }
>
>        public void sessionDestroyed(ScriptSessionEvent arg0) {
>        }
> }
>
> But doing so, I have one problem. I am going to add some user information,
> that is stored in HttpSession, e.g.(UserName) when user logs in, to
> ScriptSession upon its creation. But within MyScriptSessionListener, I will
> have access to ScriptSession but not HttpSession and I would not be able to
> extract information from HttpSession and set it to ScriptSession. Any
> thoughts on that? And BTW has the APIs changed due to which the old
> solution
> was not applicable.
>
>
>
> Lance Java wrote:
> >
> > Call addScriptSessionListener in MyScriptSessionManager's constructor
> > instead.... the scriptSessionListener will do the work.
> > 2009/11/5 DNC1234 <devajyoti.c@gmail.com>
> >
> >>
> >> Hi -
> >>
> >> I was trying to extend DefaultScriptSessionManager class so as to add
> >> attributes to "ScriptSession". My implementation was totally based upon
> >> Lance Semmens implementation from a prior post:
> >>
> >> public class MyScriptSessionManager extends DefaultScriptSessionManager
> {
> >>     public String createScriptSession(RealWebContext webContext)
> >>         String id = super.createScriptSession();
> >>         ScriptSession scriptSession = getScriptSession(id);
> >>         HttpSession session = webContext.getHttpSession();
> >>         Object someUserSpecificObject =
> >>         session.getAttribute("someUserSpecificObject");
> >>         scriptSession.setAttribute("someUserSpecificObject",
> >>         someUserSpecificObject);
> >>         return id;
> >>     }
> >>  }
> >>
> >> But then I ran into a strange problem, I downloaded DWR 2.0.5 & 3.rc1
> and
> >> in
> >> both the jar files, DefaultScriptSessionManager  class did not have
> >> method
> >> "createScriptSession()" which I was planning to override. So I am kind
> of
> >> stuck and unable to figure out how to provide the  above implementation
> >> to
> >> set attributes in ScriptSession. I had downloaded both set of jar files
> >> from
> >> DWR official site.
> >>
> >> Did anyone run into this issue before? Or if things have changed and I
> am
> >> not aware of?
> >>
> >>
> >> Best Regards,
> >> DNC
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/Setting-attributes-within-ScriptSession-%2B-DefaultScriptSessionManager-issue-tp26215810p26215810.html
> >> Sent from the DWR - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@dwr.dev.java.net
> >> For additional commands, e-mail: users-help@dwr.dev.java.net
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Re%3A-Setting-attributes-within-ScriptSession-%2B--DefaultScriptSessionManager-issue-tp26218716p26230838.html
>  Sent from the DWR - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@dwr.dev.java.net
> For additional commands, e-mail: users-help@dwr.dev.java.net
>
>

Re: Setting attributes within ScriptSession + DefaultScriptSessionManager issue

by DNC1234 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think I found the reason for the exception. It was thrown because, I had configured DWRSpringServlet in web.xml and had <dwr:controller id="dwrController" debug="true" > ... entry in spring configuration, which leads to duplication error. If you are using Spring use any one configuration set. This problem is specific to DWR 3 and did not happen with DWR 2.x. I found this out from one of the earlier posts.

Well, I am still try to find out about the deprecated APIs, and what I should use instead in DWR 3.x?

Best Regards-
DNC


Thanks for the information. Based on your solution, its imperative that I have to move from DWR 2.0.5 to 3.rc1. Doing so, I ended up having another issue. Since my DWR reverse ajax happens outside DWR thread, I had to use Spring to inject ServletContext into the class for helping DWR get access to ServerContext, something like: -

public class MessageConsumer implements ServletContextAware {

public void onMessage(..) {
         Collection sessions = ServerContextFactory.get(getServletContext())
                                        .getScriptSessionsByPage("abcd.jsp");
...
}

When I was using DWR 2.0.5 jar files this section of code worked correctly. But with the updated jar (3.rc1) I keep getting the following exception:
==========================================================================
[2009-11-09 09:31:13,686] org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - Error initializing ServerContext because this is not a DWR thread and there is more than one DWR servlet in the current classloader.
[2009-11-09 09:31:13,687] org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - This probably means that either DWR has not been properly initialized (in which case you should delay the current action until it has)
[2009-11-09 09:31:13,687] org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - or that there is more than 1 DWR servlet is configured in this classloader, in which case you should provide a ServletContext to the get() yourself.
===========================================================================

Also, the above piece of code is depicted as deprecated. If thats the case, what is the correct way to do this using DWR 3.x and what would be a solution to the exception thrown above.

Regards,
DNC



The sessionCreated() and sessionDestroyed() destroyed events will be invoked
every time a scriptSession is created and destroyed. This method will not be
invoked in the ScriptSessionManager constructor. At this time you can call
WebContextFactory.get().getHttpSession();

Cheers,
Lance.


Re: Setting attributes within ScriptSession + DefaultScriptSessionManager issue

by Lance Java :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Well, I am still try to find out about the deprecated APIs, and what I should use instead in DWR 3.x?
Not sure what you mean here... i've given you a place to intercept scriptSession creation and add attributes to it. What more do you need?


2009/11/9 DNC1234 <devajyoti.c@...>

I think I found the reason for the exception. It was thrown because, I had
configured DWRSpringServlet in web.xml and had <dwr:controller
id="dwrController" debug="true" > ... entry in spring configuration, which
leads to duplication error. If you are using Spring use any one
configuration set. This problem is specific to DWR 3 and did not happen with
DWR 2.x. I found this out from one of the earlier posts.

Well, I am still try to find out about the deprecated APIs, and what I
should use instead in DWR 3.x?

Best Regards-
DNC


Thanks for the information. Based on your solution, its imperative that I
have to move from DWR 2.0.5 to 3.rc1. Doing so, I ended up having another
issue. Since my DWR reverse ajax happens outside DWR thread, I had to use
Spring to inject ServletContext into the class for helping DWR get access to
ServerContext, something like: -

public class MessageConsumer implements ServletContextAware {

public void onMessage(..) {
        Collection sessions = ServerContextFactory.get(getServletContext())
                                       .getScriptSessionsByPage("abcd.jsp");
...
}

When I was using DWR 2.0.5 jar files this section of code worked correctly.
But with the updated jar (3.rc1) I keep getting the following exception:
==========================================================================
[2009-11-09 09:31:13,686]
org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - Error
initializing ServerContext because this is not a DWR thread and there is
more than one DWR servlet in the current classloader.
[2009-11-09 09:31:13,687]
org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - This
probably means that either DWR has not been properly initialized (in which
case you should delay the current action until it has)
[2009-11-09 09:31:13,687]
org.directwebremoting.impl.DefaultServerContextBuilder [FATAL] - or that
there is more than 1 DWR servlet is configured in this classloader, in which
case you should provide a ServletContext to the get() yourself.
===========================================================================

Also, the above piece of code is depicted as deprecated. If thats the case,
what is the correct way to do this using DWR 3.x and what would be a
solution to the exception thrown above.

Regards,
DNC



The sessionCreated() and sessionDestroyed() destroyed events will be invoked
every time a scriptSession is created and destroyed. This method will not be
invoked in the ScriptSessionManager constructor. At this time you can call
WebContextFactory.get().getHttpSession();

Cheers,
Lance.


--
View this message in context: http://old.nabble.com/Re%3A-Setting-attributes-within-ScriptSession-%2B--DefaultScriptSessionManager-issue-tp26218716p26269457.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@...