You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2008/09/25 09:37:13 UTC
svn commit: r698848 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/builder/
camel-core/src/main/java/org/apache/camel/impl/converter/
camel-core/src/main/java/org/apache/camel/language/simple/
camel-core/src/main/java/org/apache/...
Author: davsclaus
Date: Thu Sep 25 00:37:12 2008
New Revision: 698848
URL: http://svn.apache.org/viewvc?rev=698848&view=rev
Log:
CAMEL-930. Partly done: Moved stuff from file language to simple language. Fixed broken unit test in CAMEL-84. Polished code.
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsIOConverter.java
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Thu Sep 25 00:37:12 2008
@@ -20,9 +20,9 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.nio.channels.ReadableByteChannel;
-import java.util.ArrayList;
+import java.text.SimpleDateFormat;
import java.util.Collection;
-import java.util.List;
+import java.util.Date;
import java.util.Scanner;
import java.util.regex.Pattern;
@@ -30,6 +30,8 @@
import org.apache.camel.Expression;
import org.apache.camel.Message;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.language.bean.BeanLanguage;
+import org.apache.camel.language.simple.SimpleLanguage;
/**
* A helper class for working with <a href="http://activemq.apache.org/camel/expression.html">expressions</a>.
@@ -634,5 +636,67 @@
};
}
+ public static <E extends Exchange> Expression<E> dateExpression(final String command, final String pattern) {
+ return new Expression<E>() {
+ public Object evaluate(E exchange) {
+ Date date;
+ if ("now".equals(command)) {
+ date = new Date();
+ } else if (command.startsWith("header.") || command.startsWith("in.header.")) {
+ String key = command.substring(command.lastIndexOf(".") + 1);
+ date = exchange.getIn().getHeader(key, Date.class);
+ if (date == null) {
+ throw new IllegalArgumentException("Could not find java.util.Date object at " + command);
+ }
+ } else if (command.startsWith("out.header.")) {
+ String key = command.substring(command.lastIndexOf(".") + 1);
+ date = exchange.getOut().getHeader(key, Date.class);
+ if (date == null) {
+ throw new IllegalArgumentException("Could not find java.util.Date object at " + command);
+ }
+ } else {
+ throw new IllegalArgumentException("Command not supported for dateExpression: " + command);
+ }
+
+ SimpleDateFormat df = new SimpleDateFormat(pattern);
+ return df.format(date);
+ }
+
+ @Override
+ public String toString() {
+ return "date(" + command + ":" + pattern + ")";
+ }
+ };
+ }
+
+ public static <E extends Exchange> Expression<E> simpleExpression(final String simple) {
+ return new Expression<E>() {
+ public Object evaluate(E exchange) {
+ // must call evalute to return the nested langauge evaluate when evaluating
+ // stacked expressions
+ return SimpleLanguage.simple(simple).evaluate(exchange);
+ }
+
+ @Override
+ public String toString() {
+ return "simple(" + simple + ")";
+ }
+ };
+ }
+
+ public static <E extends Exchange> Expression<E> beanExpression(final String bean) {
+ return new Expression<E>() {
+ public Object evaluate(E exchange) {
+ // must call evalute to return the nested langauge evaluate when evaluating
+ // stacked expressions
+ return BeanLanguage.bean(bean).evaluate(exchange);
+ }
+
+ @Override
+ public String toString() {
+ return "bean(" + bean + ")";
+ }
+ };
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java Thu Sep 25 00:37:12 2008
@@ -112,16 +112,7 @@
return (T) convertTo(primitiveType, exchange, value);
}
}
-
- boolean camelType = type.getCanonicalName().startsWith("org.apache.camel");
- if (!camelType) {
- // TODO: as the next thing is an exception I suspect this warn is useless. TB removed.
- // only log WARN level for non internal Camel convertions
- LOG.warn("Could not find a type converter for converting "
- + value.getClass().getCanonicalName() + " -> "
- + type.getCanonicalName() + " with value: " + value);
- }
-
+
// Could not find suitable conversion
throw new NoTypeConversionAvailableException(value, type);
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java Thu Sep 25 00:37:12 2008
@@ -23,6 +23,7 @@
import org.apache.camel.Expression;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.ExpressionBuilder;
import org.apache.camel.component.file.FileExchange;
import org.apache.camel.language.bean.BeanLanguage;
@@ -31,6 +32,9 @@
* on FileExchange.
*/
public final class FileExpressionBuilder {
+
+ // TODO: All the file stuff should just be added as
+
private FileExpressionBuilder() {
// Helper class
}
@@ -139,32 +143,17 @@
public static <E extends FileExchange> Expression<E> dateExpression(final String command, final String pattern) {
return new Expression<E>() {
public Object evaluate(E exchange) {
- Date date;
if ("file".equals(command)) {
if (exchange.getFile() == null) {
return null;
}
- date = new Date(exchange.getFile().lastModified());
- } else if ("now".equals(command)) {
- date = new Date();
- } else if (command.startsWith("header.") || command.startsWith("in.header.")) {
- String key = command.substring(command.lastIndexOf(".") + 1);
- date = exchange.getIn().getHeader(key, Date.class);
- if (date == null) {
- throw new IllegalArgumentException("Could not find java.util.Date object at " + command);
- }
- } else if (command.startsWith("out.header.")) {
- String key = command.substring(command.lastIndexOf(".") + 1);
- date = exchange.getOut().getHeader(key, Date.class);
- if (date == null) {
- throw new IllegalArgumentException("Could not find java.util.Date object at " + command);
- }
- } else {
- throw new IllegalArgumentException("Command not supported for dateExpression: " + command);
+ Date date = new Date(exchange.getFile().lastModified());
+ SimpleDateFormat df = new SimpleDateFormat(pattern);
+ return df.format(date);
}
-
- SimpleDateFormat df = new SimpleDateFormat(pattern);
- return df.format(date);
+ // must call evalute to return the nested langauge evaluate when evaluating
+ // stacked expressions
+ return ExpressionBuilder.dateExpression(command, pattern).evaluate(exchange);
}
@Override
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java Thu Sep 25 00:37:12 2008
@@ -33,13 +33,9 @@
* <li>file:absolute to access the absolute file name</li>
* <li>file:canonical.path to access the canonical path name</li>
* <li>date:<command>:<pattern> for date formatting using the {@link java.text.SimpleDateFormat} patterns.
- * Supported commands are: <tt>now</tt> for current timestamp, <tt>file</tt> for the last modified timestamp of the file.
- * <tt>in.header.xxx</tt> or <tt>header.xxx</tt> to use the Date object in the in header.
- * <tt>out.header.xxx</tt> to use the Date object in the out header. </li>
- * <li>bean:<bean expression> to invoke a bean using the
- * {@link org.apache.camel.language.bean.BeanLanguage BeanLanguage}</li>
- * <li>simple:<simple expression> to invoke the simple expression, however simple: can be obmitted as this language
- * extends the simple language</li>
+ * Additional Supported commands are: <tt>file</tt> for the last modified timestamp of the file.
+ * All the commands from {@link SimpleLanguage} is also avaiable.
+ * </li>
* </ul>
* All the simple expression is also available so you can eg use <tt>${in.header.foo}</tt> to access the foo header.
*
@@ -85,18 +81,6 @@
return FileExpressionBuilder.dateExpression(command, pattern);
}
- // bean: prefix
- remainder = ifStartsWithReturnRemainder("bean:", expression);
- if (remainder != null) {
- return FileExpressionBuilder.beanExpression(remainder);
- }
-
- // simple: prefix
- remainder = ifStartsWithReturnRemainder("simple:", expression);
- if (remainder != null) {
- return FileExpressionBuilder.simpleExpression(remainder);
- }
-
// fallback to simple language if not file specific
return FileExpressionBuilder.simpleExpression(expression);
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java Thu Sep 25 00:37:12 2008
@@ -34,6 +34,13 @@
* <li>out.header.foo to access an outbound header called 'foo'</li>
* <li>property.foo to access the exchange property called 'foo'</li>
* <li>sys.foo to access the system property called 'foo'</li>
+ * <li>date:<command>:<pattern> for date formatting using the {@link java.text.SimpleDateFormat} patterns.
+ * Supported commands are: <tt>now</tt> for current timestamp,
+ * <tt>in.header.xxx</tt> or <tt>header.xxx</tt> to use the Date object in the in header.
+ * <tt>out.header.xxx</tt> to use the Date object in the out header.
+ * </li>
+ * <li>bean:<bean expression> to invoke a bean using the
+ * {@link org.apache.camel.language.bean.BeanLanguage BeanLanguage}</li>
* </ul>
*
* @version $Revision$
@@ -90,6 +97,24 @@
return ExpressionBuilder.systemProperty(remainder);
}
+ // date: prefix
+ remainder = ifStartsWithReturnRemainder("date:", expression);
+ if (remainder != null) {
+ String[] parts = remainder.split(":");
+ if (parts.length != 2) {
+ throw new IllegalSyntaxException(this, expression + " ${date:command:pattern} is the correct syntax.");
+ }
+ String command = parts[0];
+ String pattern = parts[1];
+ return ExpressionBuilder.dateExpression(command, pattern);
+ }
+
+ // bean: prefix
+ remainder = ifStartsWithReturnRemainder("bean:", expression);
+ if (remainder != null) {
+ return ExpressionBuilder.beanExpression(remainder);
+ }
+
throw new IllegalSyntaxException(this, expression);
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java Thu Sep 25 00:37:12 2008
@@ -201,6 +201,8 @@
Object convertedValue = convert(typeConverter, setter.getParameterTypes()[0], value);
setter.invoke(target, convertedValue);
return true;
+ } catch (NoTypeConversionAvailableException e) {
+ // ignore we could not find a suitable type converter for this method
} catch (IllegalArgumentException e) {
typeConvertionFailed = e;
// ignore as there could be another setter method where we could type convert with success
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java Thu Sep 25 00:37:12 2008
@@ -78,15 +78,6 @@
}
}
- public void testSimple() throws Exception {
- assertExpression("${body}", "<hello id='m123'>world!</hello>");
- assertExpression("${in.header.foo}", "abc");
-
- // end users might add simple: prefix so we support that too
- assertExpression("${simple:in.header.foo}", "abc");
- assertExpression("${simple:body}", "<hello id='m123'>world!</hello>");
- }
-
public void testSimpleAndFile() throws Exception {
assertExpression("backup-${in.header.foo}-${file:name.noext}.bak", "backup-abc-hello.bak");
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java Thu Sep 25 00:37:12 2008
@@ -63,7 +63,7 @@
@Override
protected void tearDown() throws Exception {
super.tearDown();
- System.clearProperty(JmxSystemPropertyKeys.DISABLED);
+ enableJMX();
}
protected RouteBuilder createRouteBuilder() {
@@ -81,8 +81,8 @@
}
public void testStreamResequencerTypeWithoutJmx() throws Exception {
- System.out.println("This will now fail");
- System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
+ log.debug("This will now fail");
+ disableJMX();
doTestStreamResequencerType();
}
Modified: activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsIOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsIOConverter.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsIOConverter.java (original)
+++ activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsIOConverter.java Thu Sep 25 00:37:12 2008
@@ -47,11 +47,6 @@
private JmsIOConverter() {
}
- /**
- * @param message
- * @return a ByteBuffer
- * @throws Exception
- */
@Converter
public static ByteBuffer toByteBuffer(final Message message, Exchange exchange) throws Exception {
@@ -78,8 +73,9 @@
}
} catch (MessageEOFException e) {
// we have no other way of knowing the end of the message
+ } finally {
+ dataOut.close();
}
- dataOut.close();
return NIOConverter.toByteBuffer(bytesOut.toByteArray());
}
if (message instanceof MapMessage) {
Modified: activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?rev=698848&r1=698847&r2=698848&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java (original)
+++ activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java Thu Sep 25 00:37:12 2008
@@ -81,8 +81,6 @@
/**
* Returns the underlying JMS message
- *
- * @return the underlying JMS message
*/
public Message getJmsMessage() {
return jmsMessage;