You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Thomas Chabaud <ex...@agora.msa.fr> on 2011/04/12 11:05:55 UTC

Question about HttpSessionBindingListener and getAttribute in valueBound()

Hi,

I have problem with Tomcat 6.0 StandardSession implementation.
We have an application who calls setAttribute("myAttr", myValue), and try to get this attribute in a method launched in valueBound(), but only gets null value.

According to source code, the setAttribute() method calls valueBound *before* setting attribute in attributes Map :

public void setAttribute(String name, Object value, boolean notify)
{
[...]
         // Call the valueBound() method if necessary
         if (notify && value instanceof HttpSessionBindingListener)
         {
             // Don't call any notification if replacing with the same value
             Object oldValue = attributes.get(name);
             if (value != oldValue)
             {
                 event = new HttpSessionBindingEvent(getSession(), name, value);
                 try
                 {
                     ((HttpSessionBindingListener) value).valueBound(event);
                 }
                 catch (Throwable t)
                 {
                     manager.getContainer().getLogger().error(sm.getString("standardSession.bindingEvent"), t);
                 }
             }
         }

         // Replace or add this attribute
         Object unbound = attributes.put(name, value);

         // Call the valueUnbound() method if necessary
      [...]
}

Why valueBound() is called before setting the attribute in the map ? Is it allowed to call getAttribute() from valueBound() ? Is the following code correct ?

setAttribute("myAttr", myValue);
-> valueBound() event fired

In the valueBound() :
// getAttribute() always returns null
Object myAttr = getAttribute("myAttr");

Thanks in advance.

Regards,
Thomas


Ce message est protégé par les règles relatives au secret des correspondances. Il est donc établi à destination exclusive de son destinataire. Celui-ci peut donc contenir des informations confidentielles. La divulgation de ces informations est à ce titre rigoureusement interdite. Si vous avez reçu ce message par erreur, merci de le renvoyer à l'expéditeur dont l'adresse e-mail figure ci-dessus et de détruire le message ainsi que toute pièce jointe.

This message is protected by the secrecy of correspondence rules. Therefore, this message is intended solely for the attention of the addressee. This message may contain privileged or confidential information, as such the disclosure of these informations is strictly forbidden. If, by mistake, you have received this message, please return this message to the addressser whose e-mail address is written above and destroy this message and all files attached.



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


Re: Question about HttpSessionBindingListener and getAttribute in valueBound()

Posted by Thomas Chabaud <ex...@agora.msa.fr>.
I found the answer in the servlet specification :

SRV.7.4Binding Attributes into a Session

"The valueBound method must be called before the object is made available via
the getAttribute method of the HttpSession interface."

Sorry for the noise :-\

Le 12/04/2011 11:05, Thomas Chabaud a écrit :
> Hi,
>
> I have problem with Tomcat 6.0 StandardSession implementation.
> We have an application who calls setAttribute("myAttr", myValue), and try to get this attribute in a method launched in valueBound(), but only gets null value.
>
> According to source code, the setAttribute() method calls valueBound *before* setting attribute in attributes Map :
>
> public void setAttribute(String name, Object value, boolean notify)
> {
> [...]
> // Call the valueBound() method if necessary
> if (notify && value instanceof HttpSessionBindingListener)
> {
> // Don't call any notification if replacing with the same value
> Object oldValue = attributes.get(name);
> if (value != oldValue)
> {
> event = new HttpSessionBindingEvent(getSession(), name, value);
> try
> {
> ((HttpSessionBindingListener) value).valueBound(event);
> }
> catch (Throwable t)
> {
> manager.getContainer().getLogger().error(sm.getString("standardSession.bindingEvent"), t);
> }
> }
> }
>
> // Replace or add this attribute
> Object unbound = attributes.put(name, value);
>
> // Call the valueUnbound() method if necessary
> [...]
> }
>
> Why valueBound() is called before setting the attribute in the map ? Is it allowed to call getAttribute() from valueBound() ? Is the following code correct ?
>
> setAttribute("myAttr", myValue);
> -> valueBound() event fired
>
> In the valueBound() :
> // getAttribute() always returns null
> Object myAttr = getAttribute("myAttr");
>
> Thanks in advance.
>
> Regards,
> Thomas
>
>
> Ce message est protégé par les règles relatives au secret des correspondances. Il est donc établi à destination exclusive de son destinataire. Celui-ci peut donc contenir des informations
> confidentielles. La divulgation de ces informations est à ce titre rigoureusement interdite. Si vous avez reçu ce message par erreur, merci de le renvoyer à l'expéditeur dont l'adresse e-mail figure
> ci-dessus et de détruire le message ainsi que toute pièce jointe.
>
> This message is protected by the secrecy of correspondence rules. Therefore, this message is intended solely for the attention of the addressee. This message may contain privileged or confidential
> information, as such the disclosure of these informations is strictly forbidden. If, by mistake, you have received this message, please return this message to the addressser whose e-mail address is
> written above and destroy this message and all files attached.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>




Ce message est protégé par les règles relatives au secret des correspondances. Il est donc établi à destination exclusive de son destinataire. Celui-ci peut donc contenir des informations confidentielles. La divulgation de ces informations est à ce titre rigoureusement interdite. Si vous avez reçu ce message par erreur, merci de le renvoyer à l'expéditeur dont l'adresse e-mail figure ci-dessus et de détruire le message ainsi que toute pièce jointe.

This message is protected by the secrecy of correspondence rules. Therefore, this message is intended solely for the attention of the addressee. This message may contain privileged or confidential information, as such the disclosure of these informations is strictly forbidden. If, by mistake, you have received this message, please return this message to the addressser whose e-mail address is written above and destroy this message and all files attached.



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