Looks to me like you've got a problem with the scheduler not being able to handle being run within in an outer and inner Cocoon. Try rebuilding your Cocoon without it.

If you need it, then maybe you should try having the inner cocoon use a different webapp that has been built without the scheduler.

Regards, Upayavira

Patrick Hess wrote:


Hi there,


I already asked some questions about this on the users list. What I want to do: Inside my webapp I would like to create an action or something like an action to call Cocoon in CLI-style. Simplest way would be calling the "cocoon cli" script but that's to ugly... So my next approach was trying to use the CocoonBean inside of an action. I know this creates a complete second instance of Cocoon but that seems more acceptable to me than the "external-execute" approach.

Some basic infos: I'm using Cocoon 2.1.3 / Sun JVM 1.4.1 / Win2000 and
Tomcat 4.1.24 as servlet container. Cocoon was compiled as webapp.

I wrote some test code and played a bit and create a publish() method based on code in org.apache.cocoon.Main which sets up a CocoonBean and exports some Uris...

Using the java code (below) it's possible to call the publish() method
from the main() method or as action inside of Cocoon. It's setting up a CocoonBean and exporting 2 URIs defined in my sitemap.


Calling publish() through main() from CLI works like expected but calling the action from the sitemap fails with this message:

BROKEN: Environment stack has not been cleaned up properly. Please report this (if possible together with a test case) to the Cocoon developers.

Maybe it's related to 'abuse' of CocoonBean in my code? :) Maybe someone can help me getting this topic clearer...

- it it possible to run to instances of Coccon in the same JVM?
- is there something missing in my CocoonBean setup that causes
  the message above that can be fixed?
- is there a better way to use Cocoon CLI from a Cocoon webapp?

Thanks,
  Patrick


Output when calling publish() through action from Cocoon webapp:


------------------------------------------------------------------------
cocoon 2.1.3
Copyright (c) 1999-2003 Apache Software Foundation. All rights reserved.
------------------------------------------------------------------------


- Quartz scheduler 'Cocoon
- Quartz scheduler version: 1.2.3
- Scheduler Cocoon_$_Sat_Jan_17_15:10:07_CET_2004 started.
X [0] test/data2.html BROKEN: Environment stack has not been cleaned up properly. Please report this (if possible together with a test case) to the Cocoon developers.
X [0] test/data1.html BROKEN: Environment stack has not been cleaned up properly. Please report this (if possible together with a test case) to the Cocoon developers.
Total time: 0 minutes 2 seconds, Site size: 0 Site pages: 0






Output when calling publish() from command line using main():

------------------------------------------------------------------------
cocoon 2.1.3
Copyright (c) 1999-2003 Apache Software Foundation. All rights reserved.
------------------------------------------------------------------------


* [1/1] [0/0] 1.942s 3.8Kb test/data2.html * [2/0] [0/0] 0.311s 4.3Kb test/data1.html Total time: 0 minutes 7 seconds, Site size: 8.380 Site pages: 2





Java code used for testing, publish() method contains main code and is called from main()/command line or act()/as action:


package de.posi.cocoon.action;


import java.util.HashMap;
import java.util.Map;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.bean.CocoonBean;
import org.apache.cocoon.bean.helpers.OutputStreamListener;
import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;

public class MyAction implements Action {

public Map act (Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters parameters) {


        Context context =
            ObjectModelHelper.getContext(objectModel);

String contextPath = context.getRealPath("/");
if (publish (contextPath)) {
return new HashMap();
}
return null;
}


private boolean publish (String contextPath) {

boolean result = false;
CocoonBean cocoon = new CocoonBean();
OutputStreamListener listener
= new OutputStreamListener (System.out);


        cocoon.addListener(listener);
        cocoon.setContextDir (contextPath);

        cocoon.setLogKit (contextPath +
                    "/WEB-INF/logkit.xconf");
        cocoon.setConfigFile (contextPath +
                    "/WEB-INF/cocoon.xconf");

        String destDir = contextPath + "/dest";
        cocoon.addTarget ("test/data1.html", destDir);
        cocoon.addTarget ("test/data2.html", destDir);

listener.messageGenerated(CocoonBean.getProlog());
try {
cocoon.initialize();
cocoon.process();
result = true;


        } catch (Exception e) {
            e.printStackTrace();
        }

cocoon.dispose();
listener.complete();
return result;
}


public static void main (String args[]) {

MyAction ma = new MyAction();
ma.publish ("C:\\Cocoon\\testapp"); }
}



Sitemap used for testing the action:


<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0";>
 <map:components>
  <map:actions>
   <map:action name="publish" src="de.posi.cocoon.action.MyAction"/>
  </map:actions>
 </map:components>

 <map:pipelines>
  <map:pipeline>
   <map:match pattern="publish">

    <map:act type="publish">
     <map:redirect-to uri="http://www.google.com"; />
    </map:act>
    <map:redirect-to uri="http://www.yahoo.com"; />
   </map:match>

  </map:pipeline>
 </map:pipelines>
</map:sitemap>










Reply via email to