You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/07/30 16:45:54 UTC

[1/4] git commit: CAMEL-7354: Rest DSL. Add property to runtime routes if they are from rest.

Repository: camel
Updated Branches:
  refs/heads/master f22e5d16f -> 7db64fcd7


CAMEL-7354: Rest DSL. Add property to runtime routes if they are from rest.


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

Branch: refs/heads/master
Commit: a22461a8c54d0fe2637eec34746f1aac13a2d4b3
Parents: f22e5d1
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 15:25:00 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 15:25:00 2014 +0200

----------------------------------------------------------------------
 camel-core/src/main/java/org/apache/camel/Route.java            | 1 +
 .../main/java/org/apache/camel/impl/DefaultRouteContext.java    | 5 +++++
 2 files changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a22461a8/camel-core/src/main/java/org/apache/camel/Route.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Route.java b/camel-core/src/main/java/org/apache/camel/Route.java
index dca4660..53e4c1d 100644
--- a/camel-core/src/main/java/org/apache/camel/Route.java
+++ b/camel-core/src/main/java/org/apache/camel/Route.java
@@ -35,6 +35,7 @@ public interface Route {
     String ID_PROPERTY = "id";
     String PARENT_PROPERTY = "parent";
     String GROUP_PROPERTY = "group";
+    String REST_PROPERTY = "rest";
 
     /**
      * Gets the route id

http://git-wip-us.apache.org/repos/asf/camel/blob/a22461a8/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
index 8029189..a4a5e51 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
@@ -192,6 +192,11 @@ public class DefaultRouteContext implements RouteContext {
             if (route.getGroup() != null) {
                 edcr.getProperties().put(Route.GROUP_PROPERTY, route.getGroup());
             }
+            String rest = "false";
+            if (route.isRest() != null && route.isRest()) {
+                rest = "true";
+            }
+            edcr.getProperties().put(Route.REST_PROPERTY, rest);
 
             // after the route is created then set the route on the policy processor so we get hold of it
             CamelInternalProcessor.RoutePolicyAdvice task = internal.getAdvice(CamelInternalProcessor.RoutePolicyAdvice.class);


[4/4] git commit: CAMEL-7649: camel-jms - The QueueBrowseStrategy need support for JMS Selector

Posted by da...@apache.org.
CAMEL-7649: camel-jms - The QueueBrowseStrategy need support for JMS Selector


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

Branch: refs/heads/master
Commit: 7db64fcd7446abf928b58150ae1b4e51e8955cbc
Parents: e30fd9f
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 16:43:16 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 16:43:16 2014 +0200

----------------------------------------------------------------------
 .../jms/DefaultQueueBrowseStrategy.java         | 23 ++++++++++++++++++++
 .../camel/component/jms/JmsQueueEndpoint.java   |  6 ++++-
 .../component/jms/QueueBrowseStrategy.java      |  2 ++
 .../camel/component/jms/JmsSelectorInTest.java  |  6 ++++-
 4 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7db64fcd/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java
index e337e4f..f5cb164 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java
@@ -57,4 +57,27 @@ public class DefaultQueueBrowseStrategy implements QueueBrowseStrategy {
             }
         });
     }
+
+    @Override
+    public List<Exchange> browseSelected(final String selector, final JmsOperations template, final String queue, final JmsQueueEndpoint endpoint) {
+        return template.browseSelected(queue, selector, new BrowserCallback<List<Exchange>>() {
+            public List<Exchange> doInJms(Session session, QueueBrowser browser) throws JMSException {
+                int size = endpoint.getMaximumBrowseSize();
+                if (size <= 0) {
+                    size = Integer.MAX_VALUE;
+                }
+
+                // not the best implementation in the world as we have to browse
+                // the entire queue, which could be massive
+                List<Exchange> answer = new ArrayList<Exchange>();
+                Enumeration<?> iter = browser.getEnumeration();
+                for (int i = 0; i < size && iter.hasMoreElements(); i++) {
+                    Message message = (Message) iter.nextElement();
+                    Exchange exchange = endpoint.createExchange(message);
+                    answer.add(exchange);
+                }
+                return answer;
+            }
+        });
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7db64fcd/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
index cafc1c1..e71c577 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
@@ -95,7 +95,11 @@ public class JmsQueueEndpoint extends JmsEndpoint implements BrowsableEndpoint {
         }
         String queue = getDestinationName();
         JmsOperations template = getConfiguration().createInOnlyTemplate(this, false, queue);
-        return queueBrowseStrategy.browse(template, queue, this);
+        if (getSelector() != null) {
+            return queueBrowseStrategy.browseSelected(getSelector(), template, queue, this);
+        } else {
+            return queueBrowseStrategy.browse(template, queue, this);
+        }
     }
 
     @ManagedOperation(description = "Current number of Exchanges in Queue")

http://git-wip-us.apache.org/repos/asf/camel/blob/7db64fcd/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java
index d973206..44727a2 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java
@@ -28,4 +28,6 @@ public interface QueueBrowseStrategy {
 
     List<Exchange> browse(JmsOperations template, String queue, JmsQueueEndpoint endpoint);
 
+    List<Exchange> browseSelected(String selector, JmsOperations template, String queue, JmsQueueEndpoint endpoint);
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7db64fcd/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java
index 183cc57..00f3482 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java
@@ -41,6 +41,10 @@ public class JmsSelectorInTest extends CamelTestSupport {
         template.sendBodyAndHeader("activemq:queue:foo", "Santa Rita", "drink", "wine");
 
         mock.assertIsSatisfied();
+
+        // and there should also only be 2 if browsing as the selector was configured in the route builder
+        JmsQueueEndpoint endpoint = context.getEndpoint("activemq:queue:foo", JmsQueueEndpoint.class);
+        assertEquals(2, endpoint.getExchanges().size());
     }
 
     protected CamelContext createCamelContext() throws Exception {
@@ -58,7 +62,7 @@ public class JmsSelectorInTest extends CamelTestSupport {
                 JmsEndpoint endpoint = context.getEndpoint("activemq:queue:foo", JmsEndpoint.class);
                 endpoint.setSelector("drink IN ('beer', 'wine')");
 
-                from(endpoint).to("mock:result");
+                from(endpoint).to("log:drink").to("mock:result");
             }
         };
     }


[2/4] git commit: CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.

Posted by da...@apache.org.
CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.


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

Branch: refs/heads/master
Commit: 93ae72f608f67cd95508c15942f69eddfb5487cf
Parents: a22461a
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 16:16:07 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 16:16:07 2014 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     |  13 ++-
 .../management/mbean/CamelOpenMBeanTypes.java   |  12 +++
 .../mbean/ManagedRestRegistryMBean.java         |  32 ++++++
 .../camel/component/rest/RestEndpoint.java      |   4 +
 .../apache/camel/impl/DefaultCamelContext.java  |  11 ++
 .../apache/camel/impl/DefaultRestRegistry.java  | 106 +++++++++++++++++++
 .../DefaultManagementLifecycleStrategy.java     |   4 +
 .../management/mbean/ManagedRestRegistry.java   |  76 +++++++++++++
 .../java/org/apache/camel/spi/RestRegistry.java |  54 ++++++++++
 9 files changed, 311 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 25e1239..5297031 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -52,6 +52,7 @@ import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.ProcessorFactory;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.RestConfiguration;
+import org.apache.camel.spi.RestRegistry;
 import org.apache.camel.spi.RouteStartupOrder;
 import org.apache.camel.spi.RuntimeEndpointRegistry;
 import org.apache.camel.spi.ServicePool;
@@ -1357,4 +1358,14 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
      */
     void setRuntimeEndpointRegistry(RuntimeEndpointRegistry runtimeEndpointRegistry);
 
-}
+    /**
+     * Gets the {@link org.apache.camel.spi.RestRegistry} to use
+     */
+    public RestRegistry getRestRegistry();
+
+    /**
+     * Sets a custom {@link org.apache.camel.spi.RestRegistry} to use.
+     */
+    public void setRestRegistry(RestRegistry restRegistry);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
index 6cbdb30..d5736bc 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
@@ -39,4 +39,16 @@ public final class CamelOpenMBeanTypes {
         return new CompositeType("types", "From/To types", new String[]{"from", "to"},
                 new String[]{"From type", "To type"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING});
     }
