Re: [appengine-java] Re: how to get session id under a Class which doesn't extend HttpServlet?

2010-01-09 Thread Prashant Gupta
I tried following code, getting null all the time.

public static HttpSession getSession(){
return new ThreadLocal().get().getSession();
}


2010/1/9 Elias Mårtenson 

> On 9 Jan, 01:27, Prashant Gupta  wrote:
>
> > I am trying to implement my own user management system, for that I need
> some
> > way to make session id available to all classes independent of whether it
> > extends HttpServlet or not. I know there is some way to do that but I am
> not
> > able to find it. Any kind of help would be appreciated.
>
> One way to do it is to use a servlet filter to make the user
> information available through a ThreadLocal instance. That way you can
> have a single static method that returns the user wherever you are.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.

To post to this group, send email to google-appengine-j...@googlegroups.com.

To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: how to get session id under a Class which doesn't extend HttpServlet?

2010-01-10 Thread Prashant Gupta
I googled  some keywords picked up from your reply and found some useful
stuff and I think it will workout for me.

Thanks a lot...

2010/1/10 Elias Mårtenson 

> On 9 Jan, 16:53, Prashant Gupta  wrote:
> > I tried following code, getting null all the time.
> >
> > public static HttpSession getSession(){
> > return new ThreadLocal().get().getSession();
> >
> > }
>
> You also need to create a filter where you actually put the data in
> the TheadLocal. I am just about to go out, so I don't actually have
> time to write the code for you. Sorry about that.
>
> Regards,
> Elias
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.

To post to this group, send email to google-appengine-j...@googlegroups.com.

To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: how to get session id under a Class which doesn't extend HttpServlet?

2010-01-12 Thread Prashant Gupta
Hi,

Thanks guys for looking into this.

All requests to my app pass through a single servlet, say *Main*. So, I
thought I need not to add additional filter and I used a ThreadLocal
variable to store session id :

public static final ThreadLocal sessionID = new
ThreadLocal();

And for every request I am doing

if(*Main*.sessionID.get() == null)

*Main*.sessionID.set(req.getSession().getId());

But it doesn't seem to work. According to my understanding
*Main*.sessionID.get()
should be null each new session (or each new request, I am not sure here).
Did I get something wrong?


2010/1/9 A1programmer 

> You probably want to architect the classes in such a way that they are
> not tightly coupled to the http servlet session.
>
> Anyway, when you were working with ThreadLocal earlier, did you first
> set the ServletRequest from the filter?
>
> class UserService {
>private UserDAO userDAO;
>
>   public Collection  getItemsForUser(User user){
>  return userDao.getItemsForUser(user);
>   }
>
> }
>
>
> class UserDAO {
>
>   public Collection getItemsForUser(User user) {
>
>   Long userId = user.getId();
>   String userName = user.getUserName();
>
>   // query the database based on user information
>
>   }
>
> }
>
> On Jan 9, 3:53 am, Prashant Gupta  wrote:
> > I tried following code, getting null all the time.
> >
> > public static HttpSession getSession(){
> > return new ThreadLocal().get().getSession();
> >
> > }
> >
> > 2010/1/9 Elias Mårtenson 
> >
> >
> >
> > > On 9 Jan, 01:27, Prashant Gupta  wrote:
> >
> > > > I am trying to implement my own user management system, for that I
> need
> > > some
> > > > way to make session id available to all classes independent of
> whether it
> > > > extends HttpServlet or not. I know there is some way to do that but I
> am
> > > not
> > > > able to find it. Any kind of help would be appreciated.
> >
> > > One way to do it is to use a servlet filter to make the user
> > > information available through a ThreadLocal instance. That way you can
> > > have a single static method that returns the user wherever you are.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Google App Engine for Java" group.
> > > To post to this group, send email to
> > > google-appengine-j...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > google-appengine-java+unsubscr...@googlegroups.com unsubscr...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine-java?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.

To post to this group, send email to google-appengine-j...@googlegroups.com.

To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: how to get session id under a Class which doesn't extend HttpServlet?

2010-01-14 Thread Prashant Gupta
anyone???

2010/1/12 Prashant Gupta 

