You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Kaj Kandler <Ka...@conficio.com> on 2006/10/30 13:53:56 UTC

using temporary session-context to share value

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there,
I need help with using the temporary session-context to share value.

I have a stylesheet that creates a key
- ---
<xsl:stylesheet
  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  				xmlns:session="http://apache.org/cocoon/session/1.0">

   <xsl:template match="key">
	<!-- create some random number as base for a confirmation URL -->
	<xsl:variable name="rnd" select="translate(math:random(),'.','x')"
		xmlns:math="xalan://java.lang.Math"/>
  	<xsl:copy>
		<xsl:value-of select="concat('cu',$rnd)"/>
  	</xsl:copy>
  	<session:setxml context="temporary" path="my_key"><xsl:value-of
select="concat('cu',$rnd)"/></session:setxml>
  </xsl:template>
...
- ---
and I need to use this key in an e-mail I creating later in the request:
- ---
      <map:match pattern="save">
		<map:generate src="newuser.xml"/>
<!-- generate key -->	<map:transform src="stylesheets/generate-key.xsl"/>
		<map:transform type="session"/>
		<map:transform type="cinclude"/>
		<map:transform type="write-source"/>
 		<map:serialize type="xml"/>
     </map:match>


      <map:match pattern="do-register">
      	<map:aggregate element="site" label="raw-data">
<!-- this generates the key -->  <map:part src="cocoon:/save"/>
			<map:part src="cocoon:/thanks"/>
	</map:aggregate>
	<map:transform type="idgen" label="id"/>
	<map:transform type="xinclude" label="include"/>
...
	<map:act type="sendmail">
...
		<map:parameter name="body" value="Thank you for registring with Plan-B
for OpenOffice.org. Please confirm your e-mail address by clicking on
'{session-context:temporary/my_key}'"/>
...
	    <map:serialize/>
	</map:act>
     </map:match>
- ---
However I never see the temporary/my_key in the sitemap. Any ideas what
I'm doing wrong.

K<o>
- --
KajKandler@Conficio.com
 http://conficio.blogspot.com/
 ================================================
 |  We teach software one screencast at a time  |
 ================================================
 http://www.conficio.com/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)

iD8DBQFFRfXkRDUvrJRNjTARAjIQAJ9xkDHEANjNKoAUD/tSfRgA0nuszgCgjN4/
y6Fu6fzD7rxPJujpXKwEtHk=
=U0JM
-----END PGP SIGNATURE-----

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


Re: using temporary session-context to share value

Posted by Kaj Kandler <Ka...@conficio.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Jason,
you might be bringing me on the right track here.

Let me clarify:
>> Unfortunately I seem not to be able to get the session context in the
>> sitemap to log anything meaningful.
I mean the DefaultContextManager class does not _log_ anything
meaningful to actually debug the problem. Here is my locally patched
version to see what actually goes on in there
- ---
    /**
     *  Get a public context.
     *  The session context with the given name is returned. If the
context does
     *  not exist <CODE>null</CODE> is returned.
     */
    public SessionContext getContext(String name)
    throws ProcessingException {
        // synchronized
        if (this.getLogger().isDebugEnabled() ) {
            this.getLogger().debug("BEGIN getContext name=" + name);
        }

        SessionContext context;
        if (this.isReservedContextName(name) ) {
            context = this.getReservedContext(name);
        } else {
            Session session = this.getSession(false);
            if ( session != null) {
                synchronized (session) {
                    final Map contexts = this.getSessionContexts( session );
                    context = (SessionContext)contexts.get(name);
                }
            } else {
                if (this.getLogger().isDebugEnabled() ) {
                    this.getLogger().debug("getContext no session");
                }
                context = null;
            }
        }

        if (this.getLogger().isDebugEnabled() ) {
            this.getLogger().debug("END getContext context=" + context +
"; nodes="+(context==null?"":(context.getNodeList("/").toString())));
        }

        return context;
    }
- ---

However, what I try to do is the following:

* I have a registration page (form) that goes through the session
transformer to write to a file users.xml a new entry for a user.
* I have an XSL transformation, creation a confirmation key.
* I need to send an e-mail to the person registering, with that
generated authentication key.

