You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Cristi Manole <cr...@gmail.com> on 2007/09/03 21:56:04 UTC

Trying to make a singleton out of session

Hello,

I'm trying to make WebSession as a singleton available to all wicket applications in order to provide single sign on.

Authorisation is being performed with Spring JDBC. 

The problem is this:

SEVERE: Servlet.service() for servlet default threw exception

java.lang.IllegalStateException: Request processing executed 100 steps, which means it is probably in an infinite loop.

at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1172)

at org.apache.wicket.RequestCycle.request(RequestCycle.java:500)

at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:261)

at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:127)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:148)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Unknown Source)



This is the class if it helps:

package com.moneyrulz.theworld.common;

import org.apache.wicket.Request;
import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebSession;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.moneyrulz.theworld.controller.JdbcLogin;

public final class TheWorldSession extends WebSession
{
 @SpringBean
 private JdbcLogin jdbcLogin;

 /** Trivial user representation */
 private String user;
 
 private static TheWorldSession session = null;

 /**
  * Constructor
  * 
  * @param application
  *            The application
  * @param request
  */
 private TheWorldSession(Request request)
 {
  super(request);
  
  InjectorHolder.getInjector().inject(this); //don't get spring by default in sessions...
 }
 
 public static TheWorldSession getSession(Request request)
 {
  if(session == null)
  {
   session = new TheWorldSession(request);
  }
  
  return session;
 }
 
 /**
  * Checks the given username and password, returning a User object if if the
  * username and password identify a valid user.
  * 
  * @param username
  *            The username
  * @param password
  *            The password
  * @return True if the user was authenticated
  */
 public final boolean authenticate(final String username, final String password)
 {
  if(user == null)
  {
   if(jdbcLogin.isAuthentificated(username, password))
   {
    user = username;
   }
  }

  return user != null;
 }

 /**
  * @return True if user is signed in
  */
 public boolean isSignedIn()
 {
  return user != null;
 }

 /**
  * @return User
  */
 public String getUser()
 {
  return user;
 }

 /**
  * @param user
  *            New user
  */
 public void setUser(final String user)
 {
  this.user = user;
 }
}


Tks in advance!

Re: Trying to make a singleton out of session

Posted by Eelco Hillenius <ee...@gmail.com>.
> java.lang.IllegalStateException: Request processing executed 100 steps, which means it is probably in an infinite loop.

This was fixed *after* beta 3 came out: an exception during error
handling could result in a cycle.

Eelco

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


Re: Trying to make a singleton out of session

Posted by Eelco Hillenius <ee...@gmail.com>.
On 9/3/07, Cristi Manole <cr...@gmail.com> wrote:
> I don't know why, but it works out of the box :)
>
> The only problem was that i was making this call
> mountBookmarkablePage("/index.html", Home.class);
>
> in the home application init.
>
> I moved it in another application (that takes care of signin) and it all the
> "applications" work like a charm. I have only on session for all (four) of
> them...
>
> Now reading what you said, i'm wondering if i really do have one session :)

If you didn't do what I said, you'll actually have four session
instances (though 1 http session instance). They might be of the same
class, but are different instances. Check it and see.

Eelco

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


Re: Trying to make a singleton out of session

Posted by Cristi Manole <cr...@gmail.com>.
I don't know why, but it works out of the box :)

The only problem was that i was making this call
mountBookmarkablePage("/index.html", Home.class);

in the home application init.

I moved it in another application (that takes care of signin) and it all the 
"applications" work like a charm. I have only on session for all (four) of 
them...

Now reading what you said, i'm wondering if i really do have one session :)



----- Original Message ----- 
From: "Eelco Hillenius" <ee...@gmail.com>
To: <us...@wicket.apache.org>
Sent: Monday, September 03, 2007 11:33 PM
Subject: Re: Trying to make a singleton out of session


> On 9/3/07, Cristi Manole <cr...@gmail.com> wrote:
>> Hello,
>>
>> I'm trying to make WebSession as a singleton available to all wicket 
>> applications in order to provide single sign on.
>
> That won't work just like that. If you want a wicket session object
> that is shared amongst all Wicket applications, you'll have to do some
> extra work, since *we* did the extra work to actually separate it :)
>
> The easiest way to go about this is probably to override
> getSessionAttributePrefix in your application (and you'll need that
> latest source for that, since I just now removed final from that
> method) and let all your applications return the same key. And of
> course, you need all your applications return the same kind of
> session, which you do by overriding newSession(Request request,
> Response response). I.e. just create a base application class that
> overrides these two methods, and let your other applications extend
> that.
>
> Can you let me know whether this works for you? I would have to have
> opened up a method without a good reason.
>
> Cheers,
>
> Eelco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 


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


Re: Trying to make a singleton out of session

Posted by Eelco Hillenius <ee...@gmail.com>.
On 9/3/07, Cristi Manole <cr...@gmail.com> wrote:
> Hello,
>
> I'm trying to make WebSession as a singleton available to all wicket applications in order to provide single sign on.

That won't work just like that. If you want a wicket session object
that is shared amongst all Wicket applications, you'll have to do some
extra work, since *we* did the extra work to actually separate it :)

The easiest way to go about this is probably to override
getSessionAttributePrefix in your application (and you'll need that
latest source for that, since I just now removed final from that
method) and let all your applications return the same key. And of
course, you need all your applications return the same kind of
session, which you do by overriding newSession(Request request,
Response response). I.e. just create a base application class that
overrides these two methods, and let your other applications extend
that.

Can you let me know whether this works for you? I would have to have
opened up a method without a good reason.

Cheers,

Eelco

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