camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r903977 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/converter/ camel-core/src/main/java/org/apache/camel/converter/jaxp/ components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/ components...
Date Thu, 28 Jan 2010 07:12:22 GMT
Author: ningjiang
Date: Thu Jan 28 07:12:21 2010
New Revision: 903977

URL: http://svn.apache.org/viewvc?rev=903977&view=rev
Log:
Merged revisions 903970 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r903970 | ningjiang | 2010-01-28 14:32:57 +0800 (Thu, 28 Jan 2010) | 1 line
  
  CAMEL-2407 support character encoding in XStreamDataFormat
........

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
    camel/branches/camel-1.x/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java
    camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObjectTest.java
    camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 28 07:12:21 2010
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781314-781349,781775,781
 923,781974,781993,782557,782594,782681,782886,782918-782923,783204,783248,783363,783639,783704,785564,785584,785599,787206,787581,787598,787605,787928,788393,789121,789703,790560,790936,791379,791476,791767,792038,792381,792398,792899,793359,793518,793547-793555,793862,793935,794237,794368,794550,794967,795790,798027,798052,798063,798489,798864,799252,800340,800785,800797,801084,801196,801960,802307,802478,803559,807476,810751,812937,814493,816105,817654,818063,818182-818354,818744,818747,819475,819956,820152,820168,821272,821290,822655,823013,823018,823031,823102,823177,823575,824218,824721,825760,825765,828288,828333,832647,833285,833289,833350,833370,833381,833419,835511,880655,880667,883713,884525,884750,885876,887196,895119,896772,898201,901634,902688,903638
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781314-781349,781775,781
 923,781974,781993,782557,782594,782681,782886,782918-782923,783204,783248,783363,783639,783704,785564,785584,785599,787206,787581,787598,787605,787928,788393,789121,789703,790560,790936,791379,791476,791767,792038,792381,792398,792899,793359,793518,793547-793555,793862,793935,794237,794368,794550,794967,795790,798027,798052,798063,798489,798864,799252,800340,800785,800797,801084,801196,801960,802307,802478,803559,807476,810751,812937,814493,816105,817654,818063,818182-818354,818744,818747,819475,819956,820152,820168,821272,821290,822655,823013,823018,823031,823102,823177,823575,824218,824721,825760,825765,828288,828333,832647,833285,833289,833350,833370,833381,833419,835511,880655,880667,883713,884525,884750,885876,887196,895119,896772,898201,901634,902688,903638,903970

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=903977&r1=903976&r2=903977&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
Thu Jan 28 07:12:21 2010
@@ -42,6 +42,8 @@
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.net.URL;
+import java.nio.charset.Charset;
+
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.dom.DOMSource;
 
@@ -276,4 +278,18 @@
         }
         os.flush();
     }
