camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r759901 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/model/dataformat/ components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/ components/camel-jaxb/src/test/java/org/apache/camel/example/ compon...
Date Mon, 30 Mar 2009 09:54:55 GMT
Author: davsclaus
Date: Mon Mar 30 09:54:54 2009
New Revision: 759901

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

........
  r759887 | davsclaus | 2009-03-30 11:18:46 +0200 (Mon, 30 Mar 2009) | 1 line
  
  CAMEL-1500: Added encoding option to JAXB data format. Thanks to Tobias Emmerich for providing
details how to do this.
........

Added:
    camel/branches/camel-1.x/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java
      - copied, changed from r759887, camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java
    camel/branches/camel-1.x/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml
      - copied, changed from r759887, camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml
Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
    camel/branches/camel-1.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
    camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
    camel/branches/camel-1.x/components/camel-xmpp/src/test/resources/   (props changed)

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Mar 30 09:54:54 2009
@@ -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
+/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

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/model/dataformat/JaxbDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java?rev=759901&r1=759900&r2=759901&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
Mon Mar 30 09:54:54 2009
@@ -38,6 +38,8 @@
     private Boolean prettyPrint;
     @XmlAttribute(required = false)
     private Boolean ignoreJAXBElement;
+    @XmlAttribute(required = false)
+    private String encoding;
 
     public JaxbDataFormat() {
         super("org.apache.camel.converter.jaxb.JaxbDataFormat");
@@ -85,7 +87,10 @@
             setProperty(dataFormat, "ignoreJAXBElement", Boolean.FALSE);
         } else { // the default value is true
             setProperty(dataFormat, "ignoreJAXBElement", Boolean.TRUE);
-        } 
+        }
+        if (encoding != null) {
+            setProperty(dataFormat, "encoding", encoding);
+        }
         setProperty(dataFormat, "contextPath", contextPath);
     }
 }
\ No newline at end of file

Modified: camel/branches/camel-1.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java?rev=759901&r1=759900&r2=759901&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
(original)
+++ camel/branches/camel-1.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
Mon Mar 30 09:54:54 2009
@@ -22,6 +22,7 @@
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
@@ -38,6 +39,7 @@
     private String contextPath;
     private boolean prettyPrint = true;
     private boolean ignoreJAXBElement = true;
+    private String encoding;
 
     public JaxbDataFormat() {
     }
@@ -53,7 +55,19 @@
     public void marshal(Exchange exchange, Object graph, OutputStream stream) throws IOException
{
         try {
             // must create a new instance of marshaller as its not thred safe
-            getContext().createMarshaller().marshal(graph, stream);
+            Marshaller marshaller = getContext().createMarshaller();
+
+            // exchange take precedense over encoding option
+            String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
+            if (charset == null) {
+                charset = encoding;
+            }
+            if (charset != null) {
+                marshaller.setProperty(Marshaller.JAXB_ENCODING, charset);
+            }
+
+            marshaller.marshal(graph, stream);
+
         } catch (JAXBException e) {
             throw IOHelper.createIOException(e);
         }
@@ -109,6 +123,14 @@
         this.prettyPrint = prettyPrint;
     }
 
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
     protected JAXBContext createContext() throws JAXBException {
         if (contextPath != null) {
             return JAXBContext.newInstance(contextPath);

Copied: camel/branches/camel-1.x/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java
(from r759887, camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java?p2=camel/branches/camel-1.x/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java&p1=camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java&r1=759887&r2=759901&rev=759901&view=diff
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-jaxb/src/test/java/org/apache/camel/example/SpringDataFormatWithEncodingTest.java
Mon Mar 30 09:54:54 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.example;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spring.SpringTestSupport;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -42,7 +43,7 @@
     }
 
     public void testMarshalWithEncodingPropertyInExchange() throws Exception {
-        PurchaseOrder bean = new PurchaseOrder();
+        final PurchaseOrder bean = new PurchaseOrder();
         bean.setName("Beer");
         bean.setAmount(23);
         bean.setPrice(2.5);
@@ -51,8 +52,13 @@
         mock.expectedBodiesReceived("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"
                 + "<purchaseOrder amount=\"23.0\" price=\"2.5\" name=\"Beer\"/>");
 
-        // the property should override the jaxb configuration
-        template.sendBodyAndProperty("direct:start", bean, Exchange.CHARSET_NAME, "utf-8");
+        template.send("direct:start", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(bean);
+                // the property should override the jaxb configuration
+                exchange.setProperty(Exchange.CHARSET_NAME, "utf-8");
+            }
+        });
 
         mock.assertIsSatisfied();
     }

Copied: camel/branches/camel-1.x/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml
(from r759887, camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml?p2=camel/branches/camel-1.x/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml&p1=camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml&r1=759887&r2=759901&rev=759901&view=diff
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml
(original)
+++ camel/branches/camel-1.x/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml
Mon Mar 30 09:54:54 2009
@@ -19,11 +19,11 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
-       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
     ">
 
     <!-- START SNIPPET: example -->
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
         <route>
             <from uri="direct:start"/>
             <marshal>

Modified: camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=759901&r1=759900&r2=759901&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
(original)
+++ camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
Mon Mar 30 09:54:54 2009
@@ -74,7 +74,7 @@
     private static final transient Log LOG = LogFactory.getLog(JettyHttpComponent.class);
     
     protected Server server;
-    protected HashMap<String, ConnectorRef> connectors = new HashMap<String, ConnectorRef>();
   
+    protected final HashMap<String, ConnectorRef> connectors = new HashMap<String,
ConnectorRef>();
     protected String sslKeyPassword;
     protected String sslPassword;
     protected String sslKeystore;

Propchange: camel/branches/camel-1.x/components/camel-xmpp/src/test/resources/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Mar 30 09:54:54 2009
@@ -1 +1 @@
-/camel/trunk/components/camel-xmpp/src/test/resources:757693,757743,757865,758539,758563,758617,758692,758990,759362
+/camel/trunk/components/camel-xmpp/src/test/resources:757693,757743,757865,758539,758563,758617,758692,758990,759362,759887



Mime
View raw message