[
https://issues.apache.org/jira/browse/CAMEL-5986?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Karim de Fombelle updated CAMEL-5986:
-------------------------------------
Description:
Camel-CDI offers a mechanism to resolve property placeholders like
{{{{property1}}}} in an endpoint URI as described in camel
[documentation|http://camel.apache.org/using-propertyplaceholder.html]
These placeholders could come from ConfigSource loaded via the deltaspike
configuration CDI extension and its ConfigResolver class according comments on
class _org.apache.camel.cdi.component.properties.CdiPropertiesParser_
Anyway this choice is surprising because the documentation of the
_org.apache.deltaspike.core.api.config.PropertyFileConfig_ specifies the
following:
{code}
* <p>Please note that the configuration will only be available
* after the boot is finished. This means that you cannot use
* this configuration inside a CDI Extension before the boot
* is finished!</p>
{code}
camel-cdi maven module contains a test class
_org.apache.camel.cdi.component.properties.PropertiesComponentTest_ which IMHO
does not illustrate the real use we would need in a CDI container.
It shows placeholders replaced after the boot of the CDI container, which is
inline with the javadoc above but probably not really useful.
{code}
context.resolvePropertyPlaceholders("{{directEndpoint}}_{{directEndpoint}}");
{code}
But from my standpoint the real benefit would be to use such a feature as
follows:
{code}
@RunWith(Arquillian.class)
@ApplicationScoped
public class CamelCdiCamel5986Test {
//~
----------------------------------------------------------------------------------------------------------------
//~ Instance fields
//~
----------------------------------------------------------------------------------------------------------------
@Inject
@Mock("mock:{{property1}}")
private MockEndpoint mockEndpoint;
//~
----------------------------------------------------------------------------------------------------------------
//~ Methods
//~
----------------------------------------------------------------------------------------------------------------
@Deployment
public static Archive<?> createDeployment() {
//J-
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addClasses(TestRouteBuilder.class,
SampleConfigBean.class)
.addAsResource("META-INF/camel.properties")//according
CdiConfigFile
.addPackages(true,
ConfigurationExtension.class.getPackage())
.addPackages(true, CdiCamelContext.class.getPackage())
.addAsManifestResource(EmptyAsset.INSTANCE,
"beans.xml");
return jar;
//J+
}
//test crashes with a org.jboss.weld.exceptions.DeploymentException (...)
Could not add Routes: [Route[[From[direct:begin]] ->
[To[mock:{{{{property1}}}}]]]]
@Test
public void testConfiguration() {
assertNotNull("mockEndpoint is null", mockEndpoint);
}
//~
----------------------------------------------------------------------------------------------------------------
//~ Inner Classes
//~
----------------------------------------------------------------------------------------------------------------
@ContextName
public static class TestRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:begin").to("mock:{{property1}}");
}
}
/**
* Copy of class from camel-cdi test class
org.apache.camel.cdi.support.CdiConfigFile
*/
public static class CdiConfigFile implements PropertyFileConfig {
private static final long serialVersionUID = 1L;
@Override
public String getPropertyFileName() {
return "META-INF/camel.properties";
}
}
}
{code}
was:
Camel-CDI offers a mechanism to resolve property placeholders like
{{{{property1}}}} in an endpoint URI as described in camel
[documentation|http://camel.apache.org/using-propertyplaceholder.html]
These placeholders could come from ConfigSource loaded via the deltaspike
configuration CDI extension and its ConfigResolver class according comments on
class _org.apache.camel.cdi.component.properties.CdiPropertiesParser_
Anyway this choice is surprising because the documentation of the
_org.apache.deltaspike.core.api.config.PropertyFileConfig_ specifies the
following:
{code}
* <p>Please note that the configuration will only be available
* after the boot is finished. This means that you cannot use
* this configuration inside a CDI Extension before the boot
* is finished!</p>
{code}
camel-cdi module contains a test class
_org.apache.camel.cdi.component.properties.PropertiesComponentTest_ which IMHO
does not illustrate the real use we would need in a CDI container.
It shows placeholders replacing after the boot of the CDI container, which is
inline with the javdoc illustrated below.
But from my standpoint the real benefit would be to use such a feature as
follows:
{code}
@RunWith(Arquillian.class)
@ApplicationScoped
public class CamelCdiCamel5986Test {
//~
----------------------------------------------------------------------------------------------------------------
//~ Instance fields
//~
----------------------------------------------------------------------------------------------------------------
@Inject
private SampleConfigBean bean;
@Inject
@Mock("mock:{{property1}}")
private MockEndpoint mockEndpoint;
//~
----------------------------------------------------------------------------------------------------------------
//~ Methods
//~
----------------------------------------------------------------------------------------------------------------
@Deployment
public static Archive<?> createDeployment() {
//J-
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addClasses(TestRouteBuilder.class,
SampleConfigBean.class)
.addAsResource("META-INF/camel.properties")//according
CdiConfigFile
.addPackages(true,
ConfigurationExtension.class.getPackage())
.addPackages(true, CdiCamelContext.class.getPackage())
.addAsManifestResource(EmptyAsset.INSTANCE,
"beans.xml");
return jar;
//J+
}
@Test
public void testConfiguration() {
assertNotNull("bean config is null", bean);
assertNotNull("mockEndpoint is null", mockEndpoint);
assertEquals("end", bean.getProperty1());
}
//~
----------------------------------------------------------------------------------------------------------------
//~ Inner Classes
//~
----------------------------------------------------------------------------------------------------------------
@ContextName
public static class TestRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:begin").to("mock:{{property1}}");
}
}
public static class SampleConfigBean {
@Inject
@ConfigProperty(name = "property1")
private String property1;
public String getProperty1() {
return property1;
}
}
/**
* Copy of class from camel-cdi test class
org.apache.camel.cdi.support.CdiConfigFile
*/
public static class CdiConfigFile implements PropertyFileConfig {
private static final long serialVersionUID = 1L;
@Override
public String getPropertyFileName() {
return "META-INF/camel.properties";
}
}
}
{code}
> Resolve property placeholders via another mechanism than deltaspike
> -------------------------------------------------------------------
>
> Key: CAMEL-5986
> URL: https://issues.apache.org/jira/browse/CAMEL-5986
> Project: Camel
> Issue Type: Improvement
> Components: camel-cdi
> Affects Versions: 2.11.1
> Reporter: Karim de Fombelle
>
> Camel-CDI offers a mechanism to resolve property placeholders like
> {{{{property1}}}} in an endpoint URI as described in camel
> [documentation|http://camel.apache.org/using-propertyplaceholder.html]
> These placeholders could come from ConfigSource loaded via the deltaspike
> configuration CDI extension and its ConfigResolver class according comments
> on class _org.apache.camel.cdi.component.properties.CdiPropertiesParser_
> Anyway this choice is surprising because the documentation of the
> _org.apache.deltaspike.core.api.config.PropertyFileConfig_ specifies the
> following:
> {code}
> * <p>Please note that the configuration will only be available
> * after the boot is finished. This means that you cannot use
> * this configuration inside a CDI Extension before the boot
> * is finished!</p>
> {code}
> camel-cdi maven module contains a test class
> _org.apache.camel.cdi.component.properties.PropertiesComponentTest_ which
> IMHO does not illustrate the real use we would need in a CDI container.
> It shows placeholders replaced after the boot of the CDI container, which is
> inline with the javadoc above but probably not really useful.
> {code}
> context.resolvePropertyPlaceholders("{{directEndpoint}}_{{directEndpoint}}");
> {code}
> But from my standpoint the real benefit would be to use such a feature as
> follows:
> {code}
> @RunWith(Arquillian.class)
> @ApplicationScoped
> public class CamelCdiCamel5986Test {
> //~
> ----------------------------------------------------------------------------------------------------------------
> //~ Instance fields
> //~
> ----------------------------------------------------------------------------------------------------------------
> @Inject
> @Mock("mock:{{property1}}")
> private MockEndpoint mockEndpoint;
> //~
> ----------------------------------------------------------------------------------------------------------------
> //~ Methods
> //~
> ----------------------------------------------------------------------------------------------------------------
> @Deployment
> public static Archive<?> createDeployment() {
> //J-
> JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
> .addClasses(TestRouteBuilder.class,
> SampleConfigBean.class)
>
> .addAsResource("META-INF/camel.properties")//according CdiConfigFile
> .addPackages(true,
> ConfigurationExtension.class.getPackage())
> .addPackages(true, CdiCamelContext.class.getPackage())
> .addAsManifestResource(EmptyAsset.INSTANCE,
> "beans.xml");
> return jar;
> //J+
> }
> //test crashes with a org.jboss.weld.exceptions.DeploymentException (...)
> Could not add Routes: [Route[[From[direct:begin]] ->
> [To[mock:{{{{property1}}}}]]]]
> @Test
> public void testConfiguration() {
> assertNotNull("mockEndpoint is null", mockEndpoint);
> }
> //~
> ----------------------------------------------------------------------------------------------------------------
> //~ Inner Classes
> //~
> ----------------------------------------------------------------------------------------------------------------
> @ContextName
> public static class TestRouteBuilder extends RouteBuilder {
> @Override
> public void configure() throws Exception {
> from("direct:begin").to("mock:{{property1}}");
> }
> }
> /**
> * Copy of class from camel-cdi test class
> org.apache.camel.cdi.support.CdiConfigFile
> */
> public static class CdiConfigFile implements PropertyFileConfig {
> private static final long serialVersionUID = 1L;
> @Override
> public String getPropertyFileName() {
> return "META-INF/camel.properties";
> }
> }
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira