Persist jobs that use pluginsetting configs with servlet


#1

Hi,

We are working on an automerge plugin and it uses a servlet module to create configuration settings. These are started on creation. The problem we are running into is that servlets are not started on plugin install. We would like to persist these jobs when we reinstall. The only way I’ve found so far is to create a new module type that does this for us but I was wondering if there is a better way that I have not found in the documentation yet.

Thanks much.


#2

Can you explain how you’re creating the settings on creation? And what do you mean with the servlet not starting on plugin installation?


#3

I just mean the httpservlet isn’t initialized on plugin install. I’ll redefine my question. How do I implement StateAware inside of an HttpServlet? I need to use enabled() and disabled().


#4

Okay, what I’ve gathered is that module descriptors include enabled() and disabled() so the only way to do what I want is to extend ServletModuleDescriptor in a new class and create a module type factory for a new servlet module type.


#5

@ModuleType(ListableModuleDescriptorFactory.class)
@Component
public class MyServletModuleTypeFactory extends SingleModuleDescriptorFactory<MyServletModuleDescriptor> {
    @Autowired
    public MyServletModuleTypeFactory(final HostContainer hostContainer) {
        super(hostContainer, "my-servlet", MyServletModuleDescriptor.class);
    }
}

public class MyServletModuleDescriptor extends ServletModuleDescriptor {

    public MyServletModuleDescriptor(final @ComponentImport ModuleFactory moduleFactory, final @ComponentImport ServletModuleManager servletModuleManager)
    {
        super(moduleFactory, servletModuleManager);
    }

    @Override
    public void enabled()
    {
        super.enabled();
    }

    @Override
    public void disabled()
    {
        super.disabled();
    }

}

When I run this code it is scanned but I keep receiving:

[INFO] 2018-12-09 19:36:06,585 ERROR [spring-startup]  c.a.plugin.osgi.factory.OsgiPlugin Plugin '*************' never resolved service '&moduleFactory' with filter '(&(objectClass=com.atlassian.plugin.module.ModuleFactory)(objectClass=com.atlassian.plugin.module.ModuleFactory))'
[INFO] 2018-12-09 19:36:06,585 ERROR [spring-startup]  c.a.plugin.osgi.factory.OsgiPlugin Plugin '*************' never resolved service '&servletModuleManager' with filter '(&(objectClass=com.atlassian.plugin.servlet.ServletModuleManager)(objectClass=com.atlassian.plugin.servlet.ServletModuleManager))'

Seems pretty odd.


#6

Figured out what was happening.

        <dependency>
            <groupId>com.atlassian.inject</groupId>
            <artifactId>atlassian-inject</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>

If there are any other solutions that would be better than what I have shown here then I am open to hear them.