CAMEL-8147: Camel JMX when using custom @ManagedResource should mixin the standard mbean operations/attributes so you get both worlds.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f28399ff Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f28399ff Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f28399ff Branch: refs/heads/master Commit: f28399ff35dec089db091dc9c9e03cecbb356b89 Parents: aa1fba8 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Aug 11 14:15:08 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Aug 11 15:30:40 2015 +0200 ---------------------------------------------------------------------- .../camel/component/seda/SedaEndpoint.java | 92 -------------------- .../camel/component/timer/TimerEndpoint.java | 30 ++----- .../camel/component/xslt/XsltEndpoint.java | 21 ++--- .../xslt/ManagedXsltOutputBytesTest.java | 76 ++++++++++++++++ 4 files changed, 87 insertions(+), 132 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f28399ff/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java index 1b82935..7b10d1a 100644 --- a/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java @@ -27,7 +27,6 @@ import java.util.concurrent.ExecutorService; import org.apache.camel.Component; import org.apache.camel.Consumer; import org.apache.camel.Exchange; -import org.apache.camel.Message; import org.apache.camel.MultipleConsumersSupport; import org.apache.camel.PollingConsumer; import org.apache.camel.Processor; @@ -43,8 +42,6 @@ import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriPath; -import org.apache.camel.util.EndpointHelper; -import org.apache.camel.util.MessageHelper; import org.apache.camel.util.ServiceHelper; import org.apache.camel.util.URISupport; import org.slf4j.Logger; @@ -405,7 +402,6 @@ public class SedaEndpoint extends DefaultEndpoint implements BrowsableEndpoint, this.purgeWhenStopping = purgeWhenStopping; } - @ManagedAttribute(description = "Singleton") public boolean isSingleton() { return true; } @@ -445,94 +441,6 @@ public class SedaEndpoint extends DefaultEndpoint implements BrowsableEndpoint, return new HashSet<SedaProducer>(producers); } - @ManagedOperation(description = "Current number of Exchanges in Queue") - public long queueSize() { - return getExchanges().size(); - } - - @ManagedOperation(description = "Get Exchange from queue by index") - public String browseExchange(Integer index) { - List<Exchange> exchanges = getExchanges(); - if (index >= exchanges.size()) { - return null; - } - Exchange exchange = exchanges.get(index); - if (exchange == null) { - return null; - } - // must use java type with JMX such as java.lang.String - return exchange.toString(); - } - - @ManagedOperation(description = "Get message body from queue by index") - public String browseMessageBody(Integer index) { - List<Exchange> exchanges = getExchanges(); - if (index >= exchanges.size()) { - return null; - } - Exchange exchange = exchanges.get(index); - if (exchange == null) { - return null; - } - - // must use java type with JMX such as java.lang.String - String body; - if (exchange.hasOut()) { - body = exchange.getOut().getBody(String.class); - } else { - body = exchange.getIn().getBody(String.class); - } - - return body; - } - - @ManagedOperation(description = "Get message as XML from queue by index") - public String browseMessageAsXml(Integer index, Boolean includeBody) { - List<Exchange> exchanges = getExchanges(); - if (index >= exchanges.size()) { - return null; - } - Exchange exchange = exchanges.get(index); - if (exchange == null) { - return null; - } - - Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn(); - String xml = MessageHelper.dumpAsXml(msg, includeBody); - - return xml; - } - - @ManagedOperation(description = "Gets all the messages as XML from the queue") - public String browseAllMessagesAsXml(Boolean includeBody) { - return browseRangeMessagesAsXml(0, Integer.MAX_VALUE, includeBody); - } - - @ManagedOperation(description = "Gets the range of messages as XML from the queue") - public String browseRangeMessagesAsXml(Integer fromIndex, Integer toIndex, Boolean includeBody) { - return EndpointHelper.browseRangeMessagesAsXml(this, fromIndex, toIndex, includeBody); - } - - @ManagedAttribute(description = "Camel context ID") - public String getCamelId() { - return getCamelContext().getName(); - } - - @ManagedAttribute(description = "Camel ManagementName") - public String getCamelManagementName() { - return getCamelContext().getManagementName(); - } - - @ManagedAttribute(description = "Endpoint URI", mask = true) - public String getEndpointUri() { - return super.getEndpointUri(); - } - - @ManagedAttribute(description = "Endpoint service state") - public String getState() { - return getStatus().name(); - } - void onStarted(SedaProducer producer) { producers.add(producer); } http://git-wip-us.apache.org/repos/asf/camel/blob/f28399ff/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java index 1ddcc81..a3ce56d 100644 --- a/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java @@ -86,6 +86,11 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS } @Override + public boolean isSingleton() { + return true; + } + + @Override protected void doStart() throws Exception { super.doStart(); // do nothing, the timer will be set when the first consumer will request it @@ -203,31 +208,6 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS this.time = time; } - @ManagedAttribute(description = "Singleton") - public boolean isSingleton() { - return true; - } - - @ManagedAttribute(description = "Camel id") - public String getCamelId() { - return this.getCamelContext().getName(); - } - - @ManagedAttribute(description = "Camel ManagementName") - public String getCamelManagementName() { - return this.getCamelContext().getManagementName(); - } - - @ManagedAttribute(description = "Endpoint Uri") - public String getEndpointUri() { - return super.getEndpointUri(); - } - - @ManagedAttribute(description = "Endpoint State") - public String getState() { - return getStatus().name(); - } - public Timer getTimer(TimerConsumer consumer) { if (timer != null) { // use custom timer http://git-wip-us.apache.org/repos/asf/camel/blob/f28399ff/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java index 8d3db9e..6a4ecd0 100644 --- a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java @@ -106,21 +106,6 @@ public class XsltEndpoint extends ProcessorEndpoint { return contentCache; } - @ManagedAttribute(description = "Endpoint State") - public String getState() { - return getStatus().name(); - } - - @ManagedAttribute(description = "Camel ID") - public String getCamelId() { - return getCamelContext().getName(); - } - - @ManagedAttribute(description = "Camel ManagementName") - public String getCamelManagementName() { - return getCamelContext().getManagementName(); - } - public XsltEndpoint findOrCreateEndpoint(String uri, String newResourceUri) { String newUri = uri.replace(resourceUri, newResourceUri); LOG.trace("Getting endpoint with URI: {}", newUri); @@ -151,6 +136,7 @@ public class XsltEndpoint extends ProcessorEndpoint { this.xslt = xslt; } + @ManagedAttribute(description = "The name of the template to load from classpath or file system") public String getResourceUri() { return resourceUri; } @@ -195,6 +181,7 @@ public class XsltEndpoint extends ProcessorEndpoint { this.transformerFactory = transformerFactory; } + @ManagedAttribute(description = "Whether to use Saxon as the transformerFactoryClass") public boolean isSaxon() { return saxon; } @@ -219,6 +206,7 @@ public class XsltEndpoint extends ProcessorEndpoint { this.resultHandlerFactory = resultHandlerFactory; } + @ManagedAttribute(description = "Whether or not to throw an exception if the input body is null") public boolean isFailOnNullBody() { return failOnNullBody; } @@ -230,6 +218,7 @@ public class XsltEndpoint extends ProcessorEndpoint { this.failOnNullBody = failOnNullBody; } + @ManagedAttribute(description = "What kind of option to use.") public XsltOutput getOutput() { return output; } @@ -268,6 +257,7 @@ public class XsltEndpoint extends ProcessorEndpoint { this.errorListener = errorListener; } + @ManagedAttribute(description = "Cache for the resource content (the stylesheet file) when it is loaded.") public boolean isContentCache() { return contentCache; } @@ -292,6 +282,7 @@ public class XsltEndpoint extends ProcessorEndpoint { this.uriResolver = uriResolver; } + @ManagedAttribute(description = "Whether to allow using StAX as the javax.xml.transform.Source") public boolean isAllowStAX() { return allowStAX; } http://git-wip-us.apache.org/repos/asf/camel/blob/f28399ff/camel-core/src/test/java/org/apache/camel/component/xslt/ManagedXsltOutputBytesTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/xslt/ManagedXsltOutputBytesTest.java b/camel-core/src/test/java/org/apache/camel/component/xslt/ManagedXsltOutputBytesTest.java new file mode 100644 index 0000000..a0c1ae7 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/xslt/ManagedXsltOutputBytesTest.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.component.xslt; + +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * + */ +public class ManagedXsltOutputBytesTest extends ContextTestSupport { + + @Override + protected boolean useJmx() { + return true; + } + + protected MBeanServer getMBeanServer() { + return context.getManagementStrategy().getManagementAgent().getMBeanServer(); + } + + public void testXsltOutput() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>"); + mock.message(0).body().isInstanceOf(byte[].class); + + template.sendBody("direct:start", "<hello>world!</hello>"); + + assertMockEndpointsSatisfied(); + + MBeanServer mbeanServer = getMBeanServer(); + + ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"xslt://org/apache/camel/component/xslt/example.xsl\\?output=bytes\""); + String uri = (String) mbeanServer.getAttribute(on, "EndpointUri"); + assertEquals("xslt://org/apache/camel/component/xslt/example.xsl?output=bytes", uri); + + Boolean saxon = (Boolean) mbeanServer.getAttribute(on, "Saxon"); + assertEquals(false, saxon.booleanValue()); + + XsltOutput output = (XsltOutput) mbeanServer.getAttribute(on, "Output"); + assertEquals(XsltOutput.bytes, output); + + String state = (String) mbeanServer.getAttribute(on, "State"); + assertEquals("Started", state); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("xslt:org/apache/camel/component/xslt/example.xsl?output=bytes") + .to("mock:result"); + } + }; + } +}