> Hi,
>
> Thanks guys for looking into this.
>
> All requests to my app pass through a single servlet, say *Main*. So, I
> thought I need not to add additional filter and I used a ThreadLocal
> variable to store session id :
>
> public static final ThreadLocal sessionID = new
> ThreadLocal();
>
> And for every request I am doing
>
> if(*Main*.sessionID.get() == null)
>
> *Main*.sessionID.set(req.getSession().getId());
>
> But it doesn't seem to work. According to my understanding 
> *Main*.sessionID.get()
> should be null each new session (or each new request, I am not sure here).
> Did I get something wrong?
>
>
> 2010/1/9 A1programmer 
>
>> You probably want to architect the classes in such a way that they are
>> not tightly coupled to the http servlet session.
>>
>> Anyway, when you were working with ThreadLocal earlier, did you first
>> set the ServletRequest from the filter?
>>
>> class UserService {
>>private UserDAO userDAO;
>>
>>   public Collection  getItemsForUser(User user){
>>  return userDao.getItemsForUser(user);
>>   }
>>
>> }
>>
>>
>> class UserDAO {
>>
>>   public Collection getItemsForUser(User user) {
>>
>>   Long userId = user.getId();
>>   String userName = user.getUserName();
>>
>>   // query the database based on user information
>>
>>   }
>>
>> }
>>
>> On Jan 9, 3:53 am, Prashant Gupta  wrote:
>> > I tried following code, getting null all the time.
>> >
>> > public static HttpSession getSession(){
>> > return new ThreadLocal().get().getSession();
>> >
>> > }
>> >
>> > 2010/1/9 Elias Mårtenson 
>> >
>> >
>> >
>> > > On 9 Jan, 01:27, Prashant Gupta  wrote:
>> >
>> > > > I am trying to implement my own user management system, for that I
>> need
>> > > some
>> > > > way to make session id available to all classes independent of
>> whether it
>> > > > extends HttpServlet or not. I know there is some way to do that but
>> I am
>> > > not
>> > > > able to find it. Any kind of help would be appreciated.
>> >
>> > > One way to do it is to use a servlet filter to make the user
>> > > information available through a ThreadLocal instance. That way you can
>> > > have a single static method that returns the user wherever you are.
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "Google App Engine for Java" group.
>> > > To post to this group, send email to
>> > > google-appengine-j...@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > google-appengine-java+unsubscr...@googlegroups.com> unsubscr...@googlegroups.com>
>> > > .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/google-appengine-java?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine for Java" group.
>> To post to this group, send email to
>> google-appengine-j...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine-java+unsubscr...@googlegroups.com
>> .
>>
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>
>>
>>
>>
>
-- 

You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.

To post to this group, send email to google-appengine-j...@googlegroups.com.

To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: how to get session id under a Class which doesn't extend HttpServlet?

2010-01-14 Thread Stephan Hartmann
Threads do not end when they finished serving a request. Instead they will
catch up another request in the queue and serve it.
So basically at the end of your service method of your servlet you should
explicitly set the value of your ThreadLocal to null, prefferably in a
finally block.


2010/1/14 Prashant Gupta 

