It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get serverID inside servlet module Edited

Luís Gomes Apr 10, 2018

Hello guys, I need some help.

I'm developing a confluence server plugin and I need to get the confluence server id when the servlet url is hit. I haven't figured out yet how to do it. Is there any way to do that?

Thanks in advance,

Luís

1 answer

1 accepted

0 votes
Answer accepted
Thor Weinreich Apr 10, 2018

Hi there,

You could try it with the ConfluenceInfo bean.

Luís Gomes Apr 10, 2018

Thanks for your help.

I tried with no luck. 

I tried this:

I18NBean a = null;
ConfluenceInfo ci = new ConfluenceInfo(a);
String serverID = ci.getServerId();
// serverID is null

However, all ci methods are returning null.


Any idea?

Thor Weinreich Apr 11, 2018

Hey @Luís Gomes,

I had the chance to unsuccessfully try this myself. But I figured out a way that works for me:

  • Create a field in your class with type of ConfluenceSidManager:
    private ConfluenceSidManager sidManager;
  • Inject the manager into your constructor or write a setter for it
  • Now you can get the server id like this:
    sidManager.getSid()

Hope that works for you as well.

Kind Regards

Luís Gomes Apr 12, 2018

Hey @Thor Weinreich, I've tried it but with no luck :\

How do you inject the ConfluenceSidManager into your class constructor? Or how do you call the class constructor then?

If could share a code snippet of what you described working, that would be really amazing.

Thanks again.

Kind regards

Thor Weinreich Apr 13, 2018

Hey @Luís Gomes,

Here is a good article about dependcy injection in plugins.

 

To inject it into your constructor (preferred way for v2 plugins) do this:

private ConfluenceSidManager sidManager;
...
...

public MyClass(ConfluenceSidManager sidManager) {

    this.sidManager = sidManager;

}

 

To inject the manager via a setter (the default way to do this for v1 plugins) do this:

private ConfluenceSidManager sidManager;
...
...

public
void setSidManager(ConfluenceSidManager sidManager) {
this.sidManager = sidManager;
}
...

Then you have to call the setter (e.g. if you are writing a macro inside the execute method):


setSidManager(ComponentLocator.getComponent(ConfluenceSidManager.class));

From now on you should be able to use the manager.

Luís Gomes May 04, 2018

Thanks @Thor Weinreich! That solved the problem :)

Thor Weinreich May 04, 2018

Hey @Luís Gomes, you're welcome! I'm happy to hear that :-)

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

939 views 0 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you