If I hear you correctly it is not possible in the _same request_ to have
this key generated (via XSLT) written to a session context via the
session transformer and then read it in the sitemap (in order to get it
into the e-mail body.).

I thought the existence of the temporary session context would point to
exactly this use case. Am I wrong?

By the way what exactly is a session attribute? I'm using the
session-context input module. Is session-attr simply a synonym? Because
it appears that one could access xml elements "/my_element" as well as
attributes "/my_element/@my_attribute" from the context.

Thanks for the help! I really appreciate it.

K<o>

Jason Johnston wrote:
> Kaj Kandler wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi Joeren,
>> thanks for helping me here. I tried a lot of things, off course. But
>> after hours of experimenting and trying to find some decent logging that
>> would reveal my problem, I resorted to looking for help.
>>
>> According to
>> http://cocoon.apache.org/2.1/developing/webapps/contexts.html, there is
>> always a temporary context available to do what I want to do (preserve a
>> value until the end of the request. "Using the tempory context it is
>> possible to store any XML information for processing the current
>> request."
>>
>> The attempt to use a path="/key" does no difference.
>>
>> <session:createcontext name="temp"></session:createcontext>
>> <session:setxml context="temp" path="/key"><xsl:value-of
>> select="concat('cu',$rnd)"/></session:setxml>
>>
>> Makes no difference either.
> ...
>> Unfortunately I seem not to be able to get the session context in the
>> sitemap to log anything meaningful.
> 
> When you say "get the session context in the sitemap", what exactly are
> you trying to do?  Trying to access a session attribute in the sitemap
> via the {session-attr:blah} input module or something?  If so, then this
> will not work with the session transformer.  The reason is that the
> sitemap is completely evaluated to set up the pipeline *before* any
> content starts to be fed through the pipeline.  So it's impossible to
> make any choices in the sitemap based on content going through the
> pipeline.
> 
> If you mean something else, could you give details?
> 
> 
>>
>> Once again, thanks for helping me out here.
>> K<o>
>>
>> Jeroen Reijn wrote:
>>> Hi Kaj,
>>>
>>> i do not have a lot of experience with the session-context and session
>>> transformer, but i will try as much as I can to help you out.
>>>
>>>> I have a stylesheet that creates a key
>>>> - ---
>>>> <xsl:stylesheet
>>>>   version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>>                   xmlns:session="http://apache.org/cocoon/session/1.0">
>>>>
>>>>    <xsl:template match="key">
>>>>     <!-- create some random number as base for a confirmation URL -->
>>>>     <xsl:variable name="rnd" select="translate(math:random(),'.','x')"
>>>>         xmlns:math="xalan://java.lang.Math"/>
>>>>       <xsl:copy>
>>>>         <xsl:value-of select="concat('cu',$rnd)"/>
>>>>       </xsl:copy>
>>>>       <session:setxml context="temporary" path="my_key"><xsl:value-of
>>>> select="concat('cu',$rnd)"/></session:setxml>
>>>>   </xsl:template>
>>>> ...
>>>
>>> Looking at the documentation about the session-context the following
>>> issues come to mind:
>>>
>>> In the example they create their own context first by doing:
>>> <session:createcontext name="trackdemo"/>
>>>
>>> Where trackdemo is the context used somewhere else in the xml body like:
>>> <session:mergexml context="trackdemo" path="/context">
>>>
>>> So my first question: did you set your context? If so did you try to add
>>> a / in front of your path?
>>>
>>> What happens if you do it like this?
>>>
>>> Regards,
>>>
>>> Jeroen Reijn
>>> Hippo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

- --
KajKandler@Conficio.com
 http://conficio.blogspot.com/
 ================================================
 |  We teach software one screencast at a time  |
 ================================================
 http://www.conficio.com/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)

iD8DBQFFRhYoRDUvrJRNjTARAnuMAJ44EUAgwHgW6psRVGDobB4J5RQNtgCfVZ4c
+Zq0wuuMEjtO6I7Km8G5Rz0=
=DhzF
-----END PGP SIGNATURE-----

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


Re: using temporary session-context to share value

Posted by Jason Johnston <co...@lojjic.net>.
Kaj Kandler wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi Joeren,
> thanks for helping me here. I tried a lot of things, off course. But
> after hours of experimenting and trying to find some decent logging that
> would reveal my problem, I resorted to looking for help.
> 
> According to
> http://cocoon.apache.org/2.1/developing/webapps/contexts.html, there is
> always a temporary context available to do what I want to do (preserve a
> value until the end of the request. "Using the tempory context it is
> possible to store any XML information for processing the current request."
> 
> The attempt to use a path="/key" does no difference.
> 
> <session:createcontext name="temp"></session:createcontext>
> <session:setxml context="temp" path="/key"><xsl:value-of
> select="concat('cu',$rnd)"/></session:setxml>
> 
> Makes no difference either.
...
> Unfortunately I seem not to be able to get the session context in the
> sitemap to log anything meaningful.

When you say "get the session context in the sitemap", what exactly are 
you trying to do?  Trying to access a session attribute in the sitemap 
via the {session-attr:blah} input module or something?  If so, then this 
will not work with the session transformer.  The reason is that the 
sitemap is completely evaluated to set up the pipeline *before* any 
content starts to be fed through the pipeline.  So it's impossible to 
make any choices in the sitemap based on content going through the pipeline.

If you mean something else, could you give details?


> 
> Once again, thanks for helping me out here.
> K<o>
> 
> Jeroen Reijn wrote:
>> Hi Kaj,
>>
>> i do not have a lot of experience with the session-context and session
>> transformer, but i will try as much as I can to help you out.
>>
>>> I have a stylesheet that creates a key
>>> - ---
>>> <xsl:stylesheet
>>>   version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>                   xmlns:session="http://apache.org/cocoon/session/1.0">
>>>
>>>    <xsl:template match="key">
>>>     <!-- create some random number as base for a confirmation URL -->
>>>     <xsl:variable name="rnd" select="translate(math:random(),'.','x')"
>>>         xmlns:math="xalan://java.lang.Math"/>
>>>       <xsl:copy>
>>>         <xsl:value-of select="concat('cu',$rnd)"/>
>>>       </xsl:copy>
>>>       <session:setxml context="temporary" path="my_key"><xsl:value-of
>>> select="concat('cu',$rnd)"/></session:setxml>
>>>   </xsl:template>
>>> ...
>>
>> Looking at the documentation about the session-context the following
>> issues come to mind:
>>
>> In the example they create their own context first by doing:
>> <session:createcontext name="trackdemo"/>
>>
>> Where trackdemo is the context used somewhere else in the xml body like:
>> <session:mergexml context="trackdemo" path="/context">
>>
>> So my first question: did you set your context? If so did you try to add
>> a / in front of your path?
>>
>> What happens if you do it like this?
>>
>> Regards,
>>
>> Jeroen Reijn
>> Hippo

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


Re: using temporary session-context to share value

Posted by Jeroen Reijn <j....@hippo.nl>.
Kaj,

I have no idea why it puts the XML declaration inside the session, but
since my knowlegde of the session transformer is very little I was more 
thinking of a different approach.. did you try to use flow for instance 
I guess flow can really help you out here?

Regards,

Jeroen Reijn


Kaj Kandler wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi Joeren,
> thanks for helping me here. I tried a lot of things, off course. But
> after hours of experimenting and trying to find some decent logging that
> would reveal my problem, I resorted to looking for help.
> 
> According to
> http://cocoon.apache.org/2.1/developing/webapps/contexts.html, there is
> always a temporary context available to do what I want to do (preserve a
> value until the end of the request. "Using the tempory context it is
> possible to store any XML information for processing the current request."
> 
> The attempt to use a path="/key" does no difference.
> 
> <session:createcontext name="temp"></session:createcontext>
> <session:setxml context="temp" path="/key"><xsl:value-of
> select="concat('cu',$rnd)"/></session:setxml>
> 
> Makes no difference either.
> 
> Here is what the logs have to say:
> - ---
> DEBUG (2006-10-30) 08:45.55:653 [core.session-manager] (/do-register)
> PoolThread-3/DefaultSessionManager: BEGIN setContextFragment name=temp,
> path=/key, fragment=<?xml version="1.0" encoding="UTF-8"?>
> cu0x8610037794015678
> DEBUG (2006-10-30) 08:45.55:653 [core.session-manager.context]
> (/do-register) PoolThread-3/DefaultContextManager: BEGIN getContext
> name=temp
> DEBUG (2006-10-30) 08:45.55:653 [core.session-manager.context]
> (/do-register) PoolThread-3/DefaultContextManager: END getContext
> context=org.apache.cocoon.webapps.session.context.SimpleSessionContext@54f169
> DEBUG (2006-10-30) 08:45.55:663 [core.session-manager] (/do-register)
> PoolThread-3/DefaultSessionManager: END setContextFragment
> - ---
> 
> I somehow wonder, why it says "<?xml version="1.0" encoding="UTF-8"?>
> cu0x8610037794015678" instead of "cu0x8610037794015678"?
> 
> Unfortunately I seem not to be able to get the session context in the
> sitemap to log anything meaningful.
> 
> Once again, thanks for helping me out here.
> K<o>
> 
> Jeroen Reijn wrote:
>> Hi Kaj,
>>
>> i do not have a lot of experience with the session-context and session
>> transformer, but i will try as much as I can to help you out.
>>
>>> I have a stylesheet that creates a key
>>> - ---
>>> <xsl:stylesheet
>>>   version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>>                   xmlns:session="http://apache.org/cocoon/session/1.0">
>>>
>>>    <xsl:template match="key">
>>>     <!-- create some random number as base for a confirmation URL -->
>>>     <xsl:variable name="rnd" select="translate(math:random(),'.','x')"
>>>         xmlns:math="xalan://java.lang.Math"/>
>>>       <xsl:copy>
>>>         <xsl:value-of select="concat('cu',$rnd)"/>
>>>       </xsl:copy>
>>>       <session:setxml context="temporary" path="my_key"><xsl:value-of
>>> select="concat('cu',$rnd)"/></session:setxml>
>>>   </xsl:template>
>>> ...
>>
>> Looking at the documentation about the session-context the following
>> issues come to mind:
>>
>> In the example they create their own context first by doing:
>> <session:createcontext name="trackdemo"/>
>>
>> Where trackdemo is the context used somewhere else in the xml body like:
>> <session:mergexml context="trackdemo" path="/context">
>>
>> So my first question: did you set your context? If so did you try to add
>> a / in front of your path?
>>
>> What happens if you do it like this?
>>
>> Regards,
>>
>> Jeroen Reijn
>> Hippo
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
> 
> - --
> KajKandler@Conficio.com
>  http://conficio.blogspot.com/
>  ================================================
>  |  We teach software one screencast at a time  |
>  ================================================
>  http://www.conficio.com/
>  Tel: +1 (781) 632 5773 - Fax: +1 (781) 207 9159
>  Conficio
>  P.O.Box 761062,  Melrose,
>  MA 02176
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (MingW32)
> 
> iD8DBQFFRgOvRDUvrJRNjTARAh23AJ9amKR/EZ5oYND6sfcOw2XfIVPl1wCfZP4S
> uKe2S9sDxgejCWxpIJXFTO4=
> =aQCM
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

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


Re: using temporary session-context to share value

Posted by Kaj Kandler <Ka...@conficio.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Joeren,
thanks for helping me here. I tried a lot of things, off course. But
after hours of experimenting and trying to find some decent logging that
would reveal my problem, I resorted to looking for help.

According to
http://cocoon.apache.org/2.1/developing/webapps/contexts.html, there is
always a temporary context available to do what I want to do (preserve a
value until the end of the request. "Using the tempory context it is
possible to store any XML information for processing the current request."

The attempt to use a path="/key" does no difference.

<session:createcontext name="temp"></session:createcontext>
<session:setxml context="temp" path="/key"><xsl:value-of
select="concat('cu',$rnd)"/></session:setxml>

Makes no difference either.

Here is what the logs have to say:
- ---
DEBUG (2006-10-30) 08:45.55:653 [core.session-manager] (/do-register)
PoolThread-3/DefaultSessionManager: BEGIN setContextFragment name=temp,
path=/key, fragment=<?xml version="1.0" encoding="UTF-8"?>
cu0x8610037794015678
DEBUG (2006-10-30) 08:45.55:653 [core.session-manager.context]
(/do-register) PoolThread-3/DefaultContextManager: BEGIN getContext
name=temp
DEBUG (2006-10-30) 08:45.55:653 [core.session-manager.context]
(/do-register) PoolThread-3/DefaultContextManager: END getContext
context=org.apache.cocoon.webapps.session.context.SimpleSessionContext@54f169
DEBUG (2006-10-30) 08:45.55:663 [core.session-manager] (/do-register)
PoolThread-3/DefaultSessionManager: END setContextFragment
- ---

I somehow wonder, why it says "<?xml version="1.0" encoding="UTF-8"?>
cu0x8610037794015678" instead of "cu0x8610037794015678"?

Unfortunately I seem not to be able to get the session context in the
sitemap to log anything meaningful.

Once again, thanks for helping me out here.
K<o>

Jeroen Reijn wrote:
> Hi Kaj,
> 
> i do not have a lot of experience with the session-context and session
> transformer, but i will try as much as I can to help you out.
> 
>> I have a stylesheet that creates a key
>> - ---
>> <xsl:stylesheet
>>   version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>                   xmlns:session="http://apache.org/cocoon/session/1.0">
>>
>>    <xsl:template match="key">
>>     <!-- create some random number as base for a confirmation URL -->
>>     <xsl:variable name="rnd" select="translate(math:random(),'.','x')"
>>         xmlns:math="xalan://java.lang.Math"/>
>>       <xsl:copy>
>>         <xsl:value-of select="concat('cu',$rnd)"/>
>>       </xsl:copy>
>>       <session:setxml context="temporary" path="my_key"><xsl:value-of
>> select="concat('cu',$rnd)"/></session:setxml>
>>   </xsl:template>
>> ...
> 
> 
> Looking at the documentation about the session-context the following
> issues come to mind:
> 
> In the example they create their own context first by doing:
> <session:createcontext name="trackdemo"/>
> 
> Where trackdemo is the context used somewhere else in the xml body like:
> <session:mergexml context="trackdemo" path="/context">
> 
> So my first question: did you set your context? If so did you try to add
> a / in front of your path?
> 
> What happens if you do it like this?
> 
> Regards,
> 
> Jeroen Reijn
> Hippo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

- --
KajKandler@Conficio.com
 http://conficio.blogspot.com/
 ================================================
 |  We teach software one screencast at a time  |
 ================================================
 http://www.conficio.com/
 Tel: +1 (781) 632 5773 - Fax: +1 (781) 207 9159
 Conficio
 P.O.Box 761062,  Melrose,
 MA 02176

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)

iD8DBQFFRgOvRDUvrJRNjTARAh23AJ9amKR/EZ5oYND6sfcOw2XfIVPl1wCfZP4S
uKe2S9sDxgejCWxpIJXFTO4=
=aQCM
-----END PGP SIGNATURE-----

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


Re: using temporary session-context to share value

Posted by Jeroen Reijn <j....@hippo.nl>.
Hi Kaj,

i do not have a lot of experience with the session-context and session 
transformer, but i will try as much as I can to help you out.

> I have a stylesheet that creates a key
> - ---
> <xsl:stylesheet
>   version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   				xmlns:session="http://apache.org/cocoon/session/1.0">
> 
>    <xsl:template match="key">
> 	<!-- create some random number as base for a confirmation URL -->
> 	<xsl:variable name="rnd" select="translate(math:random(),'.','x')"
> 		xmlns:math="xalan://java.lang.Math"/>
>   	<xsl:copy>
> 		<xsl:value-of select="concat('cu',$rnd)"/>
>   	</xsl:copy>
>   	<session:setxml context="temporary" path="my_key"><xsl:value-of
> select="concat('cu',$rnd)"/></session:setxml>
>   </xsl:template>
> ...


Looking at the documentation about the session-context the following 
issues come to mind:

In the example they create their own context first by doing:
<session:createcontext name="trackdemo"/>

Where trackdemo is the context used somewhere else in the xml body like:
<session:mergexml context="trackdemo" path="/context">

So my first question: did you set your context? If so did you try to add 
a / in front of your path?

What happens if you do it like this?

Regards,

Jeroen Reijn
Hippo

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