Looking for Assistance with Confluence Plugin Migration to Java Config: Runtime Errors Encountered

Hello community,

In light of the new requirements for the upcoming Confluence 9, we have encountered an issue with our plugin as outlined here.

The proposed solution involves migrating to Java Config, a process we have successfully executed with our Jira plugin in the past. However, we have encountered a roadblock.

Following the documentation provided here and here, which we previously used for converting our Jira plugin, we have attempted to implement the migration.

The issue arises when attempting to use the com.atlassian.activeobjects.external.ActiveObjects from an internal service BasServiceImpl invoking the findSession method with the error: Failed to find org.hibernate.Session from the current thread.

// Interface
@Transactional
public interface BasService

{

// Methods
….

}

....
// Constructor
public BasServiceImpl(ActiveObjects ao, PageManager pagerManager, AttachmentManager attachmentManager, BootstrapManager bootstrapManager, NotificationManager notificationManager, AccessModeCompatService accessModeCompatService, MailService mailService, ApplicationProperties appProps, PermissionManager permissionManager, MockupsLicenseManager licenseManager, UserAccessor p_userAccessor)

{

_ao = *checkNotNull*(ao);

...

}


public BasSession findSession(String token)
{

final BasSession[] basSession;
BasSession ret = null;

// runtime exception with Java Config
basSession = _ao.find(BasSession.class, "TOKEN = ?", token);

…

}

It appears there may be a discrepancy within the Spring mechanism, yet we have been unable to identify a solution, despite comparing our configuration with the Jira plugin, which is operational.

Maybe the @Transactional keyword is not handled correctly with Java Config ?

For reference, here you can find the configuration files.

Thanks for any advise !

Hi Andrea,

Do you have a stack trace?

Here you can find a stack trace, thank you !

Hi @AndreaSerra. You need to invoke AO in the context of a transaction, otherwise there will be no session present in this case.

Some Confluence requests always get a session, some don’t. You can tell the ones that do by the presence of OpenSessionIvViewFilter in the stack trace.

If you use com.atlassian.sal.api.transaction.TransactionTemplate to wrap your operation in a transaction, you make guard yourself against either code path.

Thank you @kmacleod, are you referring to this documentation ?

Our service is already using the @Transactional annotation. It was working fine by declaring them in atlassian-plugin.xml via <component> and <component-import> elements

<component key="tx-processor" name="Transactional Annotation Processor"
			   class="com.atlassian.activeobjects.external.TransactionalAnnotationProcessor">
		<decription>Processes @Transactional annotations.</decription>
</component>
<component-import key="ao" name="Active Objects service" interface="com.atlassian.activeobjects.external.ActiveObjects">
		<description>Component to access Active Objects functionality from the plugin</description>
</component-import>

@Transactional
public interface BasService {
....
    BasSession findSession(String token);
....
}
public class BasServiceImpl implements BasService
{
 private final ActiveObjects _ao;
    @Autowired
    public BasServiceImpl(ActiveObjects ao, ....)
    {
        _ao = checkNotNull(ao);
    }
...
    public BasSession findSession(String token)
    {
        final BasSession[] basSession;
        BasSession ret = null;

        basSession = _ao.find(BasSession.class, "TOKEN = ?", token);

        return ret;
    }
...

But when we switched to Spring Java Configuration it stopped to work.

How we need to change this part ?