diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/LoggingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/LoggingHandler.java index 433e9d620e..14e1aa18df 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/LoggingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/LoggingHandler.java @@ -1,23 +1,21 @@ /* * Copyright 2002-2010 the original author or authors. - * - * Licensed 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. + * + * Licensed 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.springframework.integration.handler; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.List; import org.springframework.context.expression.MapAccessor; import org.springframework.expression.EvaluationContext; @@ -25,20 +23,22 @@ import org.springframework.expression.Expression; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.integration.Message; +import org.springframework.integration.dispatcher.AggregateMessageDeliveryException; import org.springframework.util.StringUtils; /** - * MessageHandler implementation that simply logs the Message or its payload - * depending on the value of the 'shouldLogFullMessage' property. If logging - * the payload, and it is assignable to Throwable, it will log the stack trace. - * By default, it will log the payload only. + * MessageHandler implementation that simply logs the Message or its payload depending on the value of the + * 'shouldLogFullMessage' property. If logging the payload, and it is assignable to Throwable, it will log the stack + * trace. By default, it will log the payload only. * * @author Mark Fisher * @since 1.0.1 */ public class LoggingHandler extends AbstractMessageHandler { - private static enum Level { FATAL, ERROR, WARN, INFO, DEBUG, TRACE } + private static enum Level { + FATAL, ERROR, WARN, INFO, DEBUG, TRACE + } private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser(); @@ -48,18 +48,18 @@ public class LoggingHandler extends AbstractMessageHandler { private final EvaluationContext evaluationContext; - /** * Create a LoggingHandler with the given log level (case-insensitive). - *
The valid levels are: FATAL, ERROR, WARN, INFO, DEBUG, or TRACE + *
+ * The valid levels are: FATAL, ERROR, WARN, INFO, DEBUG, or TRACE
*/
public LoggingHandler(String level) {
try {
this.level = Level.valueOf(level.toUpperCase());
- }
- catch (IllegalArgumentException e) {
- throw new IllegalArgumentException("Invalid log level '" + level +
- "'. The (case-insensitive) supported values are: " + StringUtils.arrayToCommaDelimitedString(Level.values()));
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid log level '" + level
+ + "'. The (case-insensitive) supported values are: "
+ + StringUtils.arrayToCommaDelimitedString(Level.values()));
}
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
evaluationContext.addPropertyAccessor(new MapAccessor());
@@ -67,18 +67,17 @@ public class LoggingHandler extends AbstractMessageHandler {
this.expression = EXPRESSION_PARSER.parseExpression("payload");
}
-
public void setExpression(String expressionString) {
this.expression = EXPRESSION_PARSER.parseExpression(expressionString);
}
/**
- * Specify whether to log the full Message. Otherwise, only the payload
- * will be logged. This value is false by default.
+ * Specify whether to log the full Message. Otherwise, only the payload will be logged. This value is
+ * false by default.
*/
public void setShouldLogFullMessage(boolean shouldLogFullMessage) {
- this.expression = (shouldLogFullMessage) ? EXPRESSION_PARSER.parseExpression("#root")
- : EXPRESSION_PARSER.parseExpression("payload");
+ this.expression = (shouldLogFullMessage) ? EXPRESSION_PARSER.parseExpression("#root") : EXPRESSION_PARSER
+ .parseExpression("payload");
}
@Override
@@ -91,40 +90,47 @@ public class LoggingHandler extends AbstractMessageHandler {
Object logMessage = this.expression.getValue(this.evaluationContext, message);
if (logMessage instanceof Throwable) {
StringWriter stringWriter = new StringWriter();
- ((Throwable) logMessage).printStackTrace(new PrintWriter(stringWriter, true));
+ if (logMessage instanceof AggregateMessageDeliveryException) {
+ stringWriter.append(((Throwable) logMessage).getMessage());
+ for (Exception exception : (List extends Exception>) ((AggregateMessageDeliveryException)logMessage).getAggregatedExceptions()) {
+ exception.printStackTrace(new PrintWriter(stringWriter, true));
+ }
+ } else {
+ ((Throwable) logMessage).printStackTrace(new PrintWriter(stringWriter, true));
+ }
logMessage = stringWriter.toString();
}
switch (this.level) {
- case FATAL :
- if (logger.isFatalEnabled()) {
- logger.fatal(logMessage);
- }
- break;
- case ERROR :
- if (logger.isErrorEnabled()) {
- logger.error(logMessage);
- }
- break;
- case WARN :
- if (logger.isWarnEnabled()) {
- logger.warn(logMessage);
- }
- break;
- case INFO :
- if (logger.isInfoEnabled()) {
- logger.info(logMessage);
- }
- break;
- case DEBUG :
- if (logger.isDebugEnabled()) {
- logger.debug(logMessage);
- }
- break;
- case TRACE :
- if (logger.isTraceEnabled()) {
- logger.trace(logMessage);
- }
- break;
+ case FATAL:
+ if (logger.isFatalEnabled()) {
+ logger.fatal(logMessage);
+ }
+ break;
+ case ERROR:
+ if (logger.isErrorEnabled()) {
+ logger.error(logMessage);
+ }
+ break;
+ case WARN:
+ if (logger.isWarnEnabled()) {
+ logger.warn(logMessage);
+ }
+ break;
+ case INFO:
+ if (logger.isInfoEnabled()) {
+ logger.info(logMessage);
+ }
+ break;
+ case DEBUG:
+ if (logger.isDebugEnabled()) {
+ logger.debug(logMessage);
+ }
+ break;
+ case TRACE:
+ if (logger.isTraceEnabled()) {
+ logger.trace(logMessage);
+ }
+ break;
}
}
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/LoggingHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/LoggingHandlerTests.java
index 160119e168..0be4db2ce6 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/handler/LoggingHandlerTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/LoggingHandlerTests.java
@@ -18,7 +18,6 @@ package org.springframework.integration.handler;
import org.junit.Test;
import org.junit.runner.RunWith;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
@@ -42,7 +41,6 @@ public class LoggingHandlerTests {
input.send(MessageBuilder.withPayload(bean).setHeader("foo", "bar").build());
}
-
public static class TestBean {
private final String name;
diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMetrics.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMetrics.java
index 17b0a9a773..8c4f780dd1 100644
--- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMetrics.java
+++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMetrics.java
@@ -20,10 +20,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
-import org.springframework.jmx.export.annotation.ManagedMetric;
-import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
-import org.springframework.jmx.support.MetricType;
import org.springframework.util.StopWatch;
/**
@@ -110,7 +107,7 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
timer.stop();
if ((Boolean)result) {
sendSuccessRatio.success();
- sendDuration.append(timer.getTotalTimeSeconds());
+ sendDuration.append(timer.getTotalTimeMillis());
} else {
sendSuccessRatio.failure();
sendErrorCount.incrementAndGet();
@@ -132,7 +129,6 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
}
}
- @ManagedOperation
public synchronized void reset() {
sendDuration.reset();
sendErrorRate.reset();
@@ -142,52 +138,42 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
sendErrorCount.set(0);
}
- @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Sends")
public int getSendCount() {
return sendCount.get();
}
- @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Errors")
public int getSendErrorCount() {
return sendErrorCount.get();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Time Since Last Send in Seconds")
public double getTimeSinceLastSend() {
return sendRate.getTimeSinceLastMeasurement();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Rate per Second")
public double getMeanSendRate() {
return sendRate.getMean();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Error Rate per Second")
public double getMeanErrorRate() {
return sendErrorRate.getMean();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Mean Channel Error Ratio per Minute")
public double getMeanErrorRatio() {
return 1 - sendSuccessRatio.getMean();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Mean Duration")
public double getMeanSendDuration() {
return sendDuration.getMean();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Min Duration")
public double getMinSendDuration() {
return sendDuration.getMin();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Max Duration")
public double getMaxSendDuration() {
return sendDuration.getMax();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Standard Deviation Duration")
public double getStandardDeviationSendDuration() {
return sendDuration.getStandardDeviation();
}
diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMetrics.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMetrics.java
index 2364e75b3a..c50c6ba78c 100644
--- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMetrics.java
+++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/LifecycleMessageHandlerMetrics.java
@@ -56,7 +56,6 @@ public class LifecycleMessageHandlerMetrics implements MessageHandlerMetrics, Li
lifecycle.stop();
}
- @ManagedOperation
public void reset() {
delegate.reset();
}
diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMetrics.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMetrics.java
index 141147c23a..30006df772 100644
--- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMetrics.java
+++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/MessageHandlerMetrics.java
@@ -32,37 +32,37 @@ public interface MessageHandlerMetrics {
/**
* @return the number of successful handler calls
*/
- @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count", description = "rate=1h")
+ @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count")
int getHandleCount();
/**
* @return the number of failed handler calls
*/
- @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count", description = "rate=1h")
+ @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count")
int getErrorCount();
/**
* @return the maximum handler duration (milliseconds)
*/
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Mean Duration")
+ @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Mean Duration (ms)")
double getMeanDuration();
/**
* @return the minimum handler duration (milliseconds)
*/
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Min Duration")
+ @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Min Duration (ms)")
double getMinDuration();
/**
* @return the standard deviation handler duration (milliseconds)
*/
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Max Duration")
+ @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Max Duration (ms)")
double getMaxDuration();
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Standard Deviation Duration")
+ @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Standard Deviation Duration (ms)")
double getStandardDeviationDuration();
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Active Status")
+ @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Active Count")
int getActiveCount();
/**
diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMetrics.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMetrics.java
index 1c3e3f34d7..9dc052f9db 100644
--- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMetrics.java
+++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMetrics.java
@@ -26,10 +26,7 @@ import org.springframework.integration.MessageDeliveryException;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.core.MessageHandler;
-import org.springframework.jmx.export.annotation.ManagedMetric;
-import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
-import org.springframework.jmx.support.MetricType;
import org.springframework.util.StopWatch;
/**
@@ -114,7 +111,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
handler.handleMessage(message);
timer.stop();
- duration.append(timer.getTotalTimeSeconds());
+ duration.append(timer.getTotalTimeMillis());
} catch (RuntimeException e) {
errorCount.incrementAndGet();
throw e;
@@ -126,14 +123,12 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
}
}
- @ManagedOperation
public synchronized void reset() {
duration.reset();
errorCount.set(0);
handleCount.set(0);
}
- @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count", description = "rate=1h")
public int getHandleCount() {
if (logger.isTraceEnabled()) {
logger.trace("Getting Handle Count:" + this);
@@ -141,32 +136,26 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
return handleCount.get();
}
- @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count", description = "rate=1h")
public int getErrorCount() {
return errorCount.get();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Mean Duration")
public double getMeanDuration() {
return duration.getMean();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Min Duration")
public double getMinDuration() {
return duration.getMin();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Max Duration")
public double getMaxDuration() {
return duration.getMax();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Standard Deviation Duration")
public double getStandardDeviationDuration() {
return duration.getStandardDeviation();
}
- @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Active Count")
public int getActiveCount() {
return activeCount.get();
}
diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageSourceMetrics.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageSourceMetrics.java
index edcd1a84ad..0edda2aa6e 100644
--- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageSourceMetrics.java
+++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageSourceMetrics.java
@@ -18,9 +18,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.integration.core.MessageSource;
-import org.springframework.jmx.export.annotation.ManagedMetric;
-import org.springframework.jmx.export.annotation.ManagedOperation;
-import org.springframework.jmx.support.MetricType;
/**
* @author Dave Syer
@@ -62,12 +59,10 @@ public class SimpleMessageSourceMetrics implements MethodInterceptor, MessageSou
return messageSource;
}
- @ManagedOperation
public void reset() {
messageCount.set(0);
}
- @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count")
public int getMessageCount() {
return messageCount.get();
}
diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java
index 924916c5cc..d02421101b 100644
--- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java
+++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java
@@ -15,6 +15,7 @@ package org.springframework.integration.jmx.config;
import static org.junit.Assert.assertEquals;
+import java.util.Arrays;
import java.util.Set;
import javax.management.MBeanServer;
@@ -46,6 +47,7 @@ public class MBeanRegistrationTests {
@Test
public void testExporterMBeanRegistration() throws Exception {
// System.err.println(server.queryNames(new ObjectName("*:type=*MBeanExporter,*"), null));
+ System.err.println(Arrays.asList(server.getMBeanInfo(server.queryNames(new ObjectName("*:type=*Handler,*"), null).iterator().next()).getAttributes()));
Set