summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-01-20 14:54:41 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-01-20 14:56:48 +0100
commit5b9bb972f4f57a6e424b9ae64e2d9836bf3d4ed0 (patch)
treef39059c893814abb4a1cf9b2fd5c61ef35cae167 /sonar-server
parentc326464e88a2c7486d47fefa5375678b9a653401 (diff)
downloadsonarqube-5b9bb972f4f57a6e424b9ae64e2d9836bf3d4ed0.tar.gz
sonarqube-5b9bb972f4f57a6e424b9ae64e2d9836bf3d4ed0.zip
SONAR-5010 allow Java web services to use an existing ruby controller
Example : Ruby /api/rules/index should still work if Java /api/rules/search is defined
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/config/routes.rb1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/lib/java_ws_routing.rb6
3 files changed, 16 insertions, 3 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
index 6c60ff70a8e..474e68c2dfe 100644
--- a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
@@ -22,7 +22,6 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'api/resoures', :controller => 'api/resources', :action => 'index'
map.connect 'api/sources', :controller => 'api/sources', :action => 'index'
- map.resources 'rules', :path_prefix => 'api', :controller => 'api/rules'
map.resources 'properties', :path_prefix => 'api', :controller => 'api/properties', :requirements => { :id => /.*/ }
# home page
diff --git a/sonar-server/src/main/webapp/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb b/sonar-server/src/main/webapp/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb
index 2fbf3e9edd0..95d36b88fc7 100644
--- a/sonar-server/src/main/webapp/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb
@@ -312,6 +312,18 @@ module ActionController
route
end
+ #sonar
+ # Used to declare new routes that should have greater priority than existing ones
+ # -> Java web services take precedence over Ruby on Rails web services
+ # -> for example Java /api/rules/search must not disable Ruby /api/rules/index
+ def prepend_route(path, options = {})
+ options.each { |k, v| options[k] = v.to_s if [:controller, :action].include?(k) && v.is_a?(Symbol) }
+ route = builder.build(path, options)
+ routes.insert(0, route)
+ route
+ end
+ #/sonar
+
def add_named_route(name, path, options = {})
# TODO - is options EVER used?
name = options[:name_prefix] + name.to_s if options[:name_prefix]
diff --git a/sonar-server/src/main/webapp/WEB-INF/lib/java_ws_routing.rb b/sonar-server/src/main/webapp/WEB-INF/lib/java_ws_routing.rb
index 3095361c0a0..0771001f270 100644
--- a/sonar-server/src/main/webapp/WEB-INF/lib/java_ws_routing.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/lib/java_ws_routing.rb
@@ -26,13 +26,15 @@ module ActionController
deprecated_web_services = Java::OrgSonarServerUi::JRubyFacade.new.getRubyRailsWebservices()
deprecated_web_services.each do |ws|
eval(ws.getTemplate())
- add_route("api/plugins/#{ws.getId()}/:action/:id", {:controller => "api/#{ws.getId()}", :requirements => { :id => /.*/ }})
+ prepend_route("api/plugins/#{ws.getId()}/:action/:id", {:controller => "api/#{ws.getId()}", :requirements => { :id => /.*/ }})
end
# Full Java web services
ws_engine = Java::OrgSonarServerPlatform::Platform.component(Java::OrgSonarServerWs::WebServiceEngine.java_class)
ws_engine.controllers().each do |controller|
- add_route("#{controller.path()}/:wsaction/:id", {:controller => 'api/java_ws', :action => 'index', :wspath => controller.path()})
+ controller.actions.each do |action|
+ prepend_route("#{controller.path()}/#{action.key()}/:id", {:controller => 'api/java_ws', :action => 'index', :wsaction => action.key(), :wspath => controller.path()})
+ end
end
end
end