Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 37068 invoked from network); 27 Sep 2008 15:58:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Sep 2008 15:58:40 -0000 Received: (qmail 26737 invoked by uid 500); 27 Sep 2008 15:58:38 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 26707 invoked by uid 500); 27 Sep 2008 15:58:38 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 26698 invoked by uid 99); 27 Sep 2008 15:58:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Sep 2008 08:58:38 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Sep 2008 15:57:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 55C8B238898F; Sat, 27 Sep 2008 08:57:41 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r699675 - in /activemq/camel/trunk/components: camel-ftp/src/main/java/org/apache/camel/component/file/remote/ camel-ftp/src/test/java/org/apache/camel/component/file/remote/ camel-saxon/src/main/java/org/apache/camel/component/xquery/ Date: Sat, 27 Sep 2008 15:57:40 -0000 To: camel-commits@activemq.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080927155741.55C8B238898F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Sat Sep 27 08:57:40 2008 New Revision: 699675 URL: http://svn.apache.org/viewvc?rev=699675&view=rev Log: CAMEL-941: camel-ftp now also supports expressions using file language to set dynamic filenames. Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java (with props) activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java (with props) Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileMessage.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java activemq/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java Sat Sep 27 08:57:40 2008 @@ -191,7 +191,8 @@ log.debug("Retrieved file: " + ftpFile.getName() + " from: " + remoteServer()); } - RemoteFileExchange exchange = endpoint.createExchange(fullFileName, byteArrayOutputStream); + RemoteFileExchange exchange = endpoint.createExchange(fullFileName, ftpFile.getName(), + ftpFile.getSize(), byteArrayOutputStream); if (isSetNames()) { // set the filename in the special header filename marker to the ftp filename @@ -217,7 +218,7 @@ } } else if (isMoveFile()) { String fromName = ftpFile.getName(); - String toName = getMoveFileName(fromName); + String toName = getMoveFileName(fromName, exchange); if (log.isDebugEnabled()) { log.debug("Moving file: " + fromName + " to: " + toName); } Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java Sat Sep 27 08:57:40 2008 @@ -50,6 +50,11 @@ protected RemoteFileEndpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { RemoteFileConfiguration config = getConfiguration().copy(); + + // get the uri part before the options as they can be non URI valid such as the expression using $ chars + if (uri.indexOf("?") != -1) { + uri = uri.substring(0, uri.indexOf("?")); + } config.configure(new URI(uri)); // lets make sure we copy the configuration as each endpoint can Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java Sat Sep 27 08:57:40 2008 @@ -18,7 +18,9 @@ import java.net.URI; +import org.apache.camel.Expression; import org.apache.camel.RuntimeCamelException; +import org.apache.camel.language.simple.FileLanguage; import org.apache.commons.net.ftp.FTPClientConfig; public class RemoteFileConfiguration implements Cloneable { @@ -31,6 +33,7 @@ private boolean binary; private boolean directory = true; private FTPClientConfig ftpClientConfig; + private Expression expression; public RemoteFileConfiguration() { } @@ -154,8 +157,19 @@ this.ftpClientConfig = ftpClientConfig; } - public String dump() { - return "RemoteFileConfiguration{" + "protocol='" + protocol + '\'' + ", username='" + username + '\'' + ", host='" + host + '\'' + ", port=" + port + ", password='" + password + '\'' - + ", file='" + file + '\'' + ", binary=" + binary + ", directory=" + directory + '}'; + + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + + /** + * Sets the expression based on {@link org.apache.camel.language.simple.FileLanguage} + */ + public void setExpression(String fileLanguageExpression) { + this.expression = FileLanguage.file(fileLanguageExpression); } } Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java Sat Sep 27 08:57:40 2008 @@ -19,6 +19,7 @@ import java.util.concurrent.ScheduledExecutorService; import org.apache.camel.Processor; +import org.apache.camel.Exchange; import org.apache.camel.impl.ScheduledPollConsumer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -94,16 +95,24 @@ * Should the file be moved after consuming? */ protected boolean isMoveFile() { - return moveNamePostfix != null || moveNamePrefix != null; + return moveNamePostfix != null || moveNamePrefix != null || endpoint.getConfiguration().getExpression() != null; } /** * Gets the to filename for moving. * * @param name the original filename + * @param exchange the current exchange * @return the move filename */ - protected String getMoveFileName(String name) { + protected String getMoveFileName(String name, Exchange exchange) { + // move according to the expression + if (endpoint.getConfiguration().getExpression() != null) { + Object result = endpoint.getConfiguration().getExpression() .evaluate(exchange); + return exchange.getContext().getTypeConverter().convertTo(String.class, result); + } + + // move according to the pre and postfix StringBuffer buffer = new StringBuffer(); if (moveNamePrefix != null) { buffer.append(moveNamePrefix); @@ -213,5 +222,4 @@ public void setTimestamp(boolean timestamp) { this.timestamp = timestamp; } - } Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java Sat Sep 27 08:57:40 2008 @@ -19,6 +19,8 @@ import java.io.ByteArrayOutputStream; import org.apache.camel.ExchangePattern; +import org.apache.camel.Message; +import org.apache.camel.util.UuidGenerator; import org.apache.camel.impl.ScheduledPollEndpoint; public abstract class RemoteFileEndpoint extends ScheduledPollEndpoint { @@ -51,8 +53,9 @@ return (T) new RemoteFileExchange(getCamelContext(), pattern, getBinding()); } - public T createExchange(String fullFileName, ByteArrayOutputStream outputStream) { - return (T) new RemoteFileExchange(getCamelContext(), getExchangePattern(), getBinding(), getConfiguration().getHost(), fullFileName, outputStream); + public T createExchange(String fullFileName, String fileName, long fileLength, ByteArrayOutputStream outputStream) { + return (T) new RemoteFileExchange(getCamelContext(), getExchangePattern(), getBinding(), + getConfiguration().getHost(), fullFileName, fileName, fileLength, outputStream); } public RemoteFileBinding getBinding() { @@ -77,4 +80,15 @@ public void setConfiguration(RemoteFileConfiguration configuration) { this.configuration = configuration; } + + /** + * Return the file name that will be auto-generated for the given message if none is provided + */ + public String getGeneratedFileName(Message message) { + return getFileFriendlyMessageId(message.getMessageId()); + } + + protected String getFileFriendlyMessageId(String id) { + return UuidGenerator.generateSanitizedId(id); + } } Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java Sat Sep 27 08:57:40 2008 @@ -30,9 +30,10 @@ this.binding = binding; } - public RemoteFileExchange(CamelContext context, ExchangePattern pattern, T binding, String host, String fullFileName, ByteArrayOutputStream outputStream) { + public RemoteFileExchange(CamelContext context, ExchangePattern pattern, T binding, String host, + String fullFileName, String fileName, long fileLength, ByteArrayOutputStream outputStream) { this(context, pattern, binding); - setIn(new RemoteFileMessage(host, fullFileName, outputStream)); + setIn(new RemoteFileMessage(host, fullFileName, fileName, fileLength, outputStream)); } public T getBinding() { Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileMessage.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileMessage.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileMessage.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileMessage.java Sat Sep 27 08:57:40 2008 @@ -24,16 +24,19 @@ public class RemoteFileMessage extends DefaultMessage { private OutputStream outputStream; private String fullFileName; + private String fileName; private String hostname; + private long fileLength; public RemoteFileMessage() { } - public RemoteFileMessage(String hostname, String fullFileName, OutputStream outputStream) { + public RemoteFileMessage(String hostname, String fullFileName, String fileName, long fileLength, OutputStream outputStream) { this.hostname = hostname; this.fullFileName = fullFileName; + this.fileName = fileName; + this.fileLength = fileLength; this.outputStream = outputStream; - setMessageId(hostname + ":" + fullFileName); } public String getHostname() { @@ -82,6 +85,18 @@ protected void populateInitialHeaders(Map map) { super.populateInitialHeaders(map); map.put("file.remote.host", hostname); - map.put("file.remote.name", fullFileName); + map.put("file.remote.fullName", fullFileName); + map.put("file.remote.name", fileName); + + map.put("CamelFileName", fileName); + map.put("CamelFilePath", fullFileName); + // set the parent if there is a parent folder + if (fullFileName != null && fullFileName.indexOf("/") != -1) { + String parent = fullFileName.substring(0, fullFileName.lastIndexOf("/")); + map.put("CamelFileParent", parent); + } + if (fileLength > 0) { + map.put("CamelFileLength", new Long(fileLength)); + } } } Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java Sat Sep 27 08:57:40 2008 @@ -16,9 +16,11 @@ */ package org.apache.camel.component.file.remote; +import org.apache.camel.Expression; import org.apache.camel.Message; import org.apache.camel.component.file.FileComponent; import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.language.simple.FileLanguage; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -33,19 +35,44 @@ protected String createFileName(Message message, RemoteFileConfiguration fileConfig) { String answer; - String endpointFileName = fileConfig.getFile(); - String headerFileName = message.getHeader(FileComponent.HEADER_FILE_NAME, String.class); + + String name = message.getHeader(FileComponent.HEADER_FILE_NAME, String.class); + + // expression support + Expression expression = endpoint.getConfiguration().getExpression(); + if (name != null) { + // the header name can be an expression too, that should override whatever configured on the endpoint + if (name.indexOf("${") > -1) { + if (log.isDebugEnabled()) { + log.debug(FileComponent.HEADER_FILE_NAME + " contains a FileLanguage expression: " + name); + } + expression = FileLanguage.file(name); + } + } + if (expression != null) { + if (log.isDebugEnabled()) { + log.debug("Filename evaluated as expression: " + expression); + } + Object result = expression.evaluate(message.getExchange()); + name = message.getExchange().getContext().getTypeConverter().convertTo(String.class, result); + } + + String endpointFile = fileConfig.getFile(); if (fileConfig.isDirectory()) { // If the path isn't empty, we need to add a trailing / if it isn't already there String baseDir = ""; - if (endpointFileName.length() > 0) { - baseDir = endpointFileName + (endpointFileName.endsWith("/") ? "" : "/"); + if (endpointFile.length() > 0) { + baseDir = endpointFile + (endpointFile.endsWith("/") ? "" : "/"); } - String fileName = (headerFileName != null) ? headerFileName : message.getMessageId(); + String fileName = (name != null) ? name : endpoint.getGeneratedFileName(message); answer = baseDir + fileName; } else { - answer = endpointFileName; + answer = endpointFile; } + + // lets store the name we really used in the header, so end-users can retrieve it + message.setHeader(FileComponent.HEADER_FILE_NAME_PRODUCED, answer); + return answer; } Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java Sat Sep 27 08:57:40 2008 @@ -188,7 +188,8 @@ log.debug("Retrieved file: " + sftpFile.getFilename() + " from: " + remoteServer()); } - RemoteFileExchange exchange = endpoint.createExchange(getFullFileName(sftpFile), byteArrayOutputStream); + RemoteFileExchange exchange = endpoint.createExchange(getFullFileName(sftpFile), + sftpFile.getFilename(), sftpFile.getAttrs().getSize(), byteArrayOutputStream); if (isSetNames()) { String ftpBasePath = endpoint.getConfiguration().getFile(); @@ -209,7 +210,7 @@ deleteFile(sftpFile.getFilename()); } else if (isMoveFile()) { String fromName = sftpFile.getFilename(); - String toName = getMoveFileName(fromName); + String toName = getMoveFileName(fromName, exchange); if (log.isDebugEnabled()) { log.debug("Moving file: " + fromName + " to: " + toName); } Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java?rev=699675&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java (added) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java Sat Sep 27 08:57:40 2008 @@ -0,0 +1,89 @@ +/** + * 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.file.remote; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.file.FileComponent; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; + +/** + * Unit test for FTP using expression (file language) + */ +public class FtpConsumerExpressionTest extends FtpServerTestSupport { + + private int port = 20063; + + private String ftpUrl = "ftp://admin@localhost:" + port + "/filelanguage?password=admin"; + + public int getPort() { + return port; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + deleteDirectory("res/home/filelanguage"); + deleteDirectory("target/filelanguage"); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("myguidgenerator", new MyGuidGenerator()); + return jndi; + } + + + public void testMoveUsingExpression() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Reports"); + + template.sendBodyAndHeader(ftpUrl, "Reports", FileComponent.HEADER_FILE_NAME, "report2.txt"); + + assertMockEndpointsSatisfied(); + + // give time for consumer to rename file + Thread.sleep(1000); + + String now = new SimpleDateFormat("yyyyMMdd").format(new Date()); + File file = new File("res/home/filelanguage/backup/" + now + "/123-report2.bak"); + file = file.getAbsoluteFile(); + assertTrue("File should have been renamed", file.exists()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(ftpUrl + "&expression=backup/${date:now:yyyyMMdd}/${bean:myguidgenerator}" + + "-${file:name.noext}.bak").to("mock:result"); + } + }; + } + + public class MyGuidGenerator { + public String guid() { + return "123"; + } + } + +} Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java?rev=699675&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java (added) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java Sat Sep 27 08:57:40 2008 @@ -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.component.file.remote; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Calendar; +import java.util.GregorianCalendar; + +import org.apache.camel.component.file.FileComponent; +import org.apache.camel.impl.JndiRegistry; + +/** + * Unit test for FTP using expression (file language) + */ +public class FtpProducerExpressionTest extends FtpServerTestSupport { + + private int port = 20062; + + private String ftpUrl = "ftp://admin@localhost:" + port + "/filelanguage?password=admin"; + + public int getPort() { + return port; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + deleteDirectory("res/home/filelanguage"); + deleteDirectory("target/filelanguage"); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("myguidgenerator", new MyGuidGenerator()); + return jndi; + } + + public void testProduceBeanByExpression() throws Exception { + template.sendBody(ftpUrl + "&expression=${bean:myguidgenerator}.bak", "Hello World"); + + Thread.sleep(500); + assertFileExists("res/home/filelanguage/123.bak"); + } + + public void testProduceBeanByHeader() throws Exception { + template.sendBodyAndHeader(ftpUrl, "Hello World", FileComponent.HEADER_FILE_NAME, "${bean:myguidgenerator}.bak"); + + Thread.sleep(500); + assertFileExists("res/home/filelanguage/123.bak"); + } + + public void testProducerDateByHeader() throws Exception { + template.sendBodyAndHeader(ftpUrl, "Hello World", FileComponent.HEADER_FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt"); + + Thread.sleep(500); + String date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + assertFileExists("res/home/filelanguage/myfile-" + date + ".txt"); + } + + public void testProducerDateByExpression() throws Exception { + template.sendBody(ftpUrl + "&expression=myfile-${date:now:yyyyMMdd}.txt", "Hello World"); + + Thread.sleep(500); + String date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + assertFileExists("res/home/filelanguage/myfile-" + date + ".txt"); + } + + public void testProducerComplexByExpression() throws Exception { + String expression = "../filelanguageinbox/myfile-${bean:myguidgenerator.guid}-${date:now:yyyyMMdd}.txt"; + template.sendBody(ftpUrl + "&expression=" + expression, "Hello World"); + + Thread.sleep(500); + String date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + assertFileExists("res/home/filelanguageinbox/myfile-123-" + date + ".txt"); + } + + public void testProducerSimpleWithHeaderByExpression() throws Exception { + template.sendBodyAndHeader(ftpUrl + "&expression=myfile-${in.header.foo}.txt", + "Hello World", "foo", "abc"); + + Thread.sleep(500); + assertFileExists("res/home/filelanguage/myfile-abc.txt"); + } + + public void testProducerWithDateHeader() throws Exception { + Calendar cal = GregorianCalendar.getInstance(); + cal.set(1974, Calendar.APRIL, 20); + Date date = cal.getTime(); + + template.sendBodyAndHeader(ftpUrl + "&expression=mybirthday-${date:in.header.birthday:yyyyMMdd}.txt", + "Hello World", "birthday", date); + + Thread.sleep(500); + assertFileExists("res/home/filelanguage/mybirthday-19740420.txt"); + } + + private static void assertFileExists(String filename) { + File file = new File(filename); + file = file.getAbsoluteFile(); + assertTrue("File " + filename + " should exists", file.exists()); + } + + public class MyGuidGenerator { + public String guid() { + return "123"; + } + } + +} \ No newline at end of file Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: activemq/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java?rev=699675&r1=699674&r2=699675&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java (original) +++ activemq/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java Sat Sep 27 08:57:40 2008 @@ -415,10 +415,6 @@ /** * Configures the dynamic context with exchange specific parameters - * - * @param dynamicQueryContext - * @param exchange - * @throws Exception */ protected void configureQuery(DynamicQueryContext dynamicQueryContext, Exchange exchange) throws Exception {