+    
+    public static String getCharsetName(Exchange exchange) {
+        if (exchange != null) {
+            String charsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
+            if (charsetName != null) {
+                return charsetName;
+            }
+        }
+        return getDefaultCharsetName();
+    }
+    
+    public static String getDefaultCharsetName() {
+        return Charset.defaultCharset().toString();
+    }
 }

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java?rev=903977&r1=903976&r2=903977&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
Thu Jan 28 07:12:21 2010
@@ -32,6 +32,8 @@
 import javax.xml.transform.Source;
 
 import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.converter.IOConverter;
 
 /**
  * A converter of StAX objects
@@ -44,6 +46,11 @@
     private XMLOutputFactory outputFactory;
 
     @Converter
+    public XMLEventWriter createXMLEventWriter(OutputStream out, Exchange exchange) throws
XMLStreamException {
+        return getOutputFactory().createXMLEventWriter(out, IOConverter.getCharsetName(exchange));
+    }
+    
+    @Converter
     public XMLEventWriter createXMLEventWriter(OutputStream out) throws XMLStreamException
{
         return getOutputFactory().createXMLEventWriter(out);
     }
@@ -57,13 +64,18 @@
     public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException {
         return getOutputFactory().createXMLEventWriter(result);
     }
-
+    
     @Converter
     public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream) throws XMLStreamException
{
         return getOutputFactory().createXMLStreamWriter(outputStream);
     }
 
     @Converter
+    public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream, Exchange exchange)
throws XMLStreamException {
+        return getOutputFactory().createXMLStreamWriter(outputStream, IOConverter.getCharsetName(exchange));
+    }
+
+    @Converter
     public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException
{
         return getOutputFactory().createXMLStreamWriter(writer);
     }
@@ -77,6 +89,11 @@
     public XMLStreamReader createXMLStreamReader(InputStream in) throws XMLStreamException
{
         return getInputFactory().createXMLStreamReader(in);
     }
+    
+    @Converter
+    public XMLStreamReader createXMLStreamReader(InputStream in, Exchange exchange) throws
XMLStreamException {
+        return getInputFactory().createXMLStreamReader(in, IOConverter.getCharsetName(exchange));
+    }
 
     @Converter
     public XMLStreamReader createXMLStreamReader(Reader in) throws XMLStreamException {
@@ -87,13 +104,18 @@
     public XMLStreamReader createXMLStreamReader(Source in) throws XMLStreamException {
         return getInputFactory().createXMLStreamReader(in);
     }
-
+    
     @Converter
     public XMLEventReader createXMLEventReader(InputStream in) throws XMLStreamException
{
         return getInputFactory().createXMLEventReader(in);
     }
 
     @Converter
+    public XMLEventReader createXMLEventReader(InputStream in, Exchange exchange) throws
XMLStreamException {
+        return getInputFactory().createXMLEventReader(in, IOConverter.getCharsetName(exchange));
+    }
+
+    @Converter
     public XMLEventReader createXMLEventReader(Reader in) throws XMLStreamException {
         return getInputFactory().createXMLEventReader(in);
     }

Modified: camel/branches/camel-1.x/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java?rev=903977&r1=903976&r2=903977&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java
(original)
+++ camel/branches/camel-1.x/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java
Thu Jan 28 07:12:21 2010
@@ -76,12 +76,12 @@
     }    
 
     protected HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange,
Object body, OutputStream stream) throws XMLStreamException {
-        XMLStreamWriter xmlWriter = getStaxConverter().createXMLStreamWriter(stream);
+        XMLStreamWriter xmlWriter = getStaxConverter().createXMLStreamWriter(stream, exchange);
         return new StaxWriter(new QNameMap(), xmlWriter);
     }
 
     protected HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange,
InputStream stream) throws XMLStreamException {
-        XMLStreamReader xmlReader = getStaxConverter().createXMLStreamReader(stream);
+        XMLStreamReader xmlReader = getStaxConverter().createXMLStreamReader(stream, exchange);
         return new StaxReader(new QNameMap(), xmlReader);
     }
 }

Modified: camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObjectTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObjectTest.java?rev=903977&r1=903976&r2=903977&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObjectTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObjectTest.java
Thu Jan 28 07:12:21 2010
@@ -83,7 +83,7 @@
             public void configure() throws Exception {
                 from("direct:in").marshal().xstream().to("mock:result");
 
-                // just used for helping to marhsal
+                // just used for helping to marshal
                 from("direct:marshal").marshal().xstream();
 
                 from("direct:reverse").unmarshal().xstream().to("mock:reverse");

Modified: camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java?rev=903977&r1=903976&r2=903977&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java
Thu Jan 28 07:12:21 2010
@@ -22,6 +22,9 @@
 import java.util.Map;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
@@ -33,13 +36,20 @@
     public void testMarshalList() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("<?xml version='1.0' encoding='UTF-8'?>"
+        mock.expectedBodiesReceived("<?xml version='1.0' encoding='ISO-8859-1'?>"
             + "<list><string>Hello World</string></list>");
 
-        List<String> body = new ArrayList<String>();
+        final List<String> body = new ArrayList<String>();
         body.add("Hello World");
 
-        template.sendBody("direct:in", body);
+        template.send("direct:in", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOnly);
+                exchange.getIn().setBody(body);
+                exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
+            }
+        });
+       
 
         mock.assertIsSatisfied();
     }
@@ -49,15 +59,21 @@
         mock.expectedMessageCount(1);
         mock.expectedBodiesReceived(
             "<?xml version='1.0' encoding='UTF-8'?><list><map><entry><string>city</string>"
-                + "<string>London</string></entry></map></list>");
+                + "<string>London\u0E08</string></entry></map></list>");
 
-        List<Map<Object, String>> body = new ArrayList<Map<Object, String>>();
+        final List<Map<Object, String>> body = new ArrayList<Map<Object,
String>>();
         Map<Object, String> row = new HashMap<Object, String>();
-        row.put("city", "London");
+        row.put("city", "London\u0E08");
         body.add(row);
 
-        template.sendBody("direct:in", body);
-
+        template.send("direct:in", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOnly);
+                exchange.getIn().setBody(body);
+                exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
+            }
+        });
+        
         mock.assertIsSatisfied();
     }
 



Mime
View raw message