camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [12/33] git commit: CAMEL-7354: Add jmx about rest
Date Sun, 20 Jul 2014 06:53:18 GMT
CAMEL-7354: Add jmx about rest


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2ffb9a5a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2ffb9a5a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2ffb9a5a

Branch: refs/heads/master
Commit: 2ffb9a5a43fc69fb0344ca524f465e643d337a44
Parents: 2e4e7f8
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jul 2 18:01:42 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jul 19 09:38:49 2014 +0200

----------------------------------------------------------------------
 .../mbean/ManagedCamelContextMBean.java         |  3 +
 .../org/apache/camel/builder/RouteBuilder.java  |  2 +-
 .../management/mbean/ManagedCamelContext.java   | 14 ++++
 .../org/apache/camel/model/RouteDefinition.java | 14 ++++
 .../apache/camel/model/rest/RestDefinition.java |  3 +-
 .../management/ManagedFromRestGetTest.java      | 88 ++++++++++++++++++++
 6 files changed, 122 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index 583ad01..700ae22 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -164,6 +164,9 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
     @ManagedOperation(description = "Request body and headers (in out)")
     Object requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object>
headers) throws Exception;
 
+    @ManagedOperation(description = "Dumps the rests as XML")
+    String dumpRestsAsXml() throws Exception;
+
     @ManagedOperation(description = "Dumps the routes as XML")
     String dumpRoutesAsXml() throws Exception;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 9e4e334..3659a84 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -408,7 +408,7 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
     }
 
     protected void configureRoute(RouteDefinition route) {
-        route.setGroup(getClass().getName());
+        // noop
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index e26c8aa..a641b68 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -47,6 +47,8 @@ import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.ModelHelper;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
 
 /**
  * @version 
@@ -298,6 +300,18 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements
Ti
         return answer;
     }
 
+    public String dumpRestsAsXml() throws Exception {
+        List<RestDefinition> rests = context.getRestDefinitions();
+        if (rests.isEmpty()) {
+            return null;
+        }
+
+        // use a routes definition to dump the rests
+        RestsDefinition def = new RestsDefinition();
+        def.setRests(rests);
+        return ModelHelper.dumpModelAsXml(def);
+    }
+
     public String dumpRoutesAsXml() throws Exception {
         List<RouteDefinition> routes = context.getRouteDefinitions();
         if (routes.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 05a5b5f..7f12ccf 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -80,6 +80,7 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition>
{
     // keep state whether the error handler is context scoped or not
     // (will by default be context scoped of no explicit error handler configured)
     private boolean contextScopedErrorHandler = true;
+    private Boolean rest;
 
     public RouteDefinition() {
     }
@@ -93,6 +94,14 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition>
{
     }
 
     /**
+     * This route is created from the REST DSL.
+     */
+    public void fromRest(String uri) {
+        from(uri);
+        rest = true;
+    }
+
+    /**
      * Prepares the route definition to be ready to be added to {@link CamelContext}
      *
      * @param context the camel context
@@ -765,6 +774,11 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition>
{
         this.errorHandlerBuilder = errorHandlerBuilder;
     }
 
+    @XmlAttribute
+    public Boolean isRest() {
+        return rest;
+    }
+
     @SuppressWarnings("deprecation")
     public boolean isContextScopedErrorHandler(CamelContext context) {
         if (!contextScopedErrorHandler) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index 56cc843..d63badc 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -87,7 +87,8 @@ public class RestDefinition {
             String uri = path.getUri();
             for (VerbDefinition verb : path.getVerbs()) {
                 String from = "rest-binding:" + verb.getMethod() + ":" + uri + (verb.getUri()
!= null ? verb.getUri() : "");
-                RouteDefinition route = new RouteDefinition(from);
+                RouteDefinition route = new RouteDefinition();
+                route.fromRest(from);
                 answer.add(route);
                 route.getOutputs().add(verb.getTo());
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
new file mode 100644
index 0000000..f70d372
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.restbinding.DummyRestBindingCapableComponent;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+public class ManagedFromRestGetTest extends ManagementTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        // register our dummy rest capable component
+        context.addComponent("dummy-rest", new DummyRestBindingCapableComponent());
+
+        return context;
+    }
+
+    public void testFromRestModel() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
+
+        String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", null, null);
+        assertNotNull(xml);
+        log.info(xml);
+
+        assertTrue(xml.contains("rests"));
+        assertTrue(xml.contains("rest"));
+        assertTrue(xml.contains("<path uri=\"/say\">"));
+        assertTrue(xml.contains("<get method=\"get\" uri=\"/hello\">"));
+        assertTrue(xml.contains("<get method=\"get\" uri=\"/bye\">"));
+        assertTrue(xml.contains("<post method=\"post\">"));
+
+        String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
+        log.info(xml2);
+        // and we should have rest in the routes that indicate its from a rest dsl
+        assertTrue(xml2.contains("rest=\"true\""));
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                rest()
+                    .path("/say")
+                        .get("/hello").to("direct:hello")
+                        .get("/bye").to("direct:bye")
+                        .post().to("seda:update");
+
+                from("direct:hello")
+                    .transform().constant("Hello World");
+
+                from("direct:bye")
+                    .transform().constant("Bye World");
+            }
+        };
+    }
+}


Mime
View raw message