> anyone???
>
> 2010/1/12 Prashant Gupta 
>
> Hi,
>>
>> Thanks guys for looking into this.
>>
>> All requests to my app pass through a single servlet, say *Main*. So, I
>> thought I need not to add additional filter and I used a ThreadLocal
>> variable to store session id :
>>
>> public static final ThreadLocal sessionID = new
>> ThreadLocal();
>>
>> And for every request I am doing
>>
>> if(*Main*.sessionID.get() == null)
>>
>> *Main*.sessionID.set(req.getSession().getId());
>>
>> But it doesn't seem to work. According to my understanding 
>> *Main*.sessionID.get()
>> should be null each new session (or each new request, I am not sure here).
>> Did I get something wrong?
>>
>>
>> 2010/1/9 A1programmer 
>>
>>>  You probably want to architect the classes in such a way that they are
>>> not tightly coupled to the http servlet session.
>>>
>>> Anyway, when you were working with ThreadLocal earlier, did you first
>>> set the ServletRequest from the filter?
>>>
>>> class UserService {
>>>private UserDAO userDAO;
>>>
>>>   public Collection  getItemsForUser(User user){
>>>  return userDao.getItemsForUser(user);
>>>   }
>>>
>>> }
>>>
>>>
>>> class UserDAO {
>>>
>>>   public Collection getItemsForUser(User user) {
>>>
>>>   Long userId = user.getId();
>>>   String userName = user.getUserName();
>>>
>>>   // query the database based on user information
>>>
>>>   }
>>>
>>> }
>>>
>>> On Jan 9, 3:53 am, Prashant Gupta  wrote:
>>> > I tried following code, getting null all the time.
>>> >
>>> > public static HttpSession getSession(){
>>> > return new ThreadLocal().get().getSession();
>>> >
>>> > }
>>> >
>>> > 2010/1/9 Elias Mårtenson 
>>> >
>>> >
>>> >
>>> > > On 9 Jan, 01:27, Prashant Gupta  wrote:
>>> >
>>> > > > I am trying to implement my own user management system, for that I
>>> need
>>> > > some
>>> > > > way to make session id available to all classes independent of
>>> whether it
>>> > > > extends HttpServlet or not. I know there is some way to do that but
>>> I am
>>> > > not
>>> > > > able to find it. Any kind of help would be appreciated.
>>> >
>>> > > One way to do it is to use a servlet filter to make the user
>>> > > information available through a ThreadLocal instance. That way you
>>> can
>>> > > have a single static method that returns the user wherever you are.
>>> >
>>> > > --
>>> > > You received this message because you are subscribed to the Google
>>> Groups
>>> > > "Google App Engine for Java" group.
>>> > > To post to this group, send email to
>>> > > google-appengine-j...@googlegroups.com.
>>> > > To unsubscribe from this group, send email to
>>> > > google-appengine-java+unsubscr...@googlegroups.com>> unsubscr...@googlegroups.com>
>>> > > .
>>> > > For more options, visit this group at
>>> > >http://groups.google.com/group/google-appengine-java?hl=en.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Google App Engine for Java" group.
>>> To post to this group, send email to
>>> google-appengine-j...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> google-appengine-java+unsubscr...@googlegroups.com
>>> .
>>>
>>> For more options, visit this group at
>>> http://groups.google.com/group/google-appengine-java?hl=en.
>>>
>>>
>>>
>>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
-- 

You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.

To post to this group, send email to google-appengine-j...@googlegroups.com.

To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: how to get session id under a Class which doesn't extend HttpServlet?

2010-01-14 Thread Prashant Gupta
ok, thanks a lot.



2010/1/14 Stephan Hartmann 

> Threads do not end when they finished serving a request. Instead they will
> catch up another request in the queue and serve it.
> So basically at the end of your service method of your servlet you should
> explicitly set the value of your ThreadLocal to null, prefferably in a
> finally block.
>
>
> 2010/1/14 Prashant Gupta 
>
>> anyone???
>>
>> 2010/1/12 Prashant Gupta 
>>
>> Hi,
>>>
>>> Thanks guys for looking into this.
>>>
>>> All requests to my app pass through a single servlet, say *Main*. So, I
>>> thought I need not to add additional filter and I used a ThreadLocal
>>> variable to store session id :
>>>
>>> public static final ThreadLocal sessionID = new
>>> ThreadLocal();
>>>
>>> And for every request I am doing
>>>
>>> if(*Main*.sessionID.get() == null)
>>>
>>> *Main*.sessionID.set(req.getSession().getId());
>>>
>>> But it doesn't seem to work. According to my understanding 
>>> *Main*.sessionID.get()
>>> should be null each new session (or each new request, I am not sure here).
>>> Did I get something wrong?
>>>
>>>
>>> 2010/1/9 A1programmer 
>>>
  You probably want to architect the classes in such a way that they are
 not tightly coupled to the http servlet session.

 Anyway, when you were working with ThreadLocal earlier, did you first
 set the ServletRequest from the filter?

 class UserService {
private UserDAO userDAO;

   public Collection  getItemsForUser(User user){
  return userDao.getItemsForUser(user);
   }

 }


 class UserDAO {

   public Collection getItemsForUser(User user) {

   Long userId = user.getId();
   String userName = user.getUserName();

   // query the database based on user information

   }

 }

 On Jan 9, 3:53 am, Prashant Gupta  wrote:
 > I tried following code, getting null all the time.
 >
 > public static HttpSession getSession(){
 > return new ThreadLocal().get().getSession();
 >
 > }
 >
 > 2010/1/9 Elias Mårtenson 
 >
 >
 >
 > > On 9 Jan, 01:27, Prashant Gupta  wrote:
 >
 > > > I am trying to implement my own user management system, for that I
 need
 > > some
 > > > way to make session id available to all classes independent of
 whether it
 > > > extends HttpServlet or not. I know there is some way to do that
 but I am
 > > not
 > > > able to find it. Any kind of help would be appreciated.
 >
 > > One way to do it is to use a servlet filter to make the user
 > > information available through a ThreadLocal instance. That way you
 can
 > > have a single static method that returns the user wherever you are.
 >
 > > --
 > > You received this message because you are subscribed to the Google
 Groups
 > > "Google App Engine for Java" group.
 > > To post to this group, send email to
 > > google-appengine-j...@googlegroups.com.
 > > To unsubscribe from this group, send email to
 > > google-appengine-java+unsubscr...@googlegroups.com>>> unsubscr...@googlegroups.com>
 > > .
 > > For more options, visit this group at
 > >http://groups.google.com/group/google-appengine-java?hl=en.

 --
 You received this message because you are subscribed to the Google
 Groups "Google App Engine for Java" group.
 To post to this group, send email to
 google-appengine-j...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine-java+unsubscr...@googlegroups.com
 .

 For more options, visit this group at
 http://groups.google.com/group/google-appengine-java?hl=en.