+
+    public static TabularType listRestServicesTabularType() throws OpenDataException {
+        CompositeType ct = listRestServicesCompositeType();
+        return new TabularType("listRestServices", "Lists all the rest services in the registry", ct, new String[]{"url", "path", "verb", "consumes", "produces"});
+    }
+
+    public static CompositeType listRestServicesCompositeType() throws OpenDataException {
+        return new CompositeType("types", "types", new String[]{"url", "path", "verb", "consumes", "produces"},
+                new String[]{"Url", "Path", "Verb", "Consumes", "Produces"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRestRegistryMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRestRegistryMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRestRegistryMBean.java
new file mode 100644
index 0000000..804d294
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRestRegistryMBean.java
@@ -0,0 +1,32 @@
+/**
+ * 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.api.management.mbean;
+
+import javax.management.openmbean.TabularData;
+
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedOperation;
+
+public interface ManagedRestRegistryMBean extends ManagedServiceMBean {
+
+    @ManagedAttribute(description = "Number of rest services in the registry")
+    int getNumberOfRestServices();
+
+    @ManagedOperation(description = "Lists all the Rest services in the registry (url, path, verb, consumes, produces)")
+    TabularData listRestServices();
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index 1d9195d..10d366c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -153,6 +153,10 @@ public class RestEndpoint extends DefaultEndpoint {
         if (factory != null) {
             Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getConsumes(), getProduces(), getParameters());
             configureConsumer(consumer);
+
+            // add to rest registry so we can keep track of them, we will remove from the registry when the consumer is removed
+            getCamelContext().getRestRegistry().addRestService(consumer, null, getPath(), getVerb(), getConsumes(), getProduces());
+
             return consumer;
         } else {
             throw new IllegalStateException("Cannot find RestConsumerFactory in Registry or as a Component to use");

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 15987fc..fa4d673 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -116,6 +116,7 @@ import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.ProcessorFactory;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.RestConfiguration;
+import org.apache.camel.spi.RestRegistry;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.RouteStartupOrder;
 import org.apache.camel.spi.RuntimeEndpointRegistry;
@@ -175,6 +176,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
     private final List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
     private final List<RestDefinition> restDefinitions = new ArrayList<RestDefinition>();
     private RestConfiguration restConfiguration = new RestConfiguration();
+    private RestRegistry restRegistry = new DefaultRestRegistry();
     private List<InterceptStrategy> interceptStrategies = new ArrayList<InterceptStrategy>();
 
     // special flags to control the first startup which can are special
@@ -1834,6 +1836,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         addService(inflightRepository);
         addService(shutdownStrategy);
         addService(packageScanClassResolver);
+        addService(restRegistry);
 
         if (runtimeEndpointRegistry != null) {
             if (runtimeEndpointRegistry instanceof EventNotifier) {
@@ -2888,6 +2891,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         this.streamCachingStrategy = streamCachingStrategy;
     }
 
+    public RestRegistry getRestRegistry() {
+        return restRegistry;
+    }
+
+    public void setRestRegistry(RestRegistry restRegistry) {
+        this.restRegistry = restRegistry;
+    }
+
     @Override
     public String getProperty(String name) {
         String value = getProperties().get(name);

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
new file mode 100644
index 0000000..612e9ed
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
@@ -0,0 +1,106 @@
+/**
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.StaticService;
+import org.apache.camel.spi.RestRegistry;
+
+public class DefaultRestRegistry extends ServiceSupport implements StaticService, RestRegistry {
+
+    private final Map<Consumer, RestService> registry = new LinkedHashMap<Consumer, RestService>();
+
+    public void addRestService(Consumer consumer, String url, String path, String verb, String consumes, String produces) {
+        RestServiceEntry entry = new RestServiceEntry(consumer, url, path, verb, consumes, produces);
+        registry.put(consumer, entry);
+    }
+
+    public void removeRestService(Consumer consumer) {
+        registry.remove(consumer);
+    }
+
+    @Override
+    public List<RestRegistry.RestService> listAllRestServices() {
+        return new ArrayList<RestService>(registry.values());
+    }
+
+    @Override
+    public int size() {
+        return registry.size();
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        registry.clear();
+    }
+
+    /**
+     * Represents a rest service
+     */
+    private final class RestServiceEntry implements RestService {
+
+        private final Consumer consumer;
+        private final String url;
+        private final String path;
+        private final String verb;
+        private final String consumes;
+        private final String produces;
+
+        private RestServiceEntry(Consumer consumer, String url, String path, String verb, String consumes, String produces) {
+            this.consumer = consumer;
+            this.url = url;
+            this.path = path;
+            this.verb = verb;
+            this.consumes = consumes;
+            this.produces = produces;
+        }
+
+        public Consumer getConsumer() {
+            return consumer;
+        }
+
+        public String getUrl() {
+            return url;
+        }
+
+        public String getPath() {
+            return path;
+        }
+
+        public String getVerb() {
+            return verb;
+        }
+
+        public String getConsumes() {
+            return consumes;
+        }
+
+        public String getProduces() {
+            return produces;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
index 223a987..7eb1452 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
@@ -58,6 +58,7 @@ import org.apache.camel.management.mbean.ManagedConsumerCache;
 import org.apache.camel.management.mbean.ManagedEndpoint;
 import org.apache.camel.management.mbean.ManagedEndpointRegistry;
 import org.apache.camel.management.mbean.ManagedProducerCache;
+import org.apache.camel.management.mbean.ManagedRestRegistry;
 import org.apache.camel.management.mbean.ManagedRoute;
 import org.apache.camel.management.mbean.ManagedRuntimeEndpointRegistry;
 import org.apache.camel.management.mbean.ManagedService;
@@ -84,6 +85,7 @@ import org.apache.camel.spi.ManagementAware;
 import org.apache.camel.spi.ManagementNameStrategy;
 import org.apache.camel.spi.ManagementObjectStrategy;
 import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.spi.RestRegistry;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.RuntimeEndpointRegistry;
 import org.apache.camel.spi.StreamCachingStrategy;
@@ -462,6 +464,8 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport implement
             answer = new ManagedEndpointRegistry(context, (EndpointRegistry) service);
         } else if (service instanceof TypeConverterRegistry) {
             answer = new ManagedTypeConverterRegistry(context, (TypeConverterRegistry) service);
+        } else if (service instanceof RestRegistry) {
+            answer = new ManagedRestRegistry(context, (RestRegistry) service);
         } else if (service instanceof RuntimeEndpointRegistry) {
             answer = new ManagedRuntimeEndpointRegistry(context, (RuntimeEndpointRegistry) service);
         } else if (service instanceof StreamCachingStrategy) {

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
new file mode 100644
index 0000000..99bf3f5
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
@@ -0,0 +1,76 @@
+/**
+ * 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.mbean;
+
+import java.util.List;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes;
+import org.apache.camel.api.management.mbean.ManagedRestRegistryMBean;
+import org.apache.camel.spi.RestRegistry;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ *
+ */
+@ManagedResource(description = "Managed RestRegistry")
+public class ManagedRestRegistry extends ManagedService implements ManagedRestRegistryMBean {
+
+    private final RestRegistry registry;
+
+    public ManagedRestRegistry(CamelContext context, RestRegistry registry) {
+        super(context, registry);
+        this.registry = registry;
+    }
+
+    public RestRegistry getRegistry() {
+        return registry;
+    }
+
+    @Override
+    public int getNumberOfRestServices() {
+        return registry.size();
+    }
+
+    @Override
+    public TabularData listRestServices() {
+        try {
+            TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listRestServicesTabularType());
+            List<RestRegistry.RestService> services = registry.listAllRestServices();
+            for (RestRegistry.RestService entry : services) {
+                CompositeType ct = CamelOpenMBeanTypes.listRestServicesCompositeType();
+                String url = entry.getUrl();
+                String path = entry.getPath();
+                String verb = entry.getVerb();
+                String consumes = entry.getConsumes();
+                String produces = entry.getProduces();
+                CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "path", "verb", "consumes", "produces"},
+                        new Object[]{url, path, verb, consumes, produces});
+                answer.put(data);
+            }
+            return answer;
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/93ae72f6/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
new file mode 100644
index 0000000..3509b6d
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
@@ -0,0 +1,54 @@
+/**
+ * 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.spi;
+
+import java.util.List;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Service;
+
+public interface RestRegistry extends Service {
+
+    interface RestService {
+
+        Consumer getConsumer();
+
+        String getUrl();
+
+        String getPath();
+
+        String getVerb();
+
+        String getConsumes();
+
+        String getProduces();
+    }
+
+    void addRestService(Consumer consumer, String url, String path, String verb, String consumes, String produces);
+
+    void removeRestService(Consumer consumer);
+
+    List<RestService> listAllRestServices();
+
+    /**
+     * Number of rest services in the registry.
+     *
+     * @return number of rest services in the registry.
+     */
+    int size();
+
+}


[3/4] git commit: CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.

Posted by da...@apache.org.
CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.


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

Branch: refs/heads/master
Commit: e30fd9f5717511e531edfb4660d619b5c46f62e7
Parents: 93ae72f
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 30 16:22:14 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 30 16:22:14 2014 +0200

----------------------------------------------------------------------
 .../api/management/mbean/CamelOpenMBeanTypes.java    |  7 ++++---
 .../org/apache/camel/impl/DefaultRestRegistry.java   | 15 +++++++++++++++
 .../camel/management/mbean/ManagedRestRegistry.java  |  5 +++--
 .../main/java/org/apache/camel/spi/RestRegistry.java |  2 ++
 4 files changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e30fd9f5/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
index d5736bc..6ef4b81 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
@@ -42,12 +42,13 @@ public final class CamelOpenMBeanTypes {
 
     public static TabularType listRestServicesTabularType() throws OpenDataException {
         CompositeType ct = listRestServicesCompositeType();
-        return new TabularType("listRestServices", "Lists all the rest services in the registry", ct, new String[]{"url", "path", "verb", "consumes", "produces"});
+        return new TabularType("listRestServices", "Lists all the rest services in the registry", ct, new String[]{"url", "path", "verb", "consumes", "produces", "state"});
     }
 
     public static CompositeType listRestServicesCompositeType() throws OpenDataException {
-        return new CompositeType("types", "types", new String[]{"url", "path", "verb", "consumes", "produces"},
-                new String[]{"Url", "Path", "Verb", "Consumes", "Produces"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
+        return new CompositeType("types", "types", new String[]{"url", "path", "verb", "consumes", "produces", "state"},
+                new String[]{"Url", "Path", "Verb", "Consumes", "Produces", "State"},
+                new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
     }
 
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e30fd9f5/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
index 612e9ed..6d8ea81 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
@@ -22,6 +22,8 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.Consumer;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.StatefulService;
 import org.apache.camel.StaticService;
 import org.apache.camel.spi.RestRegistry;
 
@@ -102,5 +104,18 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService
         public String getProduces() {
             return produces;
         }
+
+        public String getState() {
+            // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
+            ServiceStatus status = null;
+            if (consumer instanceof StatefulService) {
+                status = ((StatefulService) consumer).getStatus();
+            }
+            // if no status exists then its stopped
+            if (status == null) {
+                status = ServiceStatus.Stopped;
+            }
+            return status.name();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e30fd9f5/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
index 99bf3f5..89c3030 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
@@ -64,8 +64,9 @@ public class ManagedRestRegistry extends ManagedService implements ManagedRestRe
                 String verb = entry.getVerb();
                 String consumes = entry.getConsumes();
                 String produces = entry.getProduces();
-                CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "path", "verb", "consumes", "produces"},
-                        new Object[]{url, path, verb, consumes, produces});
+                String state = entry.getState();
+                CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "path", "verb", "consumes", "produces", "state"},
+                        new Object[]{url, path, verb, consumes, produces, state});
                 answer.put(data);
             }
             return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/e30fd9f5/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
index 3509b6d..1b0d6af 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
@@ -36,6 +36,8 @@ public interface RestRegistry extends Service {
         String getConsumes();
 
         String getProduces();
+
+        String getState();
     }
 
     void addRestService(Consumer consumer, String url, String path, String verb, String consumes, String produces);