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;
}
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);
}
}
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;
}
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;
}
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
}
};
}
Aggregations