>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine for Java" group.
>> To post to this group, send email to
>> google-appengine-j...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine-java+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
-- 

You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.

To post to this group, send email to google-appengine-j...@googlegroups.com.

To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-appe

Re: [appengine-java] Re: how to get session id under a Class which doesn't extend HttpServlet?

2010-01-15 Thread Prashant Gupta
I tried adding a filter, after that my app stopped working, displaying
nothing. Someone please help me out to set up a filter to get session id and
keep other things working.

Thanks.





2010/1/14 Prashant Gupta 

> ok, thanks a lot.
>
>
>
> 2010/1/14 Stephan Hartmann 
>
>> Threads do not end when they finished serving a request. Instead they will
>> catch up another request in the queue and serve it.
>> So basically at the end of your service method of your servlet you should
>> explicitly set the value of your ThreadLocal to null, prefferably in a
>> finally block.
>>
>>
>> 2010/1/14 Prashant Gupta 
>>
>>>  anyone???
>>>
>>> 2010/1/12 Prashant Gupta 
>>>
>>> Hi,

 Thanks guys for looking into this.

 All requests to my app pass through a single servlet, say *Main*. So, I
 thought I need not to add additional filter and I used a ThreadLocal
 variable to store session id :

 public static final ThreadLocal sessionID = new
 ThreadLocal();

 And for every request I am doing

 if(*Main*.sessionID.get() == null)

 *Main*.sessionID.set(req.getSession().getId());

 But it doesn't seem to work. According to my understanding 
 *Main*.sessionID.get()
 should be null each new session (or each new request, I am not sure here).
 Did I get something wrong?


 2010/1/9 A1programmer 

>  You probably want to architect the classes in such a way that they are
> not tightly coupled to the http servlet session.
>
> Anyway, when you were working with ThreadLocal earlier, did you first
> set the ServletRequest from the filter?
>
> class UserService {
>private UserDAO userDAO;
>
>   public Collection  getItemsForUser(User user){
>  return userDao.getItemsForUser(user);
>   }
>
> }
>
>
> class UserDAO {
>
>   public Collection getItemsForUser(User user) {
>
>   Long userId = user.getId();
>   String userName = user.getUserName();
>
>   // query the database based on user information
>
>   }
>
> }
>
> On Jan 9, 3:53 am, Prashant Gupta  wrote:
> > I tried following code, getting null all the time.
> >
> > public static HttpSession getSession(){
> > return new ThreadLocal().get().getSession();
> >
> > }
> >
> > 2010/1/9 Elias Mårtenson 
> >
> >
> >
> > > On 9 Jan, 01:27, Prashant Gupta  wrote:
> >
> > > > I am trying to implement my own user management system, for that
> I need
> > > some
> > > > way to make session id available to all classes independent of
> whether it
> > > > extends HttpServlet or not. I know there is some way to do that
> but I am
> > > not
> > > > able to find it. Any kind of help would be appreciated.
> >
> > > One way to do it is to use a servlet filter to make the user
> > > information available through a ThreadLocal instance. That way you
> can
> > > have a single static method that returns the user wherever you are.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Google App Engine for Java" group.
> > > To post to this group, send email to
> > > google-appengine-j...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > google-appengine-java+unsubscr...@googlegroups.com unsubscr...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine-java?hl=en.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
>
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
>
>

>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Google App Engine for Java" group.
>>> To post to this group, send email to
>>> google-appengine-j...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> google-appengine-java+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/google-appengine-java?hl=en.
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine for Java" group.
>> To post to this group, send email to
>> google-appengine-j...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine-java+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>