use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class BaseNettyTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
context.addComponent("properties", new PropertiesComponent("ref:prop"));
return context;
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class CamelServletContextListener method initPropertyPlaceholder.
/**
* Initializes the property placeholders by registering the {@link PropertiesComponent} with
* the configuration from the given init parameters.
*/
private void initPropertyPlaceholder(ServletCamelContext camelContext, Map<String, Object> parameters) throws Exception {
// setup property placeholder first
Map<String, Object> properties = IntrospectionSupport.extractProperties(parameters, "propertyPlaceholder.");
if (properties != null && !properties.isEmpty()) {
PropertiesComponent pc = new PropertiesComponent();
IntrospectionSupport.setProperties(pc, properties);
// validate we could set all parameters
if (!properties.isEmpty()) {
throw new IllegalArgumentException("Error setting propertyPlaceholder parameters on CamelContext." + " There are " + properties.size() + " unknown parameters. [" + properties + "]");
}
// register the properties component
camelContext.addComponent("properties", pc);
}
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class CamelAnnotationsHandler method handleUseOverridePropertiesWithPropertiesComponent.
/**
* Handles override this method to include and override properties with the Camel {@link org.apache.camel.component.properties.PropertiesComponent}.
*
* @param context the initialized Spring context
* @param testClass the test class being executed
*/
public static void handleUseOverridePropertiesWithPropertiesComponent(ConfigurableApplicationContext context, Class<?> testClass) throws Exception {
Collection<Method> methods = getAllMethods(testClass);
final List<Properties> properties = new LinkedList<Properties>();
for (Method method : methods) {
if (AnnotationUtils.findAnnotation(method, UseOverridePropertiesWithPropertiesComponent.class) != null) {
Class<?>[] argTypes = method.getParameterTypes();
if (argTypes.length > 0) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but is not a no-argument method.");
} else if (!Properties.class.isAssignableFrom(method.getReturnType())) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but does not return a java.util.Properties.");
} else if (!Modifier.isStatic(method.getModifiers())) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but is not static.");
} else if (!Modifier.isPublic(method.getModifiers())) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but is not public.");
}
try {
properties.add((Properties) method.invoke(null));
} catch (Exception e) {
throw new RuntimeException("Method [" + method.getName() + "] threw exception during evaluation.", e);
}
}
}
if (properties.size() != 0) {
CamelSpringTestHelper.doToSpringCamelContexts(context, new CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
PropertiesComponent pc = camelContext.getComponent("properties", PropertiesComponent.class);
Properties extra = new Properties();
for (Properties prop : properties) {
extra.putAll(prop);
}
if (!extra.isEmpty()) {
LOGGER.info("Using {} properties to override any existing properties on the PropertiesComponent on CamelContext with name [{}].", extra.size(), contextName);
pc.setOverrideProperties(extra);
}
}
});
}
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class CamelSpringTestContextLoader method handleUseOverridePropertiesWithPropertiesComponent.
/**
* Handles override this method to include and override properties with the Camel {@link org.apache.camel.component.properties.PropertiesComponent}.
*
* @param context the initialized Spring context
* @param testClass the test class being executed
*/
protected void handleUseOverridePropertiesWithPropertiesComponent(ConfigurableApplicationContext context, Class<?> testClass) throws Exception {
Collection<Method> methods = getAllMethods(testClass);
final List<Properties> properties = new LinkedList<Properties>();
for (Method method : methods) {
if (AnnotationUtils.findAnnotation(method, UseOverridePropertiesWithPropertiesComponent.class) != null) {
Class<?>[] argTypes = method.getParameterTypes();
if (argTypes.length > 0) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but is not a no-argument method.");
} else if (!Properties.class.isAssignableFrom(method.getReturnType())) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but does not return a java.util.Properties.");
} else if (!Modifier.isStatic(method.getModifiers())) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but is not static.");
} else if (!Modifier.isPublic(method.getModifiers())) {
throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with UseOverridePropertiesWithPropertiesComponent but is not public.");
}
try {
properties.add((Properties) method.invoke(null));
} catch (Exception e) {
throw new RuntimeException("Method [" + method.getName() + "] threw exception during evaluation.", e);
}
}
}
if (properties.size() != 0) {
CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {
public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
PropertiesComponent pc = camelContext.getComponent("properties", PropertiesComponent.class);
Properties extra = new Properties();
for (Properties prop : properties) {
extra.putAll(prop);
}
if (!extra.isEmpty()) {
LOG.info("Using {} properties to override any existing properties on the PropertiesComponent on CamelContext with name [{}].", extra.size(), contextName);
pc.setOverrideProperties(extra);
}
}
});
}
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class BlueprintPropertiesLocationElementImplicitTest method testPropertiesLocationElement.
@Test
public void testPropertiesLocationElement() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedHeaderReceived("property-1", "property-value-1");
mock.expectedHeaderReceived("property-2", "property-value-2");
mock.expectedHeaderReceived("cm", "cm-value");
PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
assertNotNull("Properties component not defined", pc);
List<PropertiesLocation> locations = pc.getLocations();
assertNotNull(locations);
assertEquals("Properties locations", 2, locations.size());
template.sendBody("direct:start", null);
mock.assertIsSatisfied();
}
Aggregations