Repository: camel
Updated Branches:
  refs/heads/master fbe97105b -> 542ab3e8c


CAMEL-8526: Add more EIP as specialized mbeans


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

Branch: refs/heads/master
Commit: 6ad65fb057fd437f2d0a0e24173546bb1d2ec245
Parents: fbe9710
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed Jul 22 08:34:17 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Jul 22 08:34:17 2015 +0200

----------------------------------------------------------------------
 .../mbean/ManagedConvertBodyMBean.java          | 29 +++++++
 .../DefaultManagementObjectStrategy.java        |  6 +-
 .../management/mbean/ManagedConvertBody.java    | 46 ++++++++++
 .../camel/model/ConvertBodyDefinition.java      |  4 +-
 .../camel/processor/ConvertBodyProcessor.java   |  4 +
 .../management/ManagedConvertBodyTest.java      | 90 ++++++++++++++++++++
 6 files changed, 176 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6ad65fb0/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedConvertBodyMBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedConvertBodyMBean.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedConvertBodyMBean.java
new file mode 100644
index 0000000..74961db
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedConvertBodyMBean.java
@@ -0,0 +1,29 @@
+/**
+ * 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 org.apache.camel.api.management.ManagedAttribute;
+
+public interface ManagedConvertBodyMBean extends ManagedProcessorMBean {
+
+    @ManagedAttribute(description = "The java type to convert to")
+    String getType();
+
+    @ManagedAttribute(description = "To use a specific charset when 
converting")
+    String getCharset();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/6ad65fb0/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
 
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
index 2a870b6..460ee47 100644
--- 
a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
+++ 
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
@@ -38,6 +38,7 @@ import 
org.apache.camel.management.mbean.ManagedBrowsableEndpoint;
 import org.apache.camel.management.mbean.ManagedCamelContext;
 import org.apache.camel.management.mbean.ManagedComponent;
 import org.apache.camel.management.mbean.ManagedConsumer;
+import org.apache.camel.management.mbean.ManagedConvertBody;
 import org.apache.camel.management.mbean.ManagedDelayer;
 import org.apache.camel.management.mbean.ManagedDynamicRouter;
 import org.apache.camel.management.mbean.ManagedEndpoint;
@@ -76,6 +77,7 @@ import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.RecipientListDefinition;
 import org.apache.camel.model.ThreadsDefinition;
+import org.apache.camel.processor.ConvertBodyProcessor;
 import org.apache.camel.processor.Delayer;
 import org.apache.camel.processor.DynamicRouter;
 import org.apache.camel.processor.Enricher;
@@ -234,7 +236,9 @@ public class DefaultManagementObjectStrategy implements 
ManagementObjectStrategy
             }
 
             // look for specialized processor which we should prefer to use
-            if (target instanceof Delayer) {
+            if (target instanceof ConvertBodyProcessor) {
+                answer = new ManagedConvertBody(context, 
(ConvertBodyProcessor) target, definition);
+            } else if (target instanceof Delayer) {
                 answer = new ManagedDelayer(context, (Delayer) target, 
definition);
             } else if (target instanceof Throttler) {
                 answer = new ManagedThrottler(context, (Throttler) target, 
definition);

http://git-wip-us.apache.org/repos/asf/camel/blob/6ad65fb0/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConvertBody.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConvertBody.java
 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConvertBody.java
new file mode 100644
index 0000000..01aae9f
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConvertBody.java
@@ -0,0 +1,46 @@
+/**
+ * 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 org.apache.camel.CamelContext;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.ManagedConvertBodyMBean;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.processor.ConvertBodyProcessor;
+
+/**
+ * @version 
+ */
+@ManagedResource(description = "Managed ConvertBody")
+public class ManagedConvertBody extends ManagedProcessor implements 
ManagedConvertBodyMBean {
+    private final ConvertBodyProcessor processor;
+
+    public ManagedConvertBody(CamelContext context, ConvertBodyProcessor 
processor, ProcessorDefinition<?> definition) {
+        super(context, processor, definition);
+        this.processor = processor;
+    }
+
+    @Override
+    public String getType() {
+        return processor.getType().getCanonicalName();
+    }
+
+    @Override
+    public String getCharset() {
+        return processor.getCharset();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6ad65fb0/camel-core/src/main/java/org/apache/camel/model/ConvertBodyDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/ConvertBodyDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/ConvertBodyDefinition.java
index 402790e..9e5ae31 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ConvertBodyDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ConvertBodyDefinition.java
@@ -52,12 +52,12 @@ public class ConvertBodyDefinition extends 
NoOutputDefinition<ConvertBodyDefinit
 
     public ConvertBodyDefinition(Class<?> typeClass) {
         setTypeClass(typeClass);
-        setType(typeClass.getName());
+        setType(typeClass.getCanonicalName());
     }
 
     public ConvertBodyDefinition(Class<?> typeClass, String charset) {
         setTypeClass(typeClass);
-        setType(typeClass.getName());
+        setType(typeClass.getCanonicalName());
         setCharset(charset);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6ad65fb0/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java 
b/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
index d42eae4..6723731 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
@@ -125,6 +125,10 @@ public class ConvertBodyProcessor extends ServiceSupport 
implements AsyncProcess
         return type;
     }
 
+    public String getCharset() {
+        return charset;
+    }
+
     @Override
     protected void doStart() throws Exception {
         // noop

http://git-wip-us.apache.org/repos/asf/camel/blob/6ad65fb0/camel-core/src/test/java/org/apache/camel/management/ManagedConvertBodyTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedConvertBodyTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedConvertBodyTest.java
new file mode 100644
index 0000000..f070426
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedConvertBodyTest.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version 
+ */
+public class ManagedConvertBodyTest extends ManagementTestSupport {
+
+    public void testManageConvertBody() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MockEndpoint foo = getMockEndpoint("mock:foo");
+        foo.expectedMessageCount(1);
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", 
"123");
+
+        assertMockEndpointsSatisfied();
+
+        // get the stats for the route
+        MBeanServer mbeanServer = getMBeanServer();
+
+        // get the object name for the delayer
+        ObjectName on = 
ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
+
+        // should be on route1
+        String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+        assertEquals("route1", routeId);
+
+        String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
+        assertEquals("camel-1", camelId);
+
+        String state = (String) mbeanServer.getAttribute(on, "State");
+        assertEquals(ServiceStatus.Started.name(), state);
+
+        String uri = (String) mbeanServer.getAttribute(on, "Type");
+        assertEquals("byte[]", uri);
+
+        TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new 
Object[]{false}, new String[]{"boolean"});
+        assertNotNull(data);
+        assertEquals(2, data.size());
+
+        data = (TabularData) mbeanServer.invoke(on, "explain", new 
Object[]{true}, new String[]{"boolean"});
+        assertNotNull(data);
+        assertEquals(4, data.size());
+
+        String json = (String) mbeanServer.invoke(on, "informationJson", null, 
null);
+        assertNotNull(json);
+        assertTrue(json.contains("\"description\": \"Converts the message body 
to another type"));
+        assertTrue(json.contains("byte[]"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .convertBodyTo(byte[].class).id("mysend")
+                        .to("mock:foo");
+            }
+        };
+    }
+
+}

Reply via email to