CAMEL-8041: Camel commands should be reusable.

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

Branch: refs/heads/master
Commit: acd55f5317f31fd1ac65ec1c5ef5f204b08aee48
Parents: 796aa09
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Nov 13 10:38:51 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Nov 13 10:38:51 2014 +0100

----------------------------------------------------------------------
 .../apache/camel/commands/RouteListCommand.java | 126 +++++++++++++++++++
 .../camel/commands/RouteProfileCommand.java     | 100 +++++++++++++++
 .../camel/commands/RouteResetStatsCommand.java  |  51 ++++++++
 .../camel/commands/RouteResumeCommand.java      |  34 +++++
 .../apache/camel/commands/RouteShowCommand.java |  40 ++++++
 .../camel/commands/RouteStartCommand.java       |  34 +++++
 .../apache/camel/commands/RouteStopCommand.java |  34 +++++
 .../camel/commands/RouteSuspendCommand.java     |  34 +++++
 .../karaf/commands/AbstractRouteCommand.java    |  64 +---------
 .../apache/camel/karaf/commands/RouteList.java  |  99 +--------------
 .../camel/karaf/commands/RouteProfile.java      |  76 ++---------
 .../camel/karaf/commands/RouteResetStats.java   |  26 +---
 .../camel/karaf/commands/RouteResume.java       |   8 +-
 .../apache/camel/karaf/commands/RouteShow.java  |  18 +--
 .../apache/camel/karaf/commands/RouteStart.java |   9 +-
 .../apache/camel/karaf/commands/RouteStop.java  |   8 +-
 .../camel/karaf/commands/RouteSuspend.java      |   8 +-
 .../OSGI-INF/blueprint/camel-commands.xml       |   1 +
 18 files changed, 490 insertions(+), 280 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
