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/05/31 17:08:12 UTC
svn commit: r662034 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/component/file/
camel-core/src/main/java/org/apache/camel/util/
camel-core/src/test/java/org/apache/camel/util/
components/camel-jms/src/test/java/org/apache/came...
Author: davsclaus
Date: Sat May 31 08:08:12 2008
New Revision: 662034
URL: http://svn.apache.org/viewvc?rev=662034&view=rev
Log:
CAMEL-562: FileProducer now handles unfriendly file message ids from eg camel-jms that results in failure to produce files.
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java (with props)
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java?rev=662034&r1=662033&r2=662034&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java Sat May 31 08:08:12 2008
@@ -28,6 +28,7 @@
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.UuidGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -114,10 +115,10 @@
if (name != null) {
answer = new File(endpointFile, name);
if (answer.isDirectory()) {
- answer = new File(answer, message.getMessageId());
+ answer = new File(answer, getFileFriendlyMessageId(message.getMessageId()));
}
} else {
- answer = new File(endpointFile, message.getMessageId());
+ answer = new File(endpointFile, getFileFriendlyMessageId(message.getMessageId()));
}
} else {
if (name == null) {
@@ -140,4 +141,8 @@
}
}
+ private static String getFileFriendlyMessageId(String id) {
+ return UuidGenerator.generateSanitizedId(id);
+ }
+
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java?rev=662034&r1=662033&r2=662034&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java Sat May 31 08:08:12 2008
@@ -97,11 +97,20 @@
* @return a unique id
*/
public String generateSanitizedId() {
- String result = generateId();
- result = result.replace(':', '-');
- result = result.replace('_', '-');
- result = result.replace('.', '-');
- return result;
+ return generateSanitizedId(generateId());
+ }
+
+ /**
+ * Ensures that the id is friendly for a URL or file system
+ *
+ * @param id the unique id
+ * @return the id as file friendly id
+ */
+ public static String generateSanitizedId(String id) {
+ id = id.replace(':', '-');
+ id = id.replace('_', '-');
+ id = id.replace('.', '-');
+ return id;
}
}
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java?rev=662034&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java Sat May 31 08:08:12 2008
@@ -0,0 +1,48 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for UuidGenerator
+ */
+public class UuidGeneratorTest extends TestCase {
+
+ private UuidGenerator generator;
+
+ protected void setUp() throws Exception {
+ generator = new UuidGenerator("unittest");
+ }
+
+ public void testUniqueId() {
+ assertNotSame("Should generate unique ids", generator.generateId(), generator.generateId());
+ }
+
+ public void testSimpleSanitizedId() {
+ String out = UuidGenerator.generateSanitizedId("hello");
+ assertTrue("Should not contain : ", out.indexOf(':') == -1);
+ assertTrue("Should not contain . ", out.indexOf('.') == -1);
+ }
+
+ public void testNotFileFriendlySimpleSanitizedId() {
+ String out = UuidGenerator.generateSanitizedId("c:\\helloworld");
+ assertTrue("Should not contain : ", out.indexOf(':') == -1);
+ assertTrue("Should not contain . ", out.indexOf('.') == -1);
+ }
+
+}
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java?rev=662034&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java (added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java Sat May 31 08:08:12 2008
@@ -0,0 +1,70 @@
+/**
+ * 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.jms;
+
+import java.io.File;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.CamelContext;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.IOConverter;
+import org.apache.activemq.ActiveMQConnectionFactory;
+
+/**
+ * Unit test that we can consume JMS message and store it as file (to avoid regression bug)
+ */
+public class JmsRouteToFileTest extends ContextTestSupport {
+
+ protected String componentName = "activemq";
+
+ public void testRouteToFile() throws Exception {
+ deleteDirectory("target/routetofile");
+
+ template.sendBody("activemq:queue:hello", "Hello World");
+
+ // pause to let file producer save the file
+ Thread.sleep(1500);
+
+ // do file assertions
+ File dir = new File("./target/routetofile");
+ assertTrue("Should be directory", dir.isDirectory());
+ File file = dir.listFiles()[0];
+ assertTrue("File should exists", file.exists());
+ String body = IOConverter.toString(file);
+ assertEquals("Hello World", body);
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+
+ ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+ camelContext.addComponent(componentName, jmsComponentClientAcknowledge(connectionFactory));
+
+ return camelContext;
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("activemq:queue:hello").to("file://target/routetofile");
+ }
+ };
+ }
+}
Propchange: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteToFileTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date