How do you find port number where JIRA/apache is on?

Using scriptrunner, code below seems to find Catalina server and the port number (8080). However, if run from within a plugin on the same JIRA instance, Catalina is not found and service is null.

Any insight is appreciated. Thank you in advance.

import org.apache.catalina.Server;
import org.apache.catalina.ServerFactory;
import org.apache.catalina.Service;
import org.apache.catalina.connector.Connector;

int portNumber = 0;
Server server = ServerFactory.getServer();
try {
    Service service = server.findService("Catalina");
    // service is null if this were run from within a plugin. 
    Connector[] conn = service.findConnectors();
    portNumber = conn[0].getPort();
}
catch (NullPointerException e) {
    System.out.println(e.toString()); 
    // java.lang.NullPointerException: Cannot invoke method findConnectors() on null object
}
System.out.println(portNumber);
// 0 when run from within plugin. 8080 when run from scriptRunner.

1 answer

0 vote

Hi Danny,

I'm not very keen in the plugin coding, however if you can get the port from the file Catalina_home/conf/server.xml that should also work. The port is located inside that file and if you can reach that file then you might be able to fetch the port number from the file.

Just an idea. :)

Regards,

Rodrigo

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 19, 2018 in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

366 views 0 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you