camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r979735 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/converter/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/converter/ components/camel-http/src/main/java/org/apache/camel/c...
Date Tue, 27 Jul 2010 14:51:10 GMT
Author: ningjiang
Date: Tue Jul 27 14:51:10 2010
New Revision: 979735

URL: http://svn.apache.org/viewvc?rev=979735&view=rev
Log:
CAMEL-2995 Cater the quotes, double quotes from charset

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
    camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
    camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
    camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
    camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Tue Jul
27 14:51:10 2010
@@ -341,7 +341,7 @@ public final class IOConverter {
         if (exchange != null) {
             String charsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
             if (charsetName != null) {
-                return charsetName;
+                return IOConverter.normalizeCharset(charsetName);
             }
         }
         if (useDefault) {
@@ -386,5 +386,25 @@ public final class IOConverter {
         }
 
     }
+
+    /**
+     * This method will take off the quotes and double quotes of the charset
+     * @param charset
+     * @return
+     */
+    public static String normalizeCharset(String charset) {
+        if (charset != null) {
+            String answer = charset.trim();
+            if (answer.startsWith("'") || answer.startsWith("\"")) {
+                answer = answer.substring(1);
+            }
+            if (answer.endsWith("'") || answer.endsWith("\"")) {
+                answer = answer.substring(0, answer.length() - 1);
+            }
+            return answer.trim();
+        } else {
+            return null;
+        }
+    }
     
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
Tue Jul 27 14:51:10 2010
@@ -19,6 +19,7 @@ package org.apache.camel.processor;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
+import org.apache.camel.converter.IOConverter;
 
 /**
  * A processor which converts the payload of the input message to be of the given type
@@ -49,7 +50,7 @@ public class ConvertBodyProcessor implem
     public void process(Exchange exchange) throws Exception {
         Message in = exchange.getIn();
         if (charset != null) {
-            exchange.setProperty(Exchange.CHARSET_NAME, charset);
+            exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(charset));
         }
 
         // only convert if the is a body

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java Tue
Jul 27 14:51:10 2010
@@ -196,5 +196,12 @@ public class IOConverterTest extends Con
         assertNotNull(data);
         assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, data));
     }
+    
+    public void testCharsetNormalize() throws Exception {
+        assertEquals("UTF-8", IOConverter.normalizeCharset("'UTF-8'"));
+        assertEquals("UTF-8", IOConverter.normalizeCharset("\"UTF-8\""));
+        assertEquals("UTF-8", IOConverter.normalizeCharset("\"UTF-8 \""));
+        assertEquals("UTF-8", IOConverter.normalizeCharset("\' UTF-8\'"));
+    }
 
 }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
Tue Jul 27 14:51:10 2010
@@ -218,7 +218,7 @@ public class HttpProducer extends Defaul
             int index = contentType.indexOf("charset=");
             if (index > 0) {
                 String charset = contentType.substring(index + 8);
-                exchange.setProperty(Exchange.CHARSET_NAME, charset);
+                exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(charset));
             }
         }
         return doExtractResponseBody(is, exchange);

Modified: camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
(original)
+++ camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
Tue Jul 27 14:51:10 2010
@@ -219,7 +219,7 @@ public class HttpProducer extends Defaul
             int index = contentType.indexOf("charset=");
             if (index > 0) {
                 String charset = contentType.substring(index + 8);
-                exchange.setProperty(Exchange.CHARSET_NAME, charset);
+                exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(charset));
             }
         }
         return doExtractResponseBody(is, exchange);

Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
(original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
Tue Jul 27 14:51:10 2010
@@ -165,7 +165,7 @@ public class MailBinding {
 
             // after is the charset lets see if its given and a valid charset
             if (after != null) {
-                String charset = ObjectHelper.after(after, "=");
+                String charset = IOConverter.normalizeCharset(ObjectHelper.after(after, "="));
                 if (charset != null) {
                     boolean supported;
                     try {

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
(original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
Tue Jul 27 14:51:10 2010
@@ -21,6 +21,7 @@ import java.net.SocketAddress;
 import org.apache.camel.CamelException;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.DefaultConsumer;
 import org.apache.camel.processor.Logger;
 import org.apache.camel.util.ExchangeHelper;
@@ -106,7 +107,7 @@ public class MinaConsumer extends Defaul
             Exchange exchange = endpoint.createExchange(session, object);
             //Set the exchange charset property for converting
             if (endpoint.getConfiguration().getCharsetName() != null) {
-                exchange.setProperty(Exchange.CHARSET_NAME, endpoint.getConfiguration().getCharsetName());
+                exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(endpoint.getConfiguration().getCharsetName()));
             }
 
             try {

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
(original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
Tue Jul 27 14:51:10 2010
@@ -24,6 +24,7 @@ import org.apache.camel.CamelExchangeExc
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangeTimedOutException;
 import org.apache.camel.ServicePoolAware;
+import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.processor.Logger;
 import org.apache.camel.util.ExchangeHelper;
@@ -78,7 +79,7 @@ public class MinaProducer extends Defaul
 
         // set the exchange encoding property
         if (endpoint.getConfiguration().getCharsetName() != null) {
-            exchange.setProperty(Exchange.CHARSET_NAME, endpoint.getConfiguration().getCharsetName());
+            exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(endpoint.getConfiguration().getCharsetName()));
         }
 
         Object body = MinaPayloadHelper.getIn(endpoint, exchange);

Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
(original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
Tue Jul 27 14:51:10 2010
@@ -26,6 +26,7 @@ import org.apache.camel.CamelException;
 import org.apache.camel.Exchange;
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.ServicePoolAware;
+import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.DefaultAsyncProducer;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.processor.Logger;
@@ -143,7 +144,7 @@ public class NettyProducer extends Defau
 
         // set the exchange encoding property
         if (getConfiguration().getCharsetName() != null) {
-            exchange.setProperty(Exchange.CHARSET_NAME, getConfiguration().getCharsetName());
+            exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(getConfiguration().getCharsetName()));
         }
 
         ChannelFuture channelFuture;

Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
(original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
Tue Jul 27 14:51:10 2010
@@ -22,6 +22,7 @@ import org.apache.camel.component.netty.
 import org.apache.camel.component.netty.NettyConsumer;
 import org.apache.camel.component.netty.NettyHelper;
 import org.apache.camel.component.netty.NettyPayloadHelper;
+import org.apache.camel.converter.IOConverter;
 import org.apache.camel.processor.Logger;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.commons.logging.Log;
@@ -89,7 +90,7 @@ public class ServerChannelHandler extend
         }
         // set the exchange charset property for converting
         if (consumer.getConfiguration().getCharsetName() != null) {
-            exchange.setProperty(Exchange.CHARSET_NAME, consumer.getConfiguration().getCharsetName());
+            exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(consumer.getConfiguration().getCharsetName()));
         }
 
         try {

Modified: camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java?rev=979735&r1=979734&r2=979735&view=diff
==============================================================================
--- camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java
(original)
+++ camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java
Tue Jul 27 14:51:10 2010
@@ -31,6 +31,7 @@ import com.thoughtworks.xstream.io.xml.S
 import com.thoughtworks.xstream.io.xml.StaxWriter;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.converter.IOConverter;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.DataFormat;
 
@@ -85,7 +86,7 @@ public class XStreamDataFormat extends A
     // just make sure the exchange property can override the xmlstream encoding setting
     protected void updateCharactorEncodingInfo(Exchange exchange) {
         if (exchange.getProperty(Exchange.CHARSET_NAME) == null && encoding != null)
{
-            exchange.setProperty(Exchange.CHARSET_NAME, encoding);
+            exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(encoding));
         }
     }
 



Mime
View raw message