Search in sources :

Example 21 with Properties

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();
    }
}
Also used : BytesSource(org.apache.camel.BytesSource) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StringSource(org.apache.camel.StringSource) Properties(java.util.Properties) Converter(org.apache.camel.Converter)

Example 22 with Properties

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) Properties(java.util.Properties)

Example 23 with Properties

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) Properties(java.util.Properties)

Example 24 with Properties

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"));
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties)

Example 25 with Properties

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);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)9354 Test (org.junit.Test)3005 IOException (java.io.IOException)1277 Connection (java.sql.Connection)1179 File (java.io.File)1013 ResultSet (java.sql.ResultSet)860 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)819 PreparedStatement (java.sql.PreparedStatement)791 InputStream (java.io.InputStream)614 FileInputStream (java.io.FileInputStream)598 HashMap (java.util.HashMap)475 Map (java.util.Map)387 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)387 ArrayList (java.util.ArrayList)371 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)321 SQLException (java.sql.SQLException)308 Before (org.junit.Before)272 AttributesFactory (org.apache.geode.cache.AttributesFactory)245 InitialContext (javax.naming.InitialContext)214 Configuration (org.apache.hadoop.conf.Configuration)187