Generating sitepublisher pages in the background of a workflow

Posted: 28 August 2009 in CGI tasks, CSSDK, Java, Pages, SitePublisher, Sites, Teamsite, URLExternalTask, WebTask.do tasks, Worfklow models, Workflows

When you generate sitepublisher pages in the out of the box workflow, it runs as a CGI script invoking /iw-cc/Workflow/Webtask.do. This requires the user to start the input task in certain circumstances which may not always be desirable. In those cases, we want to run the page generation as a URLExternalTask, not as a CGI script.

how does it work?

In the Teamsite web application, *.do requests are intercepted by struts and so is our /iw-cc/Workflow/Webtask.do request. No exception… A task variable with a name of TaskBeanId is passed to the task and struts will instantiate an object of the corresponding class by resolving the bean entry from the file httpd/webapps/content_center/WEB-INF/conf/livesite/resources/workflow-resource-config.xml.

The TaskBeanId in question in the original task is workflow.task.PageConversionTask and, looking in the file workflow-resource-config.xml, we can translate it to com.interwoven.livesite.workflow.web.task.PageConversionWebTask.

<bean id="workflow.task.PageConversionTask"
    class="com.interwoven.livesite.workflow.web.task.PageConversionWebTask">
 <property name="viewPath" value="/livesite/Workflow/PageConversionWebTask.jsp"/>
 <property name="suffixVariableName" value="Suffix"/>
 <property name="processorVariableName" value="Processor"/>
 <property name="destinationDirectoryVariableName" value="DestinationDirectory"/>
 <property name="filterPatternVariableName" value="FilterPatterns"/>
 <!-- if you want a custom delimiter for the filter patterns, default is comma -->
 <property name="filterPatternDelimiterVariableName" value="FilterPatternDelimiter"/>
 </bean>

When an object of that class is instantiated, the other properties associated with the bean are set with the values given. These will allow the object to query the task and find the task variable with a name of Suffix, Processor, DestinationDirectory,FilterPatterns and FilterPatternDelimiter.

Creating a URLEXternalTask

Inside workflowModeler, add a URL Task to the canvas of the workflow model. set the predecessor by linking to the task from another task or the start event icon. Set the name of the task to be “Generate HTML”. This name can be whatever you want but it is quite significant elsewhere as we will see later. Set the URI to be http://localhost/iw-cc/urlexternaltask.

In the Task Variables, we will specify the class to execute and no, we will not use the class com.interwoven.livesite.workflow.web.task.PageConversionWebTask because that class expects some JSP to forward the request to. No, instead we shall look at the other bean defined by the following XML:

<bean id="workflow.task.HeadlessPageConversionTask"
    class="com.interwoven.livesite.workflow.task.PageConversionTask">
 <property name="suffixVariableName" value="Suffix"/>
 <property name="processorVariableName" value="Processor"/>
 <property name="destinationDirectoryVariableName" value="DestinationDirectory"/>
 <property name="servicePath" value="/iw-cc/livesite/PageConversionServlet"/>
 <property name="sessionStringParameterName" value="iw_sessionstring"/>
 <property name="filterPatternVariableName" value="FilterPatterns"/>
 <!-- if you want a custom delimiter for the filter patterns, default is comma -->
 <property name="filterPatternDelimiterVariableName" value="FilterPatternDelimiter"/>
 </bean>

The reason we choose this one is because it does not require to forward any requests anywhere. we will duplicate the original task variables for Suffix, Processor, DestinationDirectory, FilterPatterns, FilterPatternDelimiter.

However, when we have the original CGI script task WebTask.do activated, struts will instantiate the bean for us, with the right values for the properties. Our external task currently does no such thing. Waht we shal do is create a custom CSURLExternalTask that extends the bean class specified and, upon instantiation sets the property values.

package com.acme.workflow;

public class PageConversionTask extends com.interwoven.livesite.workflow.task.PageConversionTask {

    private String mSuffixVariableName="Suffix";
    private String mProcessorVariableName="Processor";
    private String mDestinationDirectoryVariableName="DestinationDirectory";
    private String mFilterPatternVariableName="FilterPatterns";
    private String mFilterPatternDelimiterVariableName="FilterPatternDelimiter";
    private String mSessionStringParameterName="iw_sessionstring";
    private String mServicePath="/iw-cc/livesite/PageConversionServlet";

    public PageConversionTask() {
        super();
        super.setProcessorVariableName(mProcessorVariableName);
        super.setDestinationDirectoryVariableName(mDestinationDirectoryVariableName);
        super.setFilterPatternVariableName(mFilterPatternVariableName);
        super.setFilterPatternDelimiterVariableName(mFilterPatternDelimiterVariableName);
        super.setSessionStringParameterName(mSessionStringParameterName);
        super.setServicePath(mServicePath);
        super.setSuffixVariableName(mSuffixVariableName);
        System.out.println("instantiated com.acme.workflow.PageConversionTask");
    }

}

Compile the class into the customer_src toolkit and set the task variable ClassName to com.acme.workflow.PageConversionTask. The class will be executed by the workflow but as it stands will fail to transition properly. This is because the transition link names must be whatever the name of the task is plus “Success” or “Failure”. In our case it should be “Generate HTML Success” and “Generate HTML Failure”.

Another thing, this time concerning task paramerers. The way the task has been implemented, it is shomehow expecting task parameters, otherwise it reports an excpetion and fails. We need to pass some parameters to the task and it doesn’t even matter what they are. so for the URI, we can specify http://localhost/iw-cc/urlexternaltask?someParam=someValue. The task itself doesn’t even seem to use those parameters at all(!).

This little thing could be used to our advantage. If you look in our custom class, the names of the variables are hard-coded. This should be modified in the constructor to look ath the values of equivalent parameters, which could be passed with http://localhost/iw-cc/urlexternaltask?suffixVariableName=Suffix&destinationDirectoryVariableName=DestinationDirectory etc… To read the values would be done with a task.getParameter(“suffixVariableName”) statement.

Conclusion

You now can invoke page generation in workflows automatically without the intervention of users, in complete silence of the background process in the depth of your workflows.  Genius.

Advertisements
Comments
  1. Cris B says:

    I tried this and it worked perfect! Thanks!

  2. I’m glad you approve… Now I’ want to do the same with the attach resources 🙂

  3. Howell says:

    I’ll want to do the same with the attach dependencies, seems don’t has corresponding class
    com.interwoven.livesite.workflow.task.DependencyWebTask
    like
    com.interwoven.livesite.workflow.web.task.PageConversionWebTask
    com.interwoven.livesite.workflow.task.PageConversionTask

    I tried to implement external task class file, but i dont know how to process the getDependencyProcessors()

  4. that’s not easy. I had started to look into this but gave up due to lack of time and probably won’t be able to look into it for some time to come. If you do find a solution and want to share it, please let us know.

  5. Steve North says:

    Excellent Post.

    Having issues with the large volumes e.g. >100 pages.

    It appears the PageConversionServlet is ultimately timing out (and failing the task). Changing the underlying wpostXml method is going to get painful. I think an audit task post page conversion is the way to go.

    Good Stuff !

  6. Ravi says:

    Hi, Do you have solution to the below issue?

    I’ll want to do the same with the attach dependencies, seems don’t has corresponding class
    com.interwoven.livesite.workflow.task.DependencyWebTask
    like
    com.interwoven.livesite.workflow.web.task.PageConversionWebTask
    com.interwoven.livesite.workflow.task.PageConversionTask

    I tried to implement external task class file, but i dont know how to process the getDependencyProcessors()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s