Search in sources :

Example 16 with Properties

use of java.util.Properties in project camel by apache.

the class BlueprintPropertiesResolver method resolveProperties.

@Override
public Properties resolveProperties(CamelContext context, boolean ignoreMissingLocation, List<PropertiesLocation> locations) throws Exception {
    Properties answer = new Properties();
    boolean explicit = false;
    for (PropertiesLocation location : locations) {
        if ("blueprint".equals(location.getResolver())) {
            blueprint.addPropertyPlaceholder(location.getPath());
            // indicate an explicit blueprint id was configured
            explicit = true;
        } else {
            // delegate the url
            answer.putAll(delegate.resolveProperties(context, ignoreMissingLocation, Collections.singletonList(location)));
        }
    }
    if (!explicit) {
        // this is convention over configuration
        for (String id : blueprint.lookupPropertyPlaceholderIds()) {
            blueprint.addPropertyPlaceholder(id);
        }
    }
    return answer;
}
Also used : PropertiesLocation(org.apache.camel.component.properties.PropertiesLocation) Properties(java.util.Properties)

Example 17 with Properties

use of java.util.Properties in project camel by apache.

the class ModelHelper method dumpModelAsXml.

/**
     * Dumps the definition as XML
     *
     * @param context    the CamelContext, if <tt>null</tt> then {@link org.apache.camel.spi.ModelJAXBContextFactory} is not in use
     * @param definition the definition, such as a {@link org.apache.camel.NamedNode}
     * @return the output in XML (is formatted)
     * @throws JAXBException is throw if error marshalling to XML
     */
public static String dumpModelAsXml(CamelContext context, NamedNode definition) throws JAXBException {
    JAXBContext jaxbContext = getJAXBContext(context);
    final Map<String, String> namespaces = new LinkedHashMap<>();
    // gather all namespaces from the routes or route which is stored on the expression nodes
    if (definition instanceof RoutesDefinition) {
        List<RouteDefinition> routes = ((RoutesDefinition) definition).getRoutes();
        for (RouteDefinition route : routes) {
            extractNamespaces(route, namespaces);
        }
    } else if (definition instanceof RouteDefinition) {
        RouteDefinition route = (RouteDefinition) definition;
        extractNamespaces(route, namespaces);
    }
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    StringWriter buffer = new StringWriter();
    marshaller.marshal(definition, buffer);
    XmlConverter xmlConverter = newXmlConverter(context);
    String xml = buffer.toString();
    Document dom;
    try {
        dom = xmlConverter.toDOMDocument(xml, null);
    } catch (Exception e) {
        throw new TypeConversionException(xml, Document.class, e);
    }
    // Add additional namespaces to the document root element
    Element documentElement = dom.getDocumentElement();
    for (String nsPrefix : namespaces.keySet()) {
        String prefix = nsPrefix.equals("xmlns") ? nsPrefix : "xmlns:" + nsPrefix;
        documentElement.setAttribute(prefix, namespaces.get(nsPrefix));
    }
    // We invoke the type converter directly because we need to pass some custom XML output options
    Properties outputProperties = new Properties();
    outputProperties.put(OutputKeys.INDENT, "yes");
    outputProperties.put(OutputKeys.STANDALONE, "yes");
    try {
        return xmlConverter.toStringFromDocument(dom, outputProperties);
    } catch (TransformerException e) {
        throw new IllegalStateException("Failed converting document object to string", e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) TypeConversionException(org.apache.camel.TypeConversionException) Element(org.w3c.dom.Element) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) Properties(java.util.Properties) TransformerException(javax.xml.transform.TransformerException) JAXBException(javax.xml.bind.JAXBException) TypeConversionException(org.apache.camel.TypeConversionException) LinkedHashMap(java.util.LinkedHashMap) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter) StringWriter(java.io.StringWriter) TransformerException(javax.xml.transform.TransformerException)

Example 18 with Properties

use of java.util.Properties in project camel by apache.

the class BaseAhcTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry jndi = super.createRegistry();
    Properties prop = new Properties();
    prop.setProperty("port", "" + getPort());
    jndi.bind("prop", prop);
    if (isHttps()) {
        addSslContextParametersToRegistry(jndi);
    }
    return jndi;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Properties(java.util.Properties)

Example 19 with Properties

use of java.util.Properties in project camel by apache.

the class AtmosPropertyManager method loadProperties.

private static Properties loadProperties() throws Exception {
    URL url = AtmosPropertyManager.class.getResource("/atmos.properties");
    InputStream inStream;
    try {
        inStream = url.openStream();
    } catch (IOException e) {
        throw new AtmosException("atmos.properties could not be found");
    }
    properties = new Properties();
    try {
        properties.load(inStream);
    } catch (IOException e) {
        throw new AtmosException("atmos.properties can't be read");
    }
    return properties;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL)

Example 20 with Properties

use of java.util.Properties in project camel by apache.

the class CsvTestWithProperties method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // START SNIPPET: e1
            // setup beanio data format using the mapping file, loaded from the classpath
            BeanIODataFormat format = new BeanIODataFormat("org/apache/camel/dataformat/beanio/csv/mappingsWithProperties.xml", "stream1");
            Properties properties = new Properties();
            properties.setProperty("field1", "firstName");
            properties.setProperty("field2", "lastName");
            format.setProperties(properties);
            // a route which uses the bean io data format to format a CSV data
            // to java objects
            from("direct:unmarshal").unmarshal(format).split(body()).to("mock:beanio-unmarshal");
            // convert list of java objects back to flat format
            from("direct:marshal").marshal(format).to("mock:beanio-marshal");
        // END SNIPPET: e1
        }
    };
}
Also used : BeanIODataFormat(org.apache.camel.dataformat.beanio.BeanIODataFormat) RouteBuilder(org.apache.camel.builder.RouteBuilder) 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