Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CORS for SonarQube service

Tags:

cors

sonarqube

I am trying to call one of Sonar web-service through jQuery. Since the call is going across domain, the call is failing on Chrome with following error: No 'Access-Control-Allow-Origin' header is present on the requested resource. Do anyone know how to enable CORS on SonarQube server? I am using SonarQube 4.3. I even tried adding the filter in sonarqube-4.3\web\WEB-INF\web.xml but it did not help. Any help will be appreciated.

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.methods</param-name>
    <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.headers</param-name>
    <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
  </init-param>
  <init-param>
    <param-name>cors.exposed.headers</param-name>
    <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
  </init-param>
  <init-param>
    <param-name>cors.support.credentials</param-name>
    <param-value>true</param-value>
  </init-param>
  <init-param>
    <param-name>cors.preflight.maxage</param-name>
    <param-value>10</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Thanks, Sara

like image 356
user3814164 Avatar asked Oct 21 '22 05:10

user3814164


2 Answers

I have fallen on the same issue.

To get rid of this one, just set the initialization parameter resetUnhandledResponse of the RackFilter to false in the web.xml file of Sonar.

The settings of the CORS filter should then work as it should wherever you define it, at the server or at the application level.

<filter>
 <filter-name>RackFilter</filter-name>
 <filter-class>org.jruby.rack.RackFilter</filter-class>
 <init-param>
    <param-name>resetUnhandledResponse</param-name>
    <param-value>false</param-value> <!-- true (default), false or buffer -->
 </init-param>
</filter>
like image 140
Vivian Avatar answered Oct 29 '22 03:10

Vivian


For those of you who are still looking for an answer to this question, please checkout this link. The solution is to enable CORS for your catalina server that Sonarqube runs on.

like image 37
Clinkz Avatar answered Oct 29 '22 02:10

Clinkz