brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [4/7] brooklyn-server git commit: Fix injection of management context into CXF resources
Date Tue, 08 Mar 2016 15:53:22 GMT
Fix injection of management context into CXF resources


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/563537e2
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/563537e2
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/563537e2

Branch: refs/heads/master
Commit: 563537e278d82c247fdd1ab954ed1bd5bff2f747
Parents: 0afb2c9
Author: Ciprian Ciubotariu <cheepeero@gmx.net>
Authored: Tue Feb 16 02:10:24 2016 +0200
Committer: Ciprian Ciubotariu <cheepeero@gmx.net>
Committed: Mon Feb 29 20:12:39 2016 +0200

----------------------------------------------------------------------
 .../org/apache/brooklyn/rest/RestApiSetup.java  | 26 +++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/563537e2/rest/rest-server/src/main/java/org/apache/brooklyn/rest/RestApiSetup.java
----------------------------------------------------------------------
diff --git a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/RestApiSetup.java b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/RestApiSetup.java
index d868a77..c38fe2f 100644
--- a/rest/rest-server/src/main/java/org/apache/brooklyn/rest/RestApiSetup.java
+++ b/rest/rest-server/src/main/java/org/apache/brooklyn/rest/RestApiSetup.java
@@ -34,6 +34,9 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
 
 import io.swagger.config.ScannerFactory;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.core.mgmt.ManagementContextInjectable;
+import org.apache.brooklyn.rest.util.ManagementContextProvider;
 
 public class RestApiSetup {
 
@@ -44,6 +47,12 @@ public class RestApiSetup {
         for (Object o : providers) {
             app.singleton(o);
         }
+
+        ManagementContext managementContext = extractManagementContext(providers);
+        for (Object o : app.getSingletons()) {
+            injectManagementContext(managementContext, o);
+        }
+
         CXFNonSpringJaxrsServlet servlet = new CXFNonSpringJaxrsServlet(app);
         servlet.setBus(BusFactory.newInstance().createBus());
         servlet.getBus().getInInterceptors().add(new GZIPInInterceptor());
@@ -54,6 +63,21 @@ public class RestApiSetup {
         context.addServlet(servletHolder, "/v1/*");
     }
 
+    private static void injectManagementContext(ManagementContext managementContext, Object
o) {
+        if (managementContext != null && o instanceof ManagementContextInjectable)
{
+            ((ManagementContextInjectable) o).setManagementContext(managementContext);
+        }
+    }
+
+    private static ManagementContext extractManagementContext(Object... providers) {
+        for (Object o : providers) {
+            if (o instanceof ManagementContextProvider) {
+                return ((ManagementContextProvider) o).getContext(ManagementContext.class);
+            }
+        }
+        return null;
+    }
+
     @SafeVarargs
     public static void installServletFilters(ServletContextHandler context, Class<? extends
Filter>... filters) {
         installServletFilters(context, Arrays.asList(filters));
@@ -64,7 +88,7 @@ public class RestApiSetup {
             context.addFilter(filter, "/*", EnumSet.allOf(DispatcherType.class));
         }
     }
-    
+
     public static void initSwagger() {
         ScannerFactory.setScanner(new RestApiResourceScanner());
     }


Mime
View raw message