Hello all,

This seems more like a Java question than a Tapestry question.

I'm having some troubles in trying to provide a logout link
in my application.

My first approach was to make a Direct component


<component id="signOut" type="Direct">
 <binding name="listener" property-path="listeners.directSignOut" />
 <field-binding name="stateful" field-name="Boolean.FALSE" />
</component>

with the code

public void directSignOut(IRequestCycle cycle)
{
 Visit visit = (Visit) page.getEngine().getVisit();
 visit.setUsername(null);
  visit = null;

 try
 {
  HttpSession session = cycle.getRequestContext().getSession();

  if (session != null)
   session.invalidate();
 }
 catch (IllegalStateException e)
 {
  // do nothing
 }
 finally
 {
  cycle.setPage("SignOut");
 }

but all I get is this exception:

500 Servlet Exception

java.lang.IllegalStateException: Can't call getAttribute() when session
is no longer valid.
 at com.caucho.http.session.SessionImpl.getAttribute(SessionImpl.java:275)
 at
net.sf.tapestry.ApplicationServlet.doService(ApplicationServlet.java:203)
 at net.sf.tapestry.ApplicationServlet.doGet(ApplicationServlet.java:161)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
 at
com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:9
6)
 at com.caucho.server.http.Invocation.service(Invocation.java:311)
 at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
 at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:218)
 at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:160)
 at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
 at java.lang.Thread.run(Thread.java:536)



I don't understand why the IllegalStateException doesn't get
caught.
After playing with this for a while and getting nowhere.
I tried to make a SignOutService, the code follows:


  <component id="signOut" type="Service">
    <field-binding name="service"
field-name="tapestryCIO.SignOutService.SIGN_OUT"/>
 <static-binding name="context">SignOut</static-binding>
  </component>


public class SignOutService extends AbstractService
{
 public static final String SIGN_OUT = "signout";

 public Gesture buildGesture(
  IRequestCycle cycle,
  IComponent component,
  String[] parameters)
 {
  if (parameters == null || parameters.length != 1)
   throw new ApplicationRuntimeException("SignOut service requires one
parameter.");

  return assembleGesture(cycle, SIGN_OUT, null, parameters, true);
 }

 public boolean service(
  IEngineServiceView engine,
  IRequestCycle cycle,
  ResponseOutputStream output)
  throws RequestCycleException, ServletException, IOException
 {

  String[] parameters = getParameters(cycle.getRequestContext());
  String PAGE_TO_GO_WHEN_SIGN_OFF = parameters[0];

  RequestContext context = cycle.getRequestContext();

  HttpSession session = context.getSession();

  if (session != null)
  {
   try
   {
    session.invalidate();
    cycle.setPage(PAGE_TO_GO_WHEN_SIGN_OFF);
   }
   catch (IllegalStateException ex)
   {
    // Do Nothing
   }
  }
  return true;

 }

 public String getName()
 {
  return SIGN_OUT;
 }
}

But I get the exact same IllegalStateException.


I can make the code work if instead of

cycle.setPage(PAGE_TO_GO_WHEN_SIGN_OFF);

i use

context.redirect("tapestryCIO/?context=" + PAGE_TO_GO_WHEN_SIGN_OFF +
"&service=page");

but this seems against the Tapestry way of doing things.

I must be doing something terribly wrong, but I don't now what.
I'm using Resin 2.1.1 if it matters.

Any help will be appreciated.


Luis Neves


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer

Reply via email to