You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Raphaël Piéroni <ra...@aql.fr> on 2007/09/11 17:04:06 UTC

[cocoon 2.2] Spring configuration of transformers

Hi Guys,


I have a transformer defined in the sitemap.xmap.
And this transformer have to access the database (DAO w/ transaction) 
that is defined with spring.
But i can't manage to link the 2 information.

Is there any documentation or example?

Regards,


Raphaël Piéroni

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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Joerg Heinicke <jo...@gmx.de>.
On 24.09.2007 6:07 Uhr, thuertas wrote:

> I tried to store beans in a database using Generator, Tansformer and 
> Serializer.
> That's ok for Generator and Serializer but there's nothing in database 
> when I use a Transformer!

> So why doesn't it work with a transformer? Is the spring transaction 
> initialized in the transformer?

This does not work this way at all from what I get since a Cocoon 
pipeline is streaming. I'll give a short introduction of both the 
concepts of this streaming and how Spring transaction interception works.

A Spring transaction spans a method call. The call to the method is 
intercepted, the transaction started, the actual method invocation is 
executed and when it returns from that it stops the transaction.

Now the streaming part. Whenever you call Generator.generate() it 
results in bunch of SAX ContentHandler method calls to the transformer 
and from there to the serializer. So usually (if it's not buffered) such 
a SAX event goes from the generator right through to the serializer. And 
when Generator.generate() is finished all the streaming a finished as 
well. That's why there is no Transformer.transform() method and no 
Serializer.serialize() method.

To put the picture together you only have to make the 
Generator.generate() method transactional and everything works fine. Of 
course you have to use your transformer and your serializer in a 
pipeline that's started with a transactional Generator.generate(). I'm 
sure your serializer does not work as expected for the same reason your 
transformer does not work.

Anyway, this whole approach seems to smell. I'd not execute any business 
logic in a pipeline. Actually the business processing should already be 
finished before you start to stream anything (have a look at flow 
script). The pipeline should only generate the outcome of the business 
transaction to show it to the user.

Hope this helps,

Joerg

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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by thuertas <tu...@aql.fr>.
Hi,
I tried to store beans in a database using Generator, Tansformer and 
Serializer.
That's ok for Generator and Serializer but there's nothing in database 
when I use a Transformer!
That's what I did:


>>>
>>>      <bean id="serviceProgramsGenerator"
>>> name="org.apache.cocoon.generation.Generation/serviceProgramsGenerator"
>>>     
>>                                         The above line should be 
>> o.a.c.generation.Generator not Generation, IIUC.
...
<property name="transactionAttributes">
            <props>
                <prop key="generate*">
                    PROPAGATION_REQUIRED
                </prop>



for Transformer:
 <bean 
name="org.apache.cocoon.transformation.Transformer/importTestTransformer"
        
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
...
    <property name="transactionAttributes">
            <props>
                <prop key="transform*">
                    PROPAGATION_REQUIRED
                </prop>



and for Serializer:
 <bean 
name="org.apache.cocoon.serialization.Serializer/importTestSerializer"
        
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
...
    <property name="transactionAttributes">
            <props>
                <prop key="setOutputStream*">
                    PROPAGATION_REQUIRED
                </prop>



I wrote the same code in them:
 
 MaColor color = new MaColor("purple");
  colorDAO.persist(color); 

So why doesn't it work with a transformer? Is the spring transaction 
initialized in the transformer?

Regards,

Tugdual Huertas

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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Raphaël Piéroni <ra...@aql.fr>.
Hi,

Many thanks,

that did the trick.

Raphaël


Jason Johnston a écrit :
> On Thu, 13 Sep 2007 17:56:27 +0200, Raphaël Piéroni
> <ra...@aql.fr> wrote:
>   
>> Thanks,
>> I tried, but it doesn't work.
>> Here what i did exactly:
>>     
> ...
>   
>> export defines it's spring stuff in
>> src/main/resources/META-INF/cocoon/spring/
>> It defines the block and the generator i try to test
>> like this:
>>     <bean id="com.fcompany.ma-i.block"
>> class="org.apache.cocoon.sitemap.SitemapServlet">
>>         <servlet:context mount-path="/ma-i"
>> context-path="blockcontext:/ma-i/" />
>>     </bean>
>>      <bean id="serviceProgramsGenerator"
>> name="org.apache.cocoon.generation.Generation/serviceProgramsGenerator"
>>     
>                                         
> The above line should be o.a.c.generation.Generator not Generation, IIUC.
>
>   
>>        class="com.company.project.ServiceProgramsGenerator">
>>        <property name="helperA">
>>            <ref bean="AHelper" />
>>        </property>
>>        <property name="helperMI">
>>            <ref bean="MIHelper" />
>>        </property>
>>    </bean>
>>
>> My pipeline is defined in src/main/resources/COB-INF/
>>        <map:pipeline>
>>            <map:match pattern="servicePrograms">
>>                <map:generate type="serviceProgramsGenerator" />
>>                <map:serialize type="xml" />
>>            </map:match>
>>        </map:pipeline>
>>     
>
>
> ---------------------------------------------------------------------
> 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: [cocoon 2.2] Spring configuration of transformers

Posted by Jason Johnston <co...@lojjic.net>.

On Thu, 13 Sep 2007 17:56:27 +0200, Raphaël Piéroni
<ra...@aql.fr> wrote:
> Thanks,
> I tried, but it doesn't work.
> Here what i did exactly:
...
> export defines it's spring stuff in
> src/main/resources/META-INF/cocoon/spring/
> It defines the block and the generator i try to test
> like this:
>     <bean id="com.fcompany.ma-i.block"
> class="org.apache.cocoon.sitemap.SitemapServlet">
>         <servlet:context mount-path="/ma-i"
> context-path="blockcontext:/ma-i/" />
>     </bean>
>      <bean id="serviceProgramsGenerator"
> name="org.apache.cocoon.generation.Generation/serviceProgramsGenerator"
                                        
The above line should be o.a.c.generation.Generator not Generation, IIUC.

>        class="com.company.project.ServiceProgramsGenerator">
>        <property name="helperA">
>            <ref bean="AHelper" />
>        </property>
>        <property name="helperMI">
>            <ref bean="MIHelper" />
>        </property>
>    </bean>
> 
> My pipeline is defined in src/main/resources/COB-INF/
>        <map:pipeline>
>            <map:match pattern="servicePrograms">
>                <map:generate type="serviceProgramsGenerator" />
>                <map:serialize type="xml" />
>            </map:match>
>        </map:pipeline>


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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Raphaël Piéroni <ra...@aql.fr>.
Thanks,
I tried, but it doesn't work.
Here what i did exactly:

I got 4 maven projects: common, storage, export, and webapp
obviously storage depends on common, export on storage and webapp 
depends on export.
webapp does not contain any java code nor any sitemap.

common defines it's spring configuration in 
src/main/resources/META-INF/cocoon/spring/application-context-common.xml 
(it only defines a logging component)

storage defines it's spring conf in 
src/main/resources/META-INF/cocoon/spring/application-context-storage.xml 
(it only defines the dao and transaction stuff)

export defines it's spring stuff in 
src/main/resources/META-INF/cocoon/spring/
It defines the block and the generator i try to test
like this:
    <bean id="com.fcompany.ma-i.block" 
class="org.apache.cocoon.sitemap.SitemapServlet">
        <servlet:context mount-path="/ma-i" 
context-path="blockcontext:/ma-i/" />
    </bean>
     <bean id="serviceProgramsGenerator" 
name="org.apache.cocoon.generation.Generation/serviceProgramsGenerator"
       class="com.company.project.ServiceProgramsGenerator">
       <property name="helperA">
           <ref bean="AHelper" />
       </property>
       <property name="helperMI">
           <ref bean="MIHelper" />
       </property>
   </bean>

My pipeline is defined in src/main/resources/COB-INF/
       <map:pipeline>
           <map:match pattern="servicePrograms">
               <map:generate type="serviceProgramsGenerator" />
               <map:serialize type="xml" />
           </map:match>
       </map:pipeline>

In webapp, i create the main web.xml and the main applicationContext.xml 
located in src/main/webapp/WEB-INF/

The war is correctly created.
it is also correctly started in jonas. But ther is a problem when 
calling it from a web browser.

The exception i see in the browser has a root cause which is :
org.apache.avalon.framework.configuration.ConfigurationException: Type 
'serviceProgramsGenerator' does not exist for 'map:generate' at 
file:/E:/JONAS_4_8_4/work/jonas/localhost/ma-webapp-1.0-SNAPSHOT/blocks/ma-import/sitemap.xmap:62:53 

    org.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage.getTypeForStatement(SitemapLanguage.java:558) 


I can recognise cocoon has correctly found my sitemap in the COB-INF in 
the jar in the webapp, but it seems not to found the spring component

What did i do wrong ?

Regards

Raphaël
   


Grzegorz Kossakowski a écrit :
> Raphaël Piéroni pisze:
>   
>> Do you mean something like this:
>> in my jar defining my block sitemap, i do
>> META-INF/c/s/myGenerators-services.xml
>> in which i do <bean name="o.a.c...Generator/myGeneratorName">
>>
>> and in my sitemap i do
>>        <map:pipeline>
>>            <map:match pattern="myPipeline">
>>                <map:generate type="myGeneratorName"/>
>>                <map:serialize type="xml"/>
>>            </map:match>
>>        </map:pipeline>
>> and also in the sitemap, i don't define
>> <map:components>
>>        <map:generators >
>>            <map:generator name="myGeneratorName"
>> src="com.company.project.MyGeneratorClass"/>
>>     
>
> Exactly. We decided that configuring components in sitemap is not such a good idea because it
> greatly pollutes it. Using standard (Spring-based) way of configuring all components is also easier
> for people because they don't have to learn anything new.
>
> So general advice for all people: if you develop new components don't declare them in a sitemap.
>
>   


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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Sébastien Geindre <se...@meteo.fr>.
> So general advice for all people: if you develop new components don't declare them in a sitemap.
>   
So, in order to use saxon transformer (XSLT 2.0), we have to declare it 
as spring component ?
How ? (newbie in spring...)

Thanks Grek !!

-- 
Sébastien Geindre
DPREVI/AERO/DEV
sebastien.geindre __at__ meteo.fr




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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Raphaël Piéroni pisze:
> Do you mean something like this:
> in my jar defining my block sitemap, i do
> META-INF/c/s/myGenerators-services.xml
> in which i do <bean name="o.a.c...Generator/myGeneratorName">
> 
> and in my sitemap i do
>        <map:pipeline>
>            <map:match pattern="myPipeline">
>                <map:generate type="myGeneratorName"/>
>                <map:serialize type="xml"/>
>            </map:match>
>        </map:pipeline>
> and also in the sitemap, i don't define
> <map:components>
>        <map:generators >
>            <map:generator name="myGeneratorName"
> src="com.company.project.MyGeneratorClass"/>

Exactly. We decided that configuring components in sitemap is not such a good idea because it
greatly pollutes it. Using standard (Spring-based) way of configuring all components is also easier
for people because they don't have to learn anything new.

So general advice for all people: if you develop new components don't declare them in a sitemap.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Raphaël Piéroni <ra...@aql.fr>.
Grzegorz Kossakowski a écrit :
> Raphaël Piéroni pisze:
>   
>>>  
>>>       
>>>> And this transformer have to access the database (DAO w/ transaction)
>>>> that is defined with spring.
>>>> But i can't manage to link the 2 information.
>>>>     
>>>>         
>>> Is this transformer a Spring bean? Do you want to inject Spring bean
>>> (a DAO) into some property of
>>> transformer?
>>>   
>>>       
>> Yup i try to inject the service wrapper arround the DAOs (with
>> transaction - spring aop) in a field transformer/generator
>>     
>
> Then configure your transformer as casual Spring bean and put configuration into
> META-INF/cocoon/spring. If you wonder how to name your bean just use following pattern:
> <fullyQualifiedNameOfInterfaceImplemented>/<nameOfComponentUsedInSitemap>
>
> Where first part can have three values (respectively, for Generator, Transformer and Serializer).
> This way of configuring sitemap components is preferred in Cocoon 2.2.
>
>   
Do you mean something like this:
in my jar defining my block sitemap, i do
META-INF/c/s/myGenerators-services.xml
in which i do <bean name="o.a.c...Generator/myGeneratorName">

and in my sitemap i do
        <map:pipeline>
            <map:match pattern="myPipeline">
                <map:generate type="myGeneratorName"/>
                <map:serialize type="xml"/>
            </map:match>
        </map:pipeline>
and also in the sitemap, i don't define
<map:components>
        <map:generators >
            <map:generator name="myGeneratorName" 
src="com.company.project.MyGeneratorClass"/>



Raphaël

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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Raphaël Piéroni pisze:
>>  
>>> And this transformer have to access the database (DAO w/ transaction)
>>> that is defined with spring.
>>> But i can't manage to link the 2 information.
>>>     
>>
>> Is this transformer a Spring bean? Do you want to inject Spring bean
>> (a DAO) into some property of
>> transformer?
>>   
> Yup i try to inject the service wrapper arround the DAOs (with
> transaction - spring aop) in a field transformer/generator

Then configure your transformer as casual Spring bean and put configuration into
META-INF/cocoon/spring. If you wonder how to name your bean just use following pattern:
<fullyQualifiedNameOfInterfaceImplemented>/<nameOfComponentUsedInSitemap>

Where first part can have three values (respectively, for Generator, Transformer and Serializer).
This way of configuring sitemap components is preferred in Cocoon 2.2.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Raphaël Piéroni <ra...@aql.fr>.
Grzegorz Kossakowski a écrit :
> Raphaël Piéroni pisze:
>   
>> Hi Guys,
>>
>>
>> I have a transformer defined in the sitemap.xmap.
>>     
>
> Is it your own transformer?
>   
Yep, IIRC, we also have some custom generators.
>   
>> And this transformer have to access the database (DAO w/ transaction)
>> that is defined with spring.
>> But i can't manage to link the 2 information.
>>     
>
> Is this transformer a Spring bean? Do you want to inject Spring bean (a DAO) into some property of
> transformer?
>   
Yup i try to inject the service wrapper arround the DAOs (with 
transaction - spring aop) in a field transformer/generator
>   
>> Is there any documentation or example?
>>     
>
> Nope, but it's on my TODO list (WARNING: it's already long) to write migration guide for migrating
> from Avalon to Spring.
>
>   


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


Re: [cocoon 2.2] Spring configuration of transformers

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Raphaël Piéroni pisze:
> Hi Guys,
> 
> 
> I have a transformer defined in the sitemap.xmap.

Is it your own transformer?

> And this transformer have to access the database (DAO w/ transaction)
> that is defined with spring.
> But i can't manage to link the 2 information.

Is this transformer a Spring bean? Do you want to inject Spring bean (a DAO) into some property of
transformer?

> Is there any documentation or example?

Nope, but it's on my TODO list (WARNING: it's already long) to write migration guide for migrating
from Avalon to Spring.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

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