How to get sonar host url in post job class and inside webservice class

449 views
Skip to first unread message

Thanuku Krishna Chaitanya

unread,
Apr 7, 2016, 3:46:21 AM4/7/16
to SonarQube
I have a plugin which has a post job class and a web service.

In both the classes i want to get the sonar server url. How do i do that?

I tried using sonar.web.host and sonar.host.url. Both did not work.

Can anyone please help me

Simon Brandhof

unread,
Apr 7, 2016, 4:02:56 AM4/7/16
to Thanuku Krishna Chaitanya, SonarQube
Hi,

You should inject the component org.sonar.api.platform.Server into your class and then call the method getURL().

Regards

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/98d8a474-30d3-4d28-9a08-04857c9be78f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Simon BRANDHOF | SonarSource
Tech Lead & Co-Founder
http://twitter.com/SimonBrandhof

Thanuku Krishna Chaitanya

unread,
Apr 7, 2016, 6:12:58 AM4/7/16
to SonarQube
Hi Simon,

That worked like a charm in my post job class. However getURL returned null in the web service class.

I used constructor injection. How do i get the url in the webservice class?

Thanuku Krishna Chaitanya

unread,
Apr 7, 2016, 9:38:53 AM4/7/16
to SonarQube
Hi Simon,

How can i get the server url inside the webservice?

I injected Server using constructor injection byt getURL is returning null

Simon Brandhof

unread,
Apr 7, 2016, 9:54:39 AM4/7/16
to Thanuku Krishna Chaitanya, SonarQube

That worked like a charm in my post job class. However getURL returned null in the web service class.

Good catch. That will be fixed for server extensions in 5.6 : https://jira.sonarsource.com/browse/SONAR-7534 

I used constructor injection. How do i get the url in the webservice class?

Meanwhile you should load the public URL from Settings (see property sonar.core.serverBaseURL that is optionally set in administration console) or "http://localhost:{port}", with {port} being defined by property sonar.web.port.

Regards 

Thanuku Krishna Chaitanya

unread,
Apr 9, 2016, 11:15:26 AM4/9/16
to SonarQube
sonar.web.host did not work. Meanwhile we decided to use system properties to set and get the URL. Thank you. Will change the code again while upgrading to 5.6.

Simon Brandhof

unread,
Apr 10, 2016, 4:10:47 PM4/10/16
to Thanuku Krishna Chaitanya, SonarQube

sonar.web.host did not work.

I didn't mention this property but sonar.web.port.
 
Meanwhile we decided to use system properties to set and get the URL. Thank you. Will change the code again  while upgrading to 5.6.

Ok, good to know.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages