3 Replies Latest reply on Sep 17, 2008 11:47 AM by tnabeel

    New HttpSession gets created on each request

    tnabeel

      New HttpSession gets created on each request

      I couldn't get access to the same scoped Seam-component work across requests. Just realized that a new HttpSession is created on each request.

      It makes no difference if I use <s:link> instead of <h:commandLink>

      I'm using portletbridge-impl-1.0.0.B3 / JBoss Portal 2.6.6.GA / Seam 2.0.2.SP1 / RichFaces 3.2.1
      Below is a test case that duplicates the issue. I would really appreciate help at this point. The test case below works as expected on JBoss 4.2.2.GA.

      test.xhtml:
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:s="http://jboss.com/products/seam/taglib">
      <h:form>

      <h:commandLink action="/page/test.xhtml" styleClass="menuLink">Main</h:commandLink>

      <h:outputText value="#{testBean.value}"></h:outputText>
      </h:form>
      </ui:composition>

      TestBean.java:
      import javax.faces.context.FacesContext;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.log.Log;

      @Name("testBean")
      public class TestBean {

      @Logger
      private Log log;

      private String value;

      public String getValue() {
      log.info("************SESSION ID="+FacesContext.getCurrentInstance().getExternalContext().getSession(false).hashCode());
      return value;
      }

      public void setValue(String value) {
      this.value = value;
      }

      }

      On JBoss Portal 2.6.6.GA, different session is created on each request:
      11:13:45,734 INFO [TestBean] ************SESSION ID=15014154
      11:13:49,312 INFO [TestBean] ************SESSION ID=11898309
      11:13:57,703 INFO [TestBean] ************SESSION ID=32604882
      11:14:01,578 INFO [TestBean] ************SESSION ID=7738878
      11:14:04,765 INFO [TestBean] ************SESSION ID=22343475
      11:14:09,187 INFO [TestBean] ************SESSION ID=742190

      On JBoss 4.2.2.GA, same session is returned on subsequent requests:
      11:22:00,343 INFO [TestBean] ************SESSION ID=15287424
      11:22:04,375 INFO [TestBean] ************SESSION ID=15287424
      11:22:05,718 INFO [TestBean] ************SESSION ID=15287424
      11:22:07,953 INFO [TestBean] ************SESSION ID=15287424
      11:22:11,843 INFO [TestBean] ************SESSION ID=15287424

      Again, I would really appreciate if someone could tell me if this is a bug or I'm doing something wrong.

      Thanks in advance.
      -Tareq

        • 1. Re: New HttpSession gets created on each request
          tnabeel

          Event though the session object's hashcode is different on each request, after further testing I found out that sessions are maintanined across requests as session scoped objects had the same hashCode.

          However when I make a Seam remoting call, I get a different session-scoped object instance than the one stored in the main HttpSession. This is regardless of whether or not I call Seam.Remoting.getContext().setConversationId() per the docs.

          The same Seam remoting calls works as expected on JBoss 4.2.2.GA i.e. it returns the session-scoped object instance in the main HttpSession.

          Would really appreciate help on this issue.

          • 2. Re: New HttpSession gets created on each request
            alexsmirnov

            The JSF bridge and portal engine returns a session "proxy" objects, not a original HttpSession object.
            Check sessionId attribute, nor a hash code.

            • 3. Re: New HttpSession gets created on each request
              tnabeel

              Thank you for your response. I checked for replies for a day and gave up because I didn't receive an email even though I thought I had checked "Notify me when a reply is posted". My bad.

              You are right. portletSession.getId() returns the same id across JSF requests. The issue I was actually experiencing was that Seam remote requests did not have access to the same session-scoped components.

              I will create a new thread for this issue. Thanks once again for your prompt response.