use of java.util.Properties in project camel by apache.
the class XmlConverter method toString.
/**
* Converts the given input Source into text
*/
@Converter
public String toString(Source source, Exchange exchange) throws TransformerException {
if (source == null) {
return null;
} else if (source instanceof StringSource) {
return ((StringSource) source).getText();
} else if (source instanceof BytesSource) {
return new String(((BytesSource) source).getData());
} else {
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();
}
}
use of java.util.Properties in project camel by apache.
the class PropertiesComponentOverridePropertiesTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties");
context.addComponent("properties", pc);
Properties extra = new Properties();
extra.put("cool.result", "extra");
extra.put("hey", "mock:hey");
pc.setOverrideProperties(extra);
return context;
}
use of java.util.Properties in project camel by apache.
the class PropertiesComponentDisableDefaultsTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
Properties props = new Properties();
props.put("p:mockend", "end");
props.put("p:message", "my message");
PropertiesComponent component = new PropertiesComponent();
component.setDefaultFallbackEnabled(false);
component.setInitialProperties(props);
context.addComponent("properties", component);
return context;
}
use of java.util.Properties in project camel by apache.
the class CollectionConverterTest method testToProperties.
public void testToProperties() {
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("foo", "bar");
Properties prop = CollectionConverter.toProperties(map);
assertNotNull(prop);
assertEquals(1, prop.size());
assertEquals("bar", prop.get("foo"));
}
use of java.util.Properties in project camel by apache.
the class XmlConverterTest method testToStringWithDocumentSourceOutputProperties.
public void testToStringWithDocumentSourceOutputProperties() throws Exception {
XmlConverter conv = new XmlConverter();
Document document = conv.createDocument();
Element foo = document.createElement("foo");
foo.setTextContent("bar");
document.appendChild(foo);
Properties properties = new Properties();
properties.put(OutputKeys.ENCODING, "ISO-8859-1");
String out = conv.toStringFromDocument(document, properties);
assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?><foo>bar</foo>", out);
}
Aggregations