You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2012/09/20 02:29:02 UTC
svn commit: r1387827 - in /camel/trunk: components/camel-cdi/
components/camel-cdi/src/main/java/org/apache/camel/cdi/
components/camel-cdi/src/main/java/org/apache/camel/cdi/component/
components/camel-cdi/src/main/java/org/apache/camel/cdi/component/...
Author: hadrian
Date: Thu Sep 20 00:29:01 2012
New Revision: 1387827
URL: http://svn.apache.org/viewvc?rev=1387827&view=rev
Log:
CAMEL-5616. PropertiesComponent extension in CDI.
Added:
camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/
camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/
camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java (with props)
camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java (with props)
camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/
camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/properties/
camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/properties/PropertiesComponentTest.java (with props)
Modified:
camel/trunk/components/camel-cdi/pom.xml
camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java
Modified: camel/trunk/components/camel-cdi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/pom.xml?rev=1387827&r1=1387826&r2=1387827&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/pom.xml (original)
+++ camel/trunk/components/camel-cdi/pom.xml Thu Sep 20 00:29:01 2012
@@ -37,7 +37,8 @@
*
</camel.osgi.import>
<camel.osgi.export.pkg>
- org.apache.camel.cdi
+ org.apache.camel.cdi;${camel.osgi.version},
+ org.apache.camel.cdi.component.*;${camel.osgi.version}
</camel.osgi.export.pkg>
<camel.osgi.private.pkg>
org.apache.camel.cdi.internal
Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java?rev=1387827&r1=1387826&r2=1387827&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java Thu Sep 20 00:29:01 2012
@@ -24,7 +24,7 @@ import javax.inject.Inject;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.Injector;
import org.apache.camel.spi.Registry;
-import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.camel.util.ObjectHelper;
/**
* CDI {@link org.apache.camel.CamelContext} class.
@@ -54,25 +54,24 @@ public class CdiCamelContext extends Def
return !instance.isUnsatisfied() && !instance.isAmbiguous();
}
- @Override
- public String resolvePropertyPlaceholders(String text) throws Exception {
- String placeholder = text != null ? ConfigResolver.getPropertyValue(text) : null;
- if (placeholder == null) {
- // fallback to standard properties loaded by camel
- return super.resolvePropertyPlaceholders(text);
- }
- return placeholder;
- }
-
@PostConstruct
@Override
- public void start() throws Exception {
- super.start();
+ public void start() {
+ try {
+ super.start();
+ } catch (Exception e) {
+ ObjectHelper.wrapRuntimeCamelException(e);
+ }
}
@PreDestroy
@Override
- public void stop() throws Exception {
- super.stop();
+ public void stop() {
+ try {
+ super.stop();
+ } catch (Exception e) {
+ ObjectHelper.wrapRuntimeCamelException(e);
+ }
}
+
}
Added: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java?rev=1387827&view=auto
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java (added)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java Thu Sep 20 00:29:01 2012
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.cdi.component.properties;
+
+import javax.inject.Named;
+
+import org.apache.camel.component.properties.PropertiesComponent;
+
+/**
+ * Simple extension for properties component which uses custom property resolver.
+ */
+@Named("properties")
+public class CdiPropertiesComponent extends PropertiesComponent {
+
+ public CdiPropertiesComponent() {
+ setPropertiesParser(new CdiPropertiesParser());
+ }
+
+}
Propchange: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java?rev=1387827&view=auto
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java (added)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java Thu Sep 20 00:29:01 2012
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.cdi.component.properties;
+
+import java.util.Properties;
+
+import org.apache.camel.component.properties.DefaultPropertiesParser;
+import org.apache.deltaspike.core.api.config.ConfigResolver;
+
+/**
+ * Properties parser which uses {@link ConfigResolver} from deltaspike to obtain
+ * configuration properties. If property is not recognized by deltaspike execution
+ * will be delegated to parent implementation.
+ */
+public class CdiPropertiesParser extends DefaultPropertiesParser {
+
+ @Override
+ public String parseProperty(String key, String value, Properties properties) {
+ String answer = ConfigResolver.getPropertyValue(key);
+
+ if (answer != null) {
+ return answer;
+ }
+
+ return super.parseProperty(key, value, properties);
+ }
+
+}
Propchange: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/properties/PropertiesComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/properties/PropertiesComponentTest.java?rev=1387827&view=auto
==============================================================================
--- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/properties/PropertiesComponentTest.java (added)
+++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/properties/PropertiesComponentTest.java Thu Sep 20 00:29:01 2012
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.cdi.component.properties;
+
+import org.apache.camel.cdi.CdiContextTestSupport;
+import org.junit.Test;
+
+/**
+ * Verifies behavior of properties component in CDI environment.
+ */
+public class PropertiesComponentTest extends CdiContextTestSupport {
+
+ @Test
+ public void shouldUseCdiProperties() throws Exception {
+ assertTrue(context.getComponent("properties") instanceof CdiPropertiesComponent);
+ String resolved = context.resolvePropertyPlaceholders("d{{directEndpoint}}b");
+
+ assertEquals("ddirect:injectb", resolved);
+ resolved = context.resolvePropertyPlaceholders("{{directEndpoint}}_{{directEndpoint}}");
+
+ assertEquals("direct:inject_direct:inject", resolved);
+ }
+
+ @Test
+ public void testNullArgument() throws Exception {
+ assertNull(context.resolvePropertyPlaceholders(null));
+ }
+
+ @Test
+ public void testTextWithNoPlaceholder() throws Exception {
+ assertEquals("IamAnonymous", context.resolvePropertyPlaceholders("IamAnonymous"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testUnknownNestedPlaceholder() throws Exception {
+ context.resolvePropertyPlaceholders("{{IamAnonymous}}");
+ }
+
+}
Propchange: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/component/properties/PropertiesComponentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java?rev=1387827&r1=1387826&r2=1387827&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java (original)
+++ camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java Thu Sep 20 00:29:01 2012
@@ -19,6 +19,7 @@ package org.apache.camel.itest.cdi;
import javax.inject.Inject;
import org.apache.camel.CamelContext;
+import org.apache.camel.cdi.component.properties.CdiPropertiesComponent;
import org.apache.camel.cdi.internal.CamelExtension;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
@@ -32,7 +33,7 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertNotNull;
/**
- * Verify if {@link CamelExtension} allows to create custom instance of context.
+ * Verify if {@link CamelExtension} with custom properties.
*/
@RunWith(Arquillian.class)
public class PropertiesConfigurationTest {
@@ -44,16 +45,18 @@ public class PropertiesConfigurationTest
public void checkContext() throws Exception {
assertNotNull(camelContext);
- assertEquals("value1", camelContext.resolvePropertyPlaceholders("property1"));
- assertEquals("value2", camelContext.resolvePropertyPlaceholders("property2"));
+ assertEquals("value1", camelContext.resolvePropertyPlaceholders("{{property1}}"));
+ assertEquals("value2", camelContext.resolvePropertyPlaceholders("{{property2}}"));
+ assertEquals("value1_value2", camelContext.resolvePropertyPlaceholders("{{property1}}_{{property2}}"));
}
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
- .addPackage(CamelExtension.class.getPackage())
- .addClass(Camel1Config.class)
- .addClass(Camel2Config.class)
- .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+ .addPackage(CamelExtension.class.getPackage())
+ .addPackage(CdiPropertiesComponent.class.getPackage())
+ .addClass(Camel1Config.class)
+ .addClass(Camel2Config.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
}