new file mode 100644
index 0000000..bf53247
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
@@ -0,0 +1,126 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Route;
+import org.apache.camel.ServiceStatus;
+
+public class RouteListCommand extends AbstractCamelCommand {
+
+    private static final String CONTEXT_COLUMN_LABEL = "Context";
+    private static final String ROUTE_COLUMN_LABEL = "Route";
+    private static final String STATUS_COLUMN_LABEL = "Status";
+
+    private static final int DEFAULT_COLUMN_WIDTH_INCREMENT = 0;
+    private static final String DEFAULT_FIELD_PREAMBLE = " ";
+    private static final String DEFAULT_FIELD_POSTAMBLE = " ";
+    private static final String DEFAULT_HEADER_PREAMBLE = " ";
+    private static final String DEFAULT_HEADER_POSTAMBLE = " ";
+    private static final int DEFAULT_FORMAT_BUFFER_LENGTH = 24;
+    private static final int MAX_COLUMN_WIDTH = Integer.MAX_VALUE;
+    private static final int MIN_COLUMN_WIDTH = 12;
+
+    String name;
+
+    public RouteListCommand(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public Object execute(CamelController camelController, PrintStream out, 
PrintStream err) throws Exception {
+        List<Route> routes = camelController.getRoutes(name);
+
+        final Map<String, Integer> columnWidths = computeColumnWidths(routes);
+        final String headerFormat = buildFormatString(columnWidths, true);
+        final String rowFormat = buildFormatString(columnWidths, false);
+
+        if (routes.size() > 0) {
+            out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, 
ROUTE_COLUMN_LABEL, STATUS_COLUMN_LABEL));
+            out.println(String.format(headerFormat, "-------", "-----", 
"------"));
+            for (Route route : routes) {
+                String contextId = 
route.getRouteContext().getCamelContext().getName();
+                String routeId = route.getId();
+                ServiceStatus status = 
route.getRouteContext().getCamelContext().getRouteStatus(routeId);
+                out.println(String.format(rowFormat, contextId, routeId, 
status));
+            }
+        }
+
+        return null;
+    }
+
+    private static Map<String, Integer> computeColumnWidths(final 
Iterable<Route> routes) throws Exception {
+        if (routes == null) {
+            throw new IllegalArgumentException("Unable to determine column 
widths from null Iterable<Route>");
+        } else {
+            int maxContextLen = 0;
+            int maxRouteLen = 0;
+            int maxStatusLen = 0;
+
+            for (final Route route : routes) {
+                final String contextId = 
route.getRouteContext().getCamelContext().getName();
+                maxContextLen = java.lang.Math.max(maxContextLen, contextId == 
null ? 0 : contextId.length());
+
+                final String routeId = route.getId();
+                maxRouteLen = java.lang.Math.max(maxRouteLen, routeId == null 
? 0 : routeId.length());
+
+                final String status = 
route.getRouteContext().getCamelContext().getRouteStatus(routeId).name();
+                maxStatusLen = java.lang.Math.max(maxStatusLen, status == null 
? 0 : status.length());
+            }
+
+            final Map<String, Integer> retval = new Hashtable<String, 
Integer>(3);
+            retval.put(CONTEXT_COLUMN_LABEL, maxContextLen);
+            retval.put(ROUTE_COLUMN_LABEL, maxRouteLen);
+            retval.put(STATUS_COLUMN_LABEL, maxStatusLen);
+
+            return retval;
+        }
+    }
+
+    private static String buildFormatString(final Map<String, Integer> 
columnWidths, final boolean isHeader) {
+        final String fieldPreamble;
+        final String fieldPostamble;
+        final int columnWidthIncrement;
+
+        if (isHeader) {
+            fieldPreamble = DEFAULT_HEADER_PREAMBLE;
+            fieldPostamble = DEFAULT_HEADER_POSTAMBLE;
+        } else {
+            fieldPreamble = DEFAULT_FIELD_PREAMBLE;
+            fieldPostamble = DEFAULT_FIELD_POSTAMBLE;
+        }
+        columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
+
+        int contextLen = Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        int routeLen = Math.min(columnWidths.get(ROUTE_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        int statusLen = Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
+        routeLen = Math.max(MIN_COLUMN_WIDTH, routeLen);
+        // last row does not have min width
+
+        final StringBuilder retval = new 
StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
+        
retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append('
 ');
+        
retval.append(fieldPreamble).append("%-").append(routeLen).append('.').append(routeLen).append('s').append(fieldPostamble).append('
 ');
+        
retval.append(fieldPreamble).append("%-").append(statusLen).append('.').append(statusLen).append('s').append(fieldPostamble).append('
 ');
+
+        return retval.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteProfileCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteProfileCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteProfileCommand.java
new file mode 100644
index 0000000..755a02f
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteProfileCommand.java
@@ -0,0 +1,100 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+import java.io.StringReader;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.spi.ManagementAgent;
+import org.apache.camel.util.ProcessorStatDump;
+import org.apache.camel.util.RouteStatDump;
+
+public class RouteProfileCommand extends AbstractRouteCommand {
+
+    protected static final String HEADER_FORMAT = "%-30s %10s %12s %12s %12s 
%12s %12s %12s %12s";
+    protected static final String OUTPUT_FORMAT = "%-30s %10d %12d %12d %12d 
%12d %12d %12d %12d";
+
+    private StringEscape stringEscape;
+    private volatile String previousCamelContextName;
+
+    public RouteProfileCommand(String route, String context) {
+        super(route, context);
+    }
+
+    /**
+     * Sets the {@link org.apache.camel.commands.StringEscape} to use.
+     */
+    public void setStringEscape(StringEscape stringEscape) {
+        this.stringEscape = stringEscape;
+    }
+
+    @Override
+    public void executeOnRoute(CamelController camelController, CamelContext 
camelContext, Route camelRoute, PrintStream out, PrintStream err) throws 
Exception {
+        JAXBContext context = JAXBContext.newInstance(RouteStatDump.class);
+        Unmarshaller unmarshaller = context.createUnmarshaller();
+
+        // write new header for new camel context
+        if (previousCamelContextName == null || 
!previousCamelContextName.equals(camelContext.getName())) {
+            System.out.println("");
+            
System.out.println(stringEscape.unescapeJava("\u001B[1mProfile\u001B[0m"));
+            System.out.println(stringEscape.unescapeJava("\tCamel Context: " + 
camelRoute.getRouteContext().getCamelContext().getName()));
+            System.out.println(String.format(HEADER_FORMAT, "Id", "Count", 
"Last (ms)", "Delta (ms)", "Mean (ms)", "Min (ms)", "Max (ms)", "Total (ms)", 
"Self (ms)"));
+        }
+
+        ManagementAgent agent = 
camelContext.getManagementStrategy().getManagementAgent();
+        if (agent != null) {
+            MBeanServer mBeanServer = agent.getMBeanServer();
+            Set<ObjectName> set = mBeanServer.queryNames(new 
ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,name=\"" + 
camelRoute.getId() + "\",*"), null);
+            for (ObjectName routeMBean : set) {
+                // the route must be part of the camel context
+                String camelId = (String) mBeanServer.getAttribute(routeMBean, 
"CamelId");
+                if (camelId != null && camelId.equals(camelContext.getName())) 
{
+
+                    String xml = (String) mBeanServer.invoke(routeMBean, 
"dumpRouteStatsAsXml", new Object[]{Boolean.FALSE, Boolean.TRUE}, new 
String[]{"boolean", "boolean"});
+                    RouteStatDump route = (RouteStatDump) 
unmarshaller.unmarshal(new StringReader(xml));
+
+                    long count = route.getExchangesCompleted() + 
route.getExchangesFailed();
+                    System.out.println(String.format(OUTPUT_FORMAT, 
route.getId(), count, route.getLastProcessingTime(), 
route.getDeltaProcessingTime(),
+                            route.getMeanProcessingTime(), 
route.getMinProcessingTime(), route.getMaxProcessingTime(), 
route.getTotalProcessingTime(), route.getSelfProcessingTime()));
+
+                    for (ProcessorStatDump ps : route.getProcessorStats()) {
+                        // the self time is the total time of the processor 
itself
+                        long selfTime = ps.getTotalProcessingTime();
+                        count = ps.getExchangesCompleted() + 
ps.getExchangesFailed();
+                        // indent route id with 2 spaces
+                        System.out.println(String.format(OUTPUT_FORMAT, "  " + 
ps.getId(), count, ps.getLastProcessingTime(), ps.getDeltaProcessingTime(),
+                                ps.getMeanProcessingTime(), 
ps.getMinProcessingTime(), ps.getMaxProcessingTime(), 
ps.getAccumulatedProcessingTime(), selfTime));
+                    }
+                }
+            }
+        } else {
+            System.out.println("");
+            System.out.println(stringEscape.unescapeJava("\u001B[31mJMX Agent 
of Camel is not reachable. Maybe it has been disabled on the Camel context"));
+            System.out.println(stringEscape.unescapeJava("In consequence, 
profile are not available.\u001B[0m"));
+        }
+
+        // we want to group routes from the same context in the same table
+        previousCamelContextName = camelContext.getName();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResetStatsCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResetStatsCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResetStatsCommand.java
new file mode 100644
index 0000000..750932e
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResetStatsCommand.java
@@ -0,0 +1,51 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.spi.ManagementAgent;
+
+public class RouteResetStatsCommand extends AbstractRouteCommand {
+
+    public RouteResetStatsCommand(String route, String context) {
+        super(route, context);
+    }
+
+    @Override
+    public void executeOnRoute(CamelController camelController, CamelContext 
camelContext, Route camelRoute, PrintStream out, PrintStream err) throws 
Exception {
+        ManagementAgent agent = 
camelContext.getManagementStrategy().getManagementAgent();
+        if (agent != null) {
+            MBeanServer mBeanServer = agent.getMBeanServer();
+
+            // reset route mbeans
+            ObjectName query = 
ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
+            Set<ObjectName> set = mBeanServer.queryNames(query, null);
+            for (ObjectName routeMBean : set) {
+                String camelId = (String) mBeanServer.getAttribute(routeMBean, 
"CamelId");
+                if (camelId != null && camelId.equals(camelContext.getName())) 
{
+                    mBeanServer.invoke(routeMBean, "reset", new 
Object[]{true}, new String[]{"boolean"});
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResumeCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResumeCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResumeCommand.java
new file mode 100644
index 0000000..2bacbb5
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteResumeCommand.java
@@ -0,0 +1,34 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+
+public class RouteResumeCommand extends AbstractRouteCommand {
+
+    public RouteResumeCommand(String route, String context) {
+        super(route, context);
+    }
+
+    @Override
+    public void executeOnRoute(CamelController camelController, CamelContext 
camelContext, Route camelRoute, PrintStream out, PrintStream err) throws 
Exception {
+        camelContext.resumeRoute(camelRoute.getId());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteShowCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteShowCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteShowCommand.java
new file mode 100644
index 0000000..9deaf60
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteShowCommand.java
@@ -0,0 +1,40 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.model.ModelHelper;
+import org.apache.camel.model.RouteDefinition;
+
+public class RouteShowCommand extends AbstractRouteCommand {
+
+    public RouteShowCommand(String route, String context) {
+        super(route, context);
+    }
+
+    @Override
+    public void executeOnRoute(CamelController camelController, CamelContext 
camelContext, Route camelRoute, PrintStream out, PrintStream err) throws 
Exception {
+        RouteDefinition routeDefinition = 
camelController.getRouteDefinition(camelRoute.getId(), 
camelRoute.getRouteContext().getCamelContext().getName());
+        if (routeDefinition == null) {
+            err.println("Definition of route " + camelRoute.getId() + " not 
found.");
+        }
+        System.out.println(ModelHelper.dumpModelAsXml(routeDefinition));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStartCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStartCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStartCommand.java
new file mode 100644
index 0000000..d814b0c
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStartCommand.java
@@ -0,0 +1,34 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+
+public class RouteStartCommand extends AbstractRouteCommand {
+
+    public RouteStartCommand(String route, String context) {
+        super(route, context);
+    }
+
+    @Override
+    public void executeOnRoute(CamelController camelController, CamelContext 
camelContext, Route camelRoute, PrintStream out, PrintStream err) throws 
Exception {
+        camelContext.startRoute(camelRoute.getId());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStopCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStopCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStopCommand.java
new file mode 100644
index 0000000..f1c00e1
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteStopCommand.java
@@ -0,0 +1,34 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+
+public class RouteStopCommand extends AbstractRouteCommand {
+
+    public RouteStopCommand(String route, String context) {
+        super(route, context);
+    }
+
+    @Override
+    public void executeOnRoute(CamelController camelController, CamelContext 
camelContext, Route camelRoute, PrintStream out, PrintStream err) throws 
Exception {
+        camelContext.stopRoute(camelRoute.getId());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteSuspendCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteSuspendCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteSuspendCommand.java
new file mode 100644
index 0000000..89c71bd
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteSuspendCommand.java
@@ -0,0 +1,34 @@
+/**
+ * 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.commands;
+
+import java.io.PrintStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+
+public class RouteSuspendCommand extends AbstractRouteCommand {
+
+    public RouteSuspendCommand(String route, String context) {
+        super(route, context);
+    }
+
+    @Override
+    public void executeOnRoute(CamelController camelController, CamelContext 
camelContext, Route camelRoute, PrintStream out, PrintStream err) throws 
Exception {
+        camelContext.suspendRoute(camelRoute.getId());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
index c2edac0..8d4b00f 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
@@ -16,76 +16,14 @@
  */
 package org.apache.camel.karaf.commands;
 
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
-import org.apache.camel.karaf.commands.internal.RegexUtil;
 import org.apache.felix.gogo.commands.Argument;
 
-import static org.apache.camel.util.CamelContextHelper.getRouteStartupOrder;
-
 public abstract class AbstractRouteCommand extends CamelCommandSupport {
+
     @Argument(index = 0, name = "route", description = "The Camel route ID or 
a wildcard expression", required = true, multiValued = false)
     String route;
 
     @Argument(index = 1, name = "context", description = "The Camel context 
name.", required = false, multiValued = false)
     String context;
 
-    public abstract void executeOnRoute(CamelContext camelContext, Route 
camelRoute) throws Exception;
-
-    public Object doExecute() throws Exception {
-        List<Route> camelRoutes = camelController.getRoutes(context, 
RegexUtil.wildcardAsRegex(route));
-        if (camelRoutes == null || camelRoutes.isEmpty()) {
-            System.err.println("Camel routes using " + route + " not found.");
-            return null;
-        }
-        // we want the routes sorted
-        Collections.sort(camelRoutes, new RouteComparator());
-
-        for (Route camelRoute : camelRoutes) {
-            CamelContext camelContext = 
camelRoute.getRouteContext().getCamelContext();
-            // Setting thread context classloader to the bundle classloader to 
enable
-            // legacy code that relies on it
-            ClassLoader oldClassloader = 
Thread.currentThread().getContextClassLoader();
-            
Thread.currentThread().setContextClassLoader(camelContext.getApplicationContextClassLoader());
-            try {
-                executeOnRoute(camelContext, camelRoute);
-            } finally {
-                Thread.currentThread().setContextClassLoader(oldClassloader);
-            }
-        }
-
-        return null;
-    }
-
-    /**
-     * To sort the routes.
-     */
-    private static final class RouteComparator implements Comparator<Route> {
-
-        @Override
-        public int compare(Route route1, Route route2) {
-            // sort by camel context first
-            CamelContext camel1 = route1.getRouteContext().getCamelContext();
-            CamelContext camel2 = route2.getRouteContext().getCamelContext();
-
-            if (camel1.getName().equals(camel2.getName())) {
-                // and then accordingly to startup order
-                Integer order1 = getRouteStartupOrder(camel1, route1.getId());
-                Integer order2 = getRouteStartupOrder(camel2, route2.getId());
-                if (order1 == 0 && order2 == 0) {
-                    // fallback and use name if not startup order was found
-                    return route1.getId().compareTo(route2.getId());
-                } else {
-                    return order1.compareTo(order2);
-                }
-            } else {
-                return camel1.getName().compareTo(camel2.getName());
-            }
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
index b1e2988..8deeb48 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
@@ -16,13 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import java.io.PrintStream;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Route;
-import org.apache.camel.ServiceStatus;
+import org.apache.camel.commands.RouteListCommand;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 
@@ -32,99 +26,12 @@ import org.apache.felix.gogo.commands.Command;
 @Command(scope = "camel", name = "route-list", description = "List Camel 
routes.")
 public class RouteList extends CamelCommandSupport {
 
-    private static final String CONTEXT_COLUMN_LABEL = "Context";
-    private static final String ROUTE_COLUMN_LABEL = "Route";
-    private static final String STATUS_COLUMN_LABEL = "Status";
-
-    private static final int DEFAULT_COLUMN_WIDTH_INCREMENT = 0;
-    private static final String DEFAULT_FIELD_PREAMBLE = " ";
-    private static final String DEFAULT_FIELD_POSTAMBLE = " ";
-    private static final String DEFAULT_HEADER_PREAMBLE = " ";
-    private static final String DEFAULT_HEADER_POSTAMBLE = " ";
-    private static final int DEFAULT_FORMAT_BUFFER_LENGTH = 24;
-    private static final int MAX_COLUMN_WIDTH = Integer.MAX_VALUE;
-    private static final int MIN_COLUMN_WIDTH = 12;
-
     @Argument(index = 0, name = "name", description = "The Camel context name 
where to look for the route", required = false, multiValued = false)
     String name;
 
     protected Object doExecute() throws Exception {
-        List<Route> routes = camelController.getRoutes(name);
-
-        final Map<String, Integer> columnWidths = computeColumnWidths(routes);
-        final String headerFormat = buildFormatString(columnWidths, true);
-        final String rowFormat = buildFormatString(columnWidths, false);
-        final PrintStream out = System.out;
-
-        if (routes.size() > 0) {
-            out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, 
ROUTE_COLUMN_LABEL, STATUS_COLUMN_LABEL));
-            out.println(String.format(headerFormat, "-------", "-----", 
"------"));
-            for (Route route : routes) {
-                String contextId = 
route.getRouteContext().getCamelContext().getName();
-                String routeId = route.getId();
-                ServiceStatus status = 
route.getRouteContext().getCamelContext().getRouteStatus(routeId);
-                out.println(String.format(rowFormat, contextId, routeId, 
status));
-            }
-        }
-
-        return null;
-    }
-
-    private static Map<String, Integer> computeColumnWidths(final 
Iterable<Route> routes) throws Exception {
-        if (routes == null) {
-            throw new IllegalArgumentException("Unable to determine column 
widths from null Iterable<Route>");
-        } else {
-            int maxContextLen = 0;
-            int maxRouteLen = 0;
-            int maxStatusLen = 0;
-
-            for (final Route route : routes) {
-                final String contextId = 
route.getRouteContext().getCamelContext().getName();
-                maxContextLen = java.lang.Math.max(maxContextLen, contextId == 
null ? 0 : contextId.length());
-
-                final String routeId = route.getId();
-                maxRouteLen = java.lang.Math.max(maxRouteLen, routeId == null 
? 0 : routeId.length());
-
-                final String status = 
route.getRouteContext().getCamelContext().getRouteStatus(routeId).name();
-                maxStatusLen = java.lang.Math.max(maxStatusLen, status == null 
? 0 : status.length());
-            }
-
-            final Map<String, Integer> retval = new Hashtable<String, 
Integer>(3);
-            retval.put(CONTEXT_COLUMN_LABEL, maxContextLen);
-            retval.put(ROUTE_COLUMN_LABEL, maxRouteLen);
-            retval.put(STATUS_COLUMN_LABEL, maxStatusLen);
-
-            return retval;
-        }
-    }
-
-    private static String buildFormatString(final Map<String, Integer> 
columnWidths, final boolean isHeader) {
-        final String fieldPreamble;
-        final String fieldPostamble;
-        final int columnWidthIncrement;
-
-        if (isHeader) {
-            fieldPreamble = DEFAULT_HEADER_PREAMBLE;
-            fieldPostamble = DEFAULT_HEADER_POSTAMBLE;
-        } else {
-            fieldPreamble = DEFAULT_FIELD_PREAMBLE;
-            fieldPostamble = DEFAULT_FIELD_POSTAMBLE;
-        }
-        columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
-
-        int contextLen = Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
-        int routeLen = Math.min(columnWidths.get(ROUTE_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
-        int statusLen = Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
-        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
-        routeLen = Math.max(MIN_COLUMN_WIDTH, routeLen);
-        // last row does not have min width
-
-        final StringBuilder retval = new 
StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
-        
retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append('
 ');
-        
retval.append(fieldPreamble).append("%-").append(routeLen).append('.').append(routeLen).append('s').append(fieldPostamble).append('
 ');
-        
retval.append(fieldPreamble).append("%-").append(statusLen).append('.').append(statusLen).append('s').append(fieldPostamble).append('
 ');
-
-        return retval.toString();
+        RouteListCommand command = new RouteListCommand(name);
+        return command.execute(camelController, System.out, System.err);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
index 98c94e4..e04a2f7 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
@@ -16,20 +16,9 @@
  */
 package org.apache.camel.karaf.commands;
 
-import java.io.StringReader;
-import java.util.Set;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Unmarshaller;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
-import org.apache.camel.spi.ManagementAgent;
-import org.apache.camel.util.ProcessorStatDump;
-import org.apache.camel.util.RouteStatDump;
+import org.apache.camel.commands.RouteProfileCommand;
+import org.apache.camel.commands.StringEscape;
 import org.apache.felix.gogo.commands.Command;
-import org.apache.karaf.util.StringEscapeUtils;
 
 /**
  * Command to display profile information about a Camel route.
@@ -37,63 +26,16 @@ import org.apache.karaf.util.StringEscapeUtils;
 @Command(scope = "camel", name = "route-profile", description = "Display 
profile information about Camel route(s).")
 public class RouteProfile extends AbstractRouteCommand {
 
-    protected static final String HEADER_FORMAT = "%-30s %10s %12s %12s %12s 
%12s %12s %12s %12s";
-    protected static final String OUTPUT_FORMAT = "%-30s %10d %12d %12d %12d 
%12d %12d %12d %12d";
-
-    private String previousCamelContextName;
+    private StringEscape stringEscape;
 
-    @Override
-    public Object doExecute() throws Exception {
-        previousCamelContextName = null; // reset state
-        return super.doExecute();
+    public void setStringEscape(StringEscape stringEscape) {
+        this.stringEscape = stringEscape;
     }
 
     @Override
-    public void executeOnRoute(CamelContext camelContext, Route camelRoute) 
throws Exception {
-        JAXBContext context = JAXBContext.newInstance(RouteStatDump.class);
-        Unmarshaller unmarshaller = context.createUnmarshaller();
-
-        // write new header for new camel context
-        if (previousCamelContextName == null || 
!previousCamelContextName.equals(camelContext.getName())) {
-            System.out.println("");
-            
System.out.println(StringEscapeUtils.unescapeJava("\u001B[1mProfile\u001B[0m"));
-            System.out.println(StringEscapeUtils.unescapeJava("\tCamel 
Context: " + camelRoute.getRouteContext().getCamelContext().getName()));
-            System.out.println(String.format(HEADER_FORMAT, "Id", "Count", 
"Last (ms)", "Delta (ms)", "Mean (ms)", "Min (ms)", "Max (ms)", "Total (ms)", 
"Self (ms)"));
-        }
-
-        ManagementAgent agent = 
camelContext.getManagementStrategy().getManagementAgent();
-        if (agent != null) {
-            MBeanServer mBeanServer = agent.getMBeanServer();
-            Set<ObjectName> set = mBeanServer.queryNames(new 
ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,name=\"" + 
camelRoute.getId() + "\",*"), null);
-            for (ObjectName routeMBean : set) {
-                // the route must be part of the camel context
-                String camelId = (String) mBeanServer.getAttribute(routeMBean, 
"CamelId");
-                if (camelId != null && camelId.equals(camelContext.getName())) 
{
-
-                    String xml = (String) mBeanServer.invoke(routeMBean, 
"dumpRouteStatsAsXml", new Object[]{Boolean.FALSE, Boolean.TRUE}, new 
String[]{"boolean", "boolean"});
-                    RouteStatDump route = (RouteStatDump) 
unmarshaller.unmarshal(new StringReader(xml));
-
-                    long count = route.getExchangesCompleted() + 
route.getExchangesFailed();
-                    System.out.println(String.format(OUTPUT_FORMAT, 
route.getId(), count, route.getLastProcessingTime(), 
route.getDeltaProcessingTime(),
-                            route.getMeanProcessingTime(), 
route.getMinProcessingTime(), route.getMaxProcessingTime(), 
route.getTotalProcessingTime(), route.getSelfProcessingTime()));
-
-                    for (ProcessorStatDump ps : route.getProcessorStats()) {
-                        // the self time is the total time of the processor 
itself
-                        long selfTime = ps.getTotalProcessingTime();
-                        count = ps.getExchangesCompleted() + 
ps.getExchangesFailed();
-                        // indent route id with 2 spaces
-                        System.out.println(String.format(OUTPUT_FORMAT, "  " + 
ps.getId(), count, ps.getLastProcessingTime(), ps.getDeltaProcessingTime(),
-                                ps.getMeanProcessingTime(), 
ps.getMinProcessingTime(), ps.getMaxProcessingTime(), 
ps.getAccumulatedProcessingTime(), selfTime));
-                    }
-                }
-            }
-        } else {
-            System.out.println("");
-            System.out.println(StringEscapeUtils.unescapeJava("\u001B[31mJMX 
Agent of Camel is not reachable. Maybe it has been disabled on the Camel 
context"));
-            System.out.println(StringEscapeUtils.unescapeJava("In consequence, 
profile are not available.\u001B[0m"));
-        }
-
-        // we want to group routes from the same context in the same table
-        previousCamelContextName = camelContext.getName();
+    protected Object doExecute() throws Exception {
+        RouteProfileCommand command = new RouteProfileCommand(route, context);
+        command.setStringEscape(stringEscape);
+        return command.execute(camelController, System.out, System.err);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
index ac68d38..f9da48e 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
@@ -16,13 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import java.util.Set;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
-import org.apache.camel.spi.ManagementAgent;
+import org.apache.camel.commands.RouteResetStatsCommand;
 import org.apache.felix.gogo.commands.Command;
 
 /**
@@ -32,21 +26,9 @@ import org.apache.felix.gogo.commands.Command;
 public class RouteResetStats extends AbstractRouteCommand {
 
     @Override
-    public void executeOnRoute(CamelContext camelContext, Route camelRoute) 
throws Exception {
-        ManagementAgent agent = 
camelContext.getManagementStrategy().getManagementAgent();
-        if (agent != null) {
-            MBeanServer mBeanServer = agent.getMBeanServer();
-
-            // reset route mbeans
-            ObjectName query = 
ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
-            Set<ObjectName> set = mBeanServer.queryNames(query, null);
-            for (ObjectName routeMBean : set) {
-                String camelId = (String) mBeanServer.getAttribute(routeMBean, 
"CamelId");
-                if (camelId != null && camelId.equals(camelContext.getName())) 
{
-                    mBeanServer.invoke(routeMBean, "reset", new 
Object[]{true}, new String[]{"boolean"});
-                }
-            }
-        }
+    protected Object doExecute() throws Exception {
+        RouteResetStatsCommand command = new RouteResetStatsCommand(route, 
context);
+        return command.execute(camelController, System.out, System.err);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java
index 6f91848..bf666a1 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResume.java
@@ -16,8 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
+import org.apache.camel.commands.RouteResumeCommand;
 import org.apache.felix.gogo.commands.Command;
 
 /**
@@ -27,8 +26,9 @@ import org.apache.felix.gogo.commands.Command;
 public class RouteResume extends AbstractRouteCommand {
 
     @Override
-    public void executeOnRoute(CamelContext camelContext, Route camelRoute) 
throws Exception {
-        camelContext.resumeRoute(camelRoute.getId());
+    protected Object doExecute() throws Exception {
+        RouteResumeCommand command = new RouteResumeCommand(route, context);
+        return command.execute(camelController, System.out, System.err);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteShow.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteShow.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteShow.java
index 87a71fa..4774d30 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteShow.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteShow.java
@@ -16,9 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import org.apache.camel.Route;
-import org.apache.camel.model.ModelHelper;
-import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.commands.RouteShowCommand;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 
@@ -35,18 +33,8 @@ public class RouteShow extends CamelCommandSupport {
     String context;
 
     public Object doExecute() throws Exception {
-        Route camelRoute = camelController.getRoute(route, context);
-        if (camelRoute == null) {
-            System.err.println("Camel route " + route + " not found.");
-            return null;
-        }
-        RouteDefinition routeDefinition = 
camelController.getRouteDefinition(route, 
camelRoute.getRouteContext().getCamelContext().getName());
-        if (routeDefinition == null) {
-            System.err.println("Definition of route " + route + " not found.");
-            return null;
-        }
-        System.out.println(ModelHelper.dumpModelAsXml(routeDefinition));
-        return null;
+        RouteShowCommand command = new RouteShowCommand(route, context);
+        return command.execute(camelController, System.out, System.err);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
index da8220f..b0de859 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
@@ -16,8 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
+import org.apache.camel.commands.RouteStartCommand;
 import org.apache.felix.gogo.commands.Command;
 
 /**
@@ -27,8 +26,8 @@ import org.apache.felix.gogo.commands.Command;
 public class RouteStart extends AbstractRouteCommand {
 
     @Override
-    public void executeOnRoute(CamelContext camelContext, Route camelRoute) 
throws Exception {
-        camelContext.startRoute(camelRoute.getId());
+    protected Object doExecute() throws Exception {
+        RouteStartCommand command = new RouteStartCommand(route, context);
+        return command.execute(camelController, System.out, System.err);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java
index 5be9399..f6ac865 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStop.java
@@ -16,8 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
+import org.apache.camel.commands.RouteStopCommand;
 import org.apache.felix.gogo.commands.Command;
 
 /**
@@ -27,8 +26,9 @@ import org.apache.felix.gogo.commands.Command;
 public class RouteStop extends AbstractRouteCommand {
 
     @Override
-    public void executeOnRoute(CamelContext camelContext, Route camelRoute) 
throws Exception {
-        camelContext.stopRoute(camelRoute.getId());
+    protected Object doExecute() throws Exception {
+        RouteStopCommand command = new RouteStopCommand(route, context);
+        return command.execute(camelController, System.out, System.err);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java
index accaf0e..2d9fa20 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteSuspend.java
@@ -16,8 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
+import org.apache.camel.commands.RouteSuspendCommand;
 import org.apache.felix.gogo.commands.Command;
 
 /**
@@ -27,8 +26,9 @@ import org.apache.felix.gogo.commands.Command;
 public class RouteSuspend extends AbstractRouteCommand {
 
     @Override
-    public void executeOnRoute(CamelContext camelContext, Route camelRoute) 
throws Exception {
-        camelContext.suspendRoute(camelRoute.getId());
+    protected Object doExecute() throws Exception {
+        RouteSuspendCommand command = new RouteSuspendCommand(route, context);
+        return command.execute(camelController, System.out, System.err);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/acd55f53/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
 
b/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
index cf0f525..e298a72 100644
--- 
a/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
+++ 
b/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
@@ -91,6 +91,7 @@
     <command name="camel/route-profile">
       <action class="org.apache.camel.karaf.commands.RouteProfile">
         <property name="camelController" ref="camelController"/>
+        <property name="stringEscape" ref="stringEscape"/>
       </action>
       <completers>
         <ref component-id="routeCompleter"/>

Reply via email to