You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/05/14 08:15:58 UTC
svn commit: r944131 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/converter/jaxp/ main/java/org/apache/camel/util/
test/java/org/apache/camel/converter/
test/java/org/apache/camel/converter/jaxp/
Author: ningjiang
Date: Fri May 14 06:15:58 2010
New Revision: 944131
URL: http://svn.apache.org/viewvc?rev=944131&view=rev
Log:
CAMEL-2720 supports to set the XSL Output options from camel properties.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ObjectHelperTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java?rev=944131&r1=944130&r2=944131&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java Fri May 14 06:15:58 2010
@@ -67,6 +67,7 @@ public class XmlConverter {
//It will be removed in Camel 3.0, please use the Exchange.DEFAULT_CHARSET
public static final String DEFAULT_CHARSET_PROPERTY = "org.apache.camel.default.charset";
+ public static final String OUTPUT_PROPERTIES_PREFIX = "org.apache.camel.xmlconverter.output.";
public static String defaultCharset = ObjectHelper.getSystemProperty(Exchange.DEFAULT_CHARSET_PROPERTY, "UTF-8");
/*
@@ -170,12 +171,21 @@ public class XmlConverter {
public Source toSource(Node node) {
return new DOMSource(node);
}
+
+ /**
+ * Converts the given input Source into text
+ */
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
+ public String toString(Source source) throws TransformerException {
+ return toString(source, null);
+ }
/**
* Converts the given input Source into text
*/
@Converter
- public String toString(Source source) throws TransformerException {
+ public String toString(Source source, Exchange exchange) throws TransformerException {
if (source == null) {
return null;
} else if (source instanceof StringSource) {
@@ -183,8 +193,17 @@ public class XmlConverter {
} else if (source instanceof BytesSource) {
return new String(((BytesSource) source).getData());
} else {
- StringWriter buffer = new StringWriter();
- toResult(source, new StreamResult(buffer));
+ StringWriter buffer = new StringWriter();
+ if (exchange != null) {
+ // check the camelContext properties first
+ Properties properties = ObjectHelper.getCamelPropertiesWithPrefix(OUTPUT_PROPERTIES_PREFIX, exchange.getContext());
+ if (properties.size() > 0) {
+ toResult(source, new StreamResult(buffer), properties);
+ return buffer.toString();
+ }
+ }
+ // using the old way to deal with it
+ toResult(source, new StreamResult(buffer));
return buffer.toString();
}
}
@@ -194,20 +213,29 @@ public class XmlConverter {
*/
@Converter
public byte[] toByteArray(Source source, Exchange exchange) throws TransformerException {
- String answer = toString(source);
+ String answer = toString(source, exchange);
if (exchange != null) {
return exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, answer);
} else {
return answer.getBytes();
}
}
-
+
/**
* Converts the given input Node into text
*/
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public String toString(Node node) throws TransformerException {
- return toString(new DOMSource(node));
+ return toString(node, null);
+ }
+
+ /**
+ * Converts the given input Node into text
+ */
+ @Converter
+ public String toString(Node node, Exchange exchange) throws TransformerException {
+ return toString(new DOMSource(node), exchange);
}
/**
@@ -241,34 +269,66 @@ public class XmlConverter {
}
}
+
/**
* Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
* supported (making it easy to derive from this class to add new kinds of conversion).
*/
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public SAXSource toSAXSource(String source) throws IOException, SAXException, TransformerException {
- return toSAXSource(toSource(source));
+ return toSAXSource(source, null);
}
-
+
/**
* Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
* supported (making it easy to derive from this class to add new kinds of conversion).
*/
@Converter
+ public SAXSource toSAXSource(String source, Exchange exchange) throws IOException, SAXException, TransformerException {
+ return toSAXSource(toSource(source), exchange);
+ }
+
+ /**
+ * Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
+ * supported (making it easy to derive from this class to add new kinds of conversion).
+ */
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public SAXSource toSAXSource(InputStream source) throws IOException, SAXException, TransformerException {
- return toSAXSource(toStreamSource(source));
+ return toSAXSource(source, null);
}
-
+
/**
* Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
* supported (making it easy to derive from this class to add new kinds of conversion).
*/
@Converter
+ public SAXSource toSAXSource(InputStream source, Exchange exchange) throws IOException, SAXException, TransformerException {
+ return toSAXSource(toStreamSource(source), exchange);
+ }
+
+ /**
+ * Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
+ * supported (making it easy to derive from this class to add new kinds of conversion).
+ */
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
+ @Converter
public SAXSource toSAXSource(Source source) throws IOException, SAXException, TransformerException {
+ return toSAXSource(source, null);
+ }
+
+ /**
+ * Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
+ * supported (making it easy to derive from this class to add new kinds of conversion).
+ */
+ @Converter
+ public SAXSource toSAXSource(Source source, Exchange exchange) throws IOException, SAXException, TransformerException {
if (source instanceof SAXSource) {
return (SAXSource) source;
} else if (source instanceof DOMSource) {
- return toSAXSourceFromDOM((DOMSource) source);
+ return toSAXSourceFromDOM((DOMSource) source, exchange);
} else if (source instanceof StreamSource) {
return toSAXSourceFromStream((StreamSource) source);
} else {
@@ -276,14 +336,20 @@ public class XmlConverter {
}
}
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public StreamSource toStreamSource(Source source) throws TransformerException {
+ return toStreamSource(source, null);
+ }
+
+ @Converter
+ public StreamSource toStreamSource(Source source, Exchange exchange) throws TransformerException {
if (source instanceof StreamSource) {
return (StreamSource) source;
} else if (source instanceof DOMSource) {
- return toStreamSourceFromDOM((DOMSource) source);
+ return toStreamSourceFromDOM((DOMSource) source, exchange);
} else if (source instanceof SAXSource) {
- return toStreamSourceFromSAX((SAXSource) source);
+ return toStreamSourceFromSAX((SAXSource) source, exchange);
} else {
return null;
}
@@ -331,8 +397,14 @@ public class XmlConverter {
return null;
}
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public StreamSource toStreamSourceFromSAX(SAXSource source) throws TransformerException {
+ return toStreamSourceFromSAX(source, null);
+ }
+
+ @Converter
+ public StreamSource toStreamSourceFromSAX(SAXSource source, Exchange exchange) throws TransformerException {
InputSource inputSource = source.getInputSource();
if (inputSource != null) {
if (inputSource.getCharacterStream() != null) {
@@ -342,13 +414,19 @@ public class XmlConverter {
return new StreamSource(inputSource.getByteStream());
}
}
- String result = toString(source);
+ String result = toString(source, exchange);
return new StringSource(result);
}
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public StreamSource toStreamSourceFromDOM(DOMSource source) throws TransformerException {
- String result = toString(source);
+ return toStreamSourceFromDOM(source, null);
+ }
+
+ @Converter
+ public StreamSource toStreamSourceFromDOM(DOMSource source, Exchange exchange) throws TransformerException {
+ String result = toString(source, exchange);
return new StringSource(result);
}
@@ -365,9 +443,15 @@ public class XmlConverter {
return new SAXSource(inputSource);
}
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public Reader toReaderFromSource(Source src) throws TransformerException {
- StreamSource stSrc = toStreamSource(src);
+ return toReaderFromSource(src, null);
+ }
+
+ @Converter
+ public Reader toReaderFromSource(Source src, Exchange exchange) throws TransformerException {
+ StreamSource stSrc = toStreamSource(src, exchange);
Reader r = stSrc.getReader();
if (r == null) {
r = new InputStreamReader(stSrc.getInputStream());
@@ -405,9 +489,15 @@ public class XmlConverter {
}
return new DOMSource(document, systemId);
}
-
- @Converter
+
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public SAXSource toSAXSourceFromDOM(DOMSource source) throws TransformerException {
+ return toSAXSourceFromDOM(source, null);
+ }
+
+ @Converter
+ public SAXSource toSAXSourceFromDOM(DOMSource source, Exchange exchange) throws TransformerException {
if (DOM_TO_SAX_CLASS != null) {
try {
Constructor<?> cns = DOM_TO_SAX_CLASS.getConstructor(Node.class);
@@ -417,7 +507,7 @@ public class XmlConverter {
throw new TransformerException(e);
}
} else {
- String str = toString(source);
+ String str = toString(source, exchange);
StringReader reader = new StringReader(str);
return new SAXSource(new InputSource(reader));
}
@@ -586,15 +676,27 @@ public class XmlConverter {
}
}
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public InputStream toInputStream(DOMSource source) throws TransformerException, IOException {
- String s = toString(source);
+ return toInputStream(source, null);
+ }
+
+ @Converter
+ public InputStream toInputStream(DOMSource source, Exchange exchange) throws TransformerException, IOException {
+ String s = toString(source, exchange);
return new ByteArrayInputStream(s.getBytes());
}
- @Converter
+ @Deprecated
+ //It will be removed in Camel 3.0, please use the method which take the exchange as the parameter
public InputStream toInputStream(Document dom) throws TransformerException, IOException {
- String s = toString(dom);
+ return toInputStream(dom, null);
+ }
+
+ @Converter
+ public InputStream toInputStream(Document dom, Exchange exchange) throws TransformerException, IOException {
+ String s = toString(dom, exchange);
return new ByteArrayInputStream(s.getBytes());
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=944131&r1=944130&r2=944131&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Fri May 14 06:15:58 2010
@@ -34,11 +34,14 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Properties;
import java.util.Scanner;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.apache.camel.CamelContext;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
@@ -574,6 +577,29 @@ public final class ObjectHelper {
String result = getSystemProperty(name, defaultValue.toString());
return Boolean.parseBoolean(result);
}
+
+ /**
+ * A helper method to access a camel context properties with a prefix
+ *
+ * @param name the name of the system property required
+ * @param defaultValue the default value to use if the property is not
+ * available or a security exception prevents access
+ * @return the properties which holds the camel context properties with the prefix,
+ * and the key omit the prefix part
+ */
+ public static Properties getCamelPropertiesWithPrefix(String prefix, CamelContext camelContext) {
+ Properties answer = new Properties();
+ Map<String, String> camelProperties = camelContext.getProperties();
+ if (camelProperties != null) {
+ for (Map.Entry<String, String> entry : camelProperties.entrySet()) {
+ String key = entry.getKey();
+ if (key.startsWith(prefix)) {
+ answer.put(key.substring(prefix.length()), entry.getValue());
+ }
+ }
+ }
+ return answer;
+ }
/**
* Returns the type name of the given type or null if the type variable is
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ObjectHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ObjectHelperTest.java?rev=944131&r1=944130&r2=944131&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ObjectHelperTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ObjectHelperTest.java Fri May 14 06:15:58 2010
@@ -17,12 +17,16 @@
package org.apache.camel.converter;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.util.ObjectHelper;
/**
@@ -114,5 +118,18 @@ public class ObjectHelperTest extends Te
it.next();
assertFalse(it.hasNext());
}
+
+ public void testGetCamelContextPropertiesWithPrefix() {
+ CamelContext context = new DefaultCamelContext();
+ Map<String, String> properties = context.getProperties();
+ properties.put("camel.object.helper.test1", "test1");
+ properties.put("camel.object.helper.test2", "test2");
+ properties.put("camel.object.test", "test");
+
+ Properties result = ObjectHelper.getCamelPropertiesWithPrefix("camel.object.helper.", context);
+ assertEquals("Get a wrong size properties", 2, result.size());
+ assertEquals("It should contain the test1", "test1", result.get("test1"));
+ assertEquals("It should contain the test2", "test2", result.get("test2"));
+ }
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java?rev=944131&r1=944130&r2=944131&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java Fri May 14 06:15:58 2010
@@ -20,6 +20,8 @@ import java.io.File;
import java.io.InputStream;
import java.io.Reader;
import java.nio.ByteBuffer;
+
+import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
@@ -31,8 +33,10 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
+import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultExchange;
/**
@@ -56,7 +60,7 @@ public class XmlConverterTest extends Co
XmlConverter conv = new XmlConverter();
Source source = null;
- String out = conv.toString(source);
+ String out = conv.toString(source, null);
assertEquals(null, out);
}
@@ -64,7 +68,7 @@ public class XmlConverterTest extends Co
XmlConverter conv = new XmlConverter();
Source source = conv.toSource("<foo>bar</foo>".getBytes());
- String out = conv.toString(source);
+ String out = conv.toString(source, null);
assertEquals("<foo>bar</foo>", out);
}
@@ -96,11 +100,11 @@ public class XmlConverterTest extends Co
public void testToDomSourceByStaxSource() throws Exception {
XmlConverter conv = new XmlConverter();
- SAXSource source = conv.toSAXSource("<foo>bar</foo>");
+ SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
DOMSource out = conv.toDOMSource(source);
assertNotSame(source, out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToDomSourceByCustomSource() throws Exception {
@@ -123,27 +127,27 @@ public class XmlConverterTest extends Co
XmlConverter conv = new XmlConverter();
InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<foo>bar</foo>");
- SAXSource out = conv.toSAXSource(is);
+ SAXSource out = conv.toSAXSource(is, null);
assertNotNull(out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToSaxSourceByDomSource() throws Exception {
XmlConverter conv = new XmlConverter();
DOMSource source = conv.toDOMSource("<foo>bar</foo>");
- SAXSource out = conv.toSAXSource(source);
+ SAXSource out = conv.toSAXSource(source, null);
assertNotSame(source, out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToSaxSourceByStaxSource() throws Exception {
XmlConverter conv = new XmlConverter();
- SAXSource source = conv.toSAXSource("<foo>bar</foo>");
- SAXSource out = conv.toSAXSource(source);
+ SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
+ SAXSource out = conv.toSAXSource(source, null);
assertSame(source, out);
}
@@ -159,7 +163,7 @@ public class XmlConverterTest extends Co
}
};
- SAXSource out = conv.toSAXSource(dummy);
+ SAXSource out = conv.toSAXSource(dummy, null);
assertNull(out);
}
@@ -168,7 +172,7 @@ public class XmlConverterTest extends Co
File file = new File("org/apache/camel/converter/stream/test.xml").getAbsoluteFile();
StreamSource source = conv.toStreamSource(file);
- StreamSource out = conv.toStreamSource(source);
+ StreamSource out = conv.toStreamSource(source, null);
assertSame(source, out);
}
@@ -177,7 +181,7 @@ public class XmlConverterTest extends Co
XmlConverter conv = new XmlConverter();
StreamSource source = conv.toStreamSource("<foo>bar</foo>".getBytes(), exchange);
- StreamSource out = conv.toStreamSource(source);
+ StreamSource out = conv.toStreamSource(source, null);
assertSame(source, out);
}
@@ -185,20 +189,20 @@ public class XmlConverterTest extends Co
XmlConverter conv = new XmlConverter();
DOMSource source = conv.toDOMSource("<foo>bar</foo>");
- StreamSource out = conv.toStreamSource(source);
+ StreamSource out = conv.toStreamSource(source, null);
assertNotSame(source, out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToStreamSourceByStaxSource() throws Exception {
XmlConverter conv = new XmlConverter();
- SAXSource source = conv.toSAXSource("<foo>bar</foo>");
- StreamSource out = conv.toStreamSource(source);
+ SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
+ StreamSource out = conv.toStreamSource(source, null);
assertNotSame(source, out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToStreamSourceByCustomSource() throws Exception {
@@ -213,7 +217,7 @@ public class XmlConverterTest extends Co
}
};
- StreamSource out = conv.toStreamSource(dummy);
+ StreamSource out = conv.toStreamSource(dummy, null);
assertNull(out);
}
@@ -223,7 +227,7 @@ public class XmlConverterTest extends Co
InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<foo>bar</foo>");
StreamSource out = conv.toStreamSource(is);
assertNotNull(out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToStreamSourceByReader() throws Exception {
@@ -232,7 +236,7 @@ public class XmlConverterTest extends Co
Reader reader = context.getTypeConverter().convertTo(Reader.class, "<foo>bar</foo>");
StreamSource out = conv.toStreamSource(reader);
assertNotNull(out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToStreamSourceByByteArray() throws Exception {
@@ -242,7 +246,7 @@ public class XmlConverterTest extends Co
byte[] bytes = context.getTypeConverter().convertTo(byte[].class, "<foo>bar</foo>");
StreamSource out = conv.toStreamSource(bytes, exchange);
assertNotNull(out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToStreamSourceByByteBuffer() throws Exception {
@@ -252,7 +256,7 @@ public class XmlConverterTest extends Co
ByteBuffer bytes = context.getTypeConverter().convertTo(ByteBuffer.class, "<foo>bar</foo>");
StreamSource out = conv.toStreamSource(bytes, exchange);
assertNotNull(out);
- assertEquals("<foo>bar</foo>", conv.toString(out));
+ assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
public void testToVariousUsingNull() throws Exception {
@@ -281,9 +285,9 @@ public class XmlConverterTest extends Co
public void testToReaderFromSource() throws Exception {
XmlConverter conv = new XmlConverter();
- SAXSource source = conv.toSAXSource("<foo>bar</foo>");
+ SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
- Reader out = conv.toReaderFromSource(source);
+ Reader out = conv.toReaderFromSource(source, null);
assertNotNull(out);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
@@ -299,7 +303,7 @@ public class XmlConverterTest extends Co
public void testToDomElement() throws Exception {
XmlConverter conv = new XmlConverter();
- SAXSource source = conv.toSAXSource("<foo>bar</foo>");
+ SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
Element out = conv.toDOMElement(source);
assertNotNull(out);
@@ -346,7 +350,7 @@ public class XmlConverterTest extends Co
XmlConverter conv = new XmlConverter();
Document doc = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
- InputStream is = conv.toInputStream(doc);
+ InputStream is = conv.toInputStream(doc, null);
assertNotNull(is);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, is));
}
@@ -365,7 +369,7 @@ public class XmlConverterTest extends Co
XmlConverter conv = new XmlConverter();
DOMSource source = conv.toDOMSource("<foo>bar</foo>");
- InputStream out = conv.toInputStream(source);
+ InputStream out = conv.toInputStream(source, null);
assertNotSame(source, out);
String s = context.getTypeConverter().convertTo(String.class, out);
@@ -380,5 +384,19 @@ public class XmlConverterTest extends Co
assertNotNull(out);
assertNotNull(out.getByteStream());
}
+
+ public void testOutOptionsFromCamelContext() throws Exception {
+ CamelContext context = new DefaultCamelContext();
+ Exchange exchange = new DefaultExchange(context);
+ // shows how to set the OutputOptions from camelContext
+ context.getProperties().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.ENCODING, "US_ASCII");
+ XmlConverter conv = new XmlConverter();
+
+ SAXSource source = conv.toSAXSource("<foo>bar</foo>", exchange);
+ DOMSource out = conv.toDOMSource(source);
+ assertNotSame(source, out);
+
+ assertEquals("<?xml version=\"1.0\" encoding=\"US_ASCII\"?><foo>bar</foo>", conv.toString(out, exchange));
+ }
}