camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r904453 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/model/dataformat/ components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/ components...
Date Fri, 29 Jan 2010 10:33:48 GMT
Author: ningjiang
Date: Fri Jan 29 10:33:40 2010
New Revision: 904453

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

........
  r904442 | ningjiang | 2010-01-29 18:03:19 +0800 (Fri, 29 Jan 2010) | 1 line
  
  CAMEL-2407 support the encoding property in xstream dataformat
........

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.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 Fri Jan 29 10:33:40 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,903970,904365,904440
+/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,904365,904440,904442

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/builder/DataFormatClause.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java?rev=904453&r1=904452&r2=904453&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
Fri Jan 29 10:33:40 2010
@@ -181,7 +181,14 @@
     }
     
     /**
-     * Uses the JSON data format
+     * Uses the xstream by setting the encoding
+     */
+    public T xstream(String encoding) {
+        return dataFormat(new XStreamDataFormat(encoding));
+    }
+    
+    /**
+     * Uses the JSON data format 
      */
     public T json() {
         return dataFormat(new JsonDataFormat());

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java?rev=904453&r1=904452&r2=904453&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java
Fri Jan 29 10:33:40 2010
@@ -31,18 +31,31 @@
 @XmlRootElement(name = "xstream")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class XStreamDataFormat extends DataFormatType {
-    @XmlAttribute(required = false)
-    private Boolean prettyPrint;
+    @XmlAttribute
+    private String encoding;
 
     public XStreamDataFormat() {
         super("org.apache.camel.dataformat.xstream.XStreamDataFormat");
     }
-
-    public Boolean getPrettyPrint() {
-        return prettyPrint;
+    
+    public XStreamDataFormat(String encoding) {
+        this();
+        setEncoding(encoding);
+    }
+    
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
     }
 
-    public void setPrettyPrint(Boolean prettyPrint) {
-        this.prettyPrint = prettyPrint;
+    public String getEncoding() {
+        return encoding;
+    }
+    
+    @Override
+    protected void configureDataFormat(DataFormat dataFormat) {
+        if (encoding != null) {
+            setProperty(dataFormat, "encoding", encoding);
+        }
     }
+        
 }
\ No newline at end of file

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=904453&r1=904452&r2=904453&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
Fri Jan 29 10:33:40 2010
@@ -42,6 +42,7 @@
  * @version $Revision$
  */
 public class XStreamDataFormat extends AbstractXStreamWrapper  {
+    String encoding;
     
     public XStreamDataFormat() {
         super();
@@ -50,6 +51,14 @@
     public XStreamDataFormat(XStream xstream) {
         super(xstream);
     }
+    
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+    
+    public String getEncoding() {
+        return encoding;
+    }
 
     /**
      * A factory method which takes a collection of types to be annotated
@@ -73,14 +82,23 @@
             xstream.processAnnotations(type);
         }
         return answer;
-    }    
+    }
+    
+    // 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);
+        }
+    }
 
     protected HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange,
Object body, OutputStream stream) throws XMLStreamException {
+        updateCharactorEncodingInfo(exchange);
         XMLStreamWriter xmlWriter = getStaxConverter().createXMLStreamWriter(stream, exchange);
         return new StaxWriter(new QNameMap(), xmlWriter);
     }
 
     protected HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange,
InputStream stream) throws XMLStreamException {
+        updateCharactorEncodingInfo(exchange);
         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=904453&r1=904452&r2=904453&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
Fri Jan 29 10:33:40 2010
@@ -21,7 +21,7 @@
 import org.apache.camel.component.mock.MockEndpoint;
 
 /**
- * Marhsal tests with domain objects.
+ * Marshal tests with domain objects.
  */
 public class MarshalDomainObjectTest extends ContextTestSupport {
 
@@ -84,9 +84,9 @@
                 from("direct:in").marshal().xstream().to("mock:result");
 
                 // just used for helping to marshal
-                from("direct:marshal").marshal().xstream();
+                from("direct:marshal").marshal().xstream("UTF-8");
 
-                from("direct:reverse").unmarshal().xstream().to("mock:reverse");
+                from("direct:reverse").unmarshal().xstream("UTF-8").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=904453&r1=904452&r2=904453&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
Fri Jan 29 10:33:40 2010
@@ -76,11 +76,29 @@
         
         mock.assertIsSatisfied();
     }
+    
+    public void testSetEncodingOnXstream() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived(
+            "<?xml version='1.0' encoding='UTF-8'?><list><map><entry><string>city</string>"
+                + "<string>London\u0E08</string></entry></map></list>");
+
+        List<Map<Object, String>> body = new ArrayList<Map<Object, String>>();
+        Map<Object, String> row = new HashMap<Object, String>();
+        row.put("city", "London\u0E08");
+        body.add(row);
+
+        template.sendBody("direct:in-UTF-8", body);
+
+        mock.assertIsSatisfied();
+    }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
                 from("direct:in").marshal().xstream().to("mock:result");
+                from("direct:in-UTF-8").marshal().xstream("UTF-8").to("mock:result");
             }
         };
     }



Mime
View raw message