Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Creating a LongRunningTask

Pankaj Jangid
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 19, 2011

I tried to discuss this in forums but got no answer. Pasting the contents of my posting here.

I am getting this Error in CustomLongRunningTask which extends ConfluenceAbstractLongRunningTask.

java.lang.ClassCastException: org.springframework.orm.hibernate.HibernateTransactionManager cannot be cast to org.springframework.transaction.PlatformTransactionManager

This exception occurs in my LongRunningClass at tt.setTransactionManager() shown below:-

protected void runInternal()
  {
    TransactionTemplate tt = new TransactionTemplate();
    tt.setTransactionManager((PlatformTransactionManager)ContainerManager
      .getInstance()
      .getContainerContext()
      .getComponent("transactionManager"));
    tt.execute(new TransactionCallbackWithoutResult() {
    .......
    })
  }

When I change the line

tt.setTransactionManager((PlatformTransactionManager)ContainerManager
    .getInstance()
    .getContainerContext()
    .getComponent("transactionManager"));

to

tt.setTransactionManager((HibernateTransactionManager)ContainerManager
    .getInstance()
    .getContainerContext()
    .getComponent("transactionManager"));

it compiles ok with atlas-mvn compile. But then I get this error at runtime:

Exception in thread "ECMS Export task" java.lang.NoClassDefFoundError: 
org/springframework/orm/hibernate/HibernateTransactionManager

Then I followed instructions at http://confluence.atlassian.com/display/DEVNET/Setting+OSGi+Manifest+Instructions+in+your+Plugin and updated pom to include <dependency> and <Include-Package>.

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-hibernate2</artifactId>
  <version>2.0.8</version>
  <scope>provided</scope>
</dependency>

<plugin>
  <groupId>com.atlassian.maven.plugins</groupId>
  <artifactId>maven-confluence-plugin</artifactId>
  <version>3.3.4</version>
  <extensions>true</extensions>
  <configuration>
     <productVersion>${confluence.version}</productVersion>
     <productDataVersion>${confluence.data.version}</productDataVersion>
     <log4jProperties>src/main/resources/log4j/log4j.properties</log4jProperties>
     <instructions>
        <Import-Package>*</Import-Package>
     </instructions>
  </configuration>
</plugin>

I get this error during plugin install:-

[INFO] [talledLocalContainer] Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle 
com.cadence.confluence.plugins.ecms [84]: Unable to resolve 84.0: missing requirement [84.0] package; 
(package=org.springframework.orm.hibernate)

And plugin is not loaded at all. I am stuck.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
CharlesA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2011

You are running into some reasonably nasty classloader issues.

For various technical and compatibility reasons, the plugin system runs its own, independent version of Spring. Because of this, the Spring classes loaded in the plugins classloader are not the same as the Spring classes loaded by the core Confluence application, and the Confluence application does not export any Spring classes to the plugin system.

In the first example when the TransactionManager from Confluence core is passed to your plugin, your plugin has loaded a different PlatformTransactionManager class that can not be reconciled with the one in core's classloader. Then when you changed your plugin to no longer bundle its own version of the transaction manager, your plugin can't find the TransactionManager class because (as mentioned above) it is not exported from Confluence to the plugin system.

In order to export pure Spring services to plugins, we have written bridging code between the two different layers. Instead of using the TransactionManager directly, you're better off taking Stefan's advice and using the SAL TransactionTemplate; a bridging service that allows you to run code in its own transaction without touching Spring directly.

0 votes
Stefan Kleineikenscheidt _K15t_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2011

Have you checked your package import for the TransactionTemplate? Make sure you use com.atlassian.sal.api.transaction.TransactionTemplate.

Pankaj Jangid
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2011

Usint TransactionTemplate also isn't working. Currently what I am doing is (sort-of) synchronously executing the long running task. And only after finishing the task I return from Action::execute().

This way the progress bar is not visible. :(

TAGS
AUG Leaders

Atlassian Community Events