You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/11/09 17:42:00 UTC

[1/2] camel git commit: CAMEL-9303: PropertiesComponent - Allow service host and port to be specified individually

Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 146f91f23 -> 6640c1317
  refs/heads/master f46794b51 -> 69068911b


CAMEL-9303: PropertiesComponent - Allow service host and port to be specified individually


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6640c131
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6640c131
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6640c131

Branch: refs/heads/camel-2.16.x
Commit: 6640c1317447a5d5a57af66c707c683ff6c41840
Parents: 146f91f
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 9 17:43:21 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 9 17:45:08 2015 +0100

----------------------------------------------------------------------
 .../properties/PropertiesComponent.java         |  2 +
 .../ServiceHostPropertiesFunction.java          | 76 ++++++++++++++++++++
 .../ServicePortPropertiesFunction.java          | 76 ++++++++++++++++++++
 .../PropertiesComponentServiceHostPortTest.java | 70 ++++++++++++++++++
 .../PropertiesComponentServiceHostTest.java     | 70 ++++++++++++++++++
 .../PropertiesComponentServicePortTest.java     | 70 ++++++++++++++++++
 6 files changed, 364 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6640c131/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 3eee968..952606c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -112,6 +112,8 @@ public class PropertiesComponent extends DefaultComponent {
         addFunction(new EnvPropertiesFunction());
         addFunction(new SysPropertiesFunction());
         addFunction(new ServicePropertiesFunction());
+        addFunction(new ServiceHostPropertiesFunction());
+        addFunction(new ServicePortPropertiesFunction());
     }
     
     public PropertiesComponent(String location) {

http://git-wip-us.apache.org/repos/asf/camel/blob/6640c131/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java b/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
new file mode 100644
index 0000000..6df3eac
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
@@ -0,0 +1,76 @@
+/**
+ * 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.component.properties;
+
+import java.util.Locale;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * A {@link PropertiesFunction} that lookup the property value from
+ * OS environment variables using the service idiom.
+ * <p/>
+ * A service is defined using two environment variables where name is name of the service:
+ * <ul>
+ *   <li><tt>NAME_SERVICE_HOST</tt></li>
+ *   <li><tt>NAME_SERVICE_PORT</tt></li>
+ * </ul>
+ * in other words the service uses <tt>_SERVICE_HOST</tt> and <tt>_SERVICE_PORT</tt> as prefix.
+ * <p/>
+ * This implementation is to return the host part only.
+ *
+ * @see ServicePropertiesFunction
+ * @see ServicePortPropertiesFunction
+ */
+public class ServiceHostPropertiesFunction implements PropertiesFunction {
+
+    private static final String HOST_PREFIX = "_SERVICE_HOST";
+
+    @Override
+    public String getName() {
+        return "service.host";
+    }
+
+    @Override
+    public String apply(String remainder) {
+        String key = remainder;
+        String defaultValue = null;
+
+        if (remainder.contains(":")) {
+            key = ObjectHelper.before(remainder, ":");
+            defaultValue = ObjectHelper.after(remainder, ":");
+        }
+
+        // make sure to use upper case
+        if (key != null) {
+            // make sure to use underscore as dash is not supported as ENV variables
+            key = key.toUpperCase(Locale.ENGLISH).replace('-', '_');
+
+            // a service should have both the host and port defined
+            String host = System.getenv(key + HOST_PREFIX);
+
+            if (host != null) {
+                return host;
+            } else {
+                return defaultValue;
+            }
+        }
+
+        return defaultValue;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/6640c131/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java b/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
new file mode 100644
index 0000000..8761c33
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
@@ -0,0 +1,76 @@
+/**
+ * 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.component.properties;
+
+import java.util.Locale;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * A {@link org.apache.camel.component.properties.PropertiesFunction} that lookup the property value from
+ * OS environment variables using the service idiom.
+ * <p/>
+ * A service is defined using two environment variables where name is name of the service:
+ * <ul>
+ *   <li><tt>NAME_SERVICE_HOST</tt></li>
+ *   <li><tt>NAME_SERVICE_PORT</tt></li>
+ * </ul>
+ * in other words the service uses <tt>_SERVICE_HOST</tt> and <tt>_SERVICE_PORT</tt> as prefix.
+ * <p/>
+ * This implementation is to return the port part only.
+ *
+ * @see ServicePropertiesFunction
+ * @see ServiceHostPropertiesFunction
+ */
+public class ServicePortPropertiesFunction implements PropertiesFunction {
+
+    private static final String PORT_PREFIX = "_SERVICE_PORT";
+
+    @Override
+    public String getName() {
+        return "service.port";
+    }
+
+    @Override
+    public String apply(String remainder) {
+        String key = remainder;
+        String defaultValue = null;
+
+        if (remainder.contains(":")) {
+            key = ObjectHelper.before(remainder, ":");
+            defaultValue = ObjectHelper.after(remainder, ":");
+        }
+
+        // make sure to use upper case
+        if (key != null) {
+            // make sure to use underscore as dash is not supported as ENV variables
+            key = key.toUpperCase(Locale.ENGLISH).replace('-', '_');
+
+            // a service should have both the host and port defined
+            String port = System.getenv(key + PORT_PREFIX);
+
+            if (port != null) {
+                return port;
+            } else {
+                return defaultValue;
+            }
+        }
+
+        return defaultValue;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/6640c131/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java
new file mode 100644
index 0000000..ec92663
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentServiceHostPortTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:FOO}}:{{service.port:FOO}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        String body = System.getenv("FOO_SERVICE_HOST") + ":" + System.getenv("FOO_SERVICE_PORT");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived(body);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testFunctionGetOrElse() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:BAR:myotherserver}}:{{service.port:BAR:8888}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("myotherserver:8888");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6640c131/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java
new file mode 100644
index 0000000..cfa3ce0
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentServiceHostTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:FOO}}:8888")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        String body = System.getenv("FOO_SERVICE_HOST") + ":8888";
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived(body);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testFunctionGetOrElse() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:BAR:myotherserver}}:8888")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("myotherserver:8888");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6640c131/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java
new file mode 100644
index 0000000..e303be0
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentServicePortTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("someserver:{{service.port:FOO}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        String body = "someserver:" + System.getenv("FOO_SERVICE_PORT");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived(body);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testFunctionGetOrElse() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("myotherserver:{{service.port:BAR:8888}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("myotherserver:8888");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}


[2/2] camel git commit: CAMEL-9303: PropertiesComponent - Allow service host and port to be specified individually

Posted by da...@apache.org.
CAMEL-9303: PropertiesComponent - Allow service host and port to be specified individually


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/69068911
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/69068911
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/69068911

Branch: refs/heads/master
Commit: 69068911bcc2770bec8626a4337afdf98e2e17bf
Parents: f46794b
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 9 17:43:21 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 9 17:45:20 2015 +0100

----------------------------------------------------------------------
 .../properties/PropertiesComponent.java         |  2 +
 .../ServiceHostPropertiesFunction.java          | 76 ++++++++++++++++++++
 .../ServicePortPropertiesFunction.java          | 76 ++++++++++++++++++++
 .../PropertiesComponentServiceHostPortTest.java | 70 ++++++++++++++++++
 .../PropertiesComponentServiceHostTest.java     | 70 ++++++++++++++++++
 .../PropertiesComponentServicePortTest.java     | 70 ++++++++++++++++++
 6 files changed, 364 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/69068911/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 3eee968..952606c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -112,6 +112,8 @@ public class PropertiesComponent extends DefaultComponent {
         addFunction(new EnvPropertiesFunction());
         addFunction(new SysPropertiesFunction());
         addFunction(new ServicePropertiesFunction());
+        addFunction(new ServiceHostPropertiesFunction());
+        addFunction(new ServicePortPropertiesFunction());
     }
     
     public PropertiesComponent(String location) {

http://git-wip-us.apache.org/repos/asf/camel/blob/69068911/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java b/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
new file mode 100644
index 0000000..6df3eac
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
@@ -0,0 +1,76 @@
+/**
+ * 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.component.properties;
+
+import java.util.Locale;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * A {@link PropertiesFunction} that lookup the property value from
+ * OS environment variables using the service idiom.
+ * <p/>
+ * A service is defined using two environment variables where name is name of the service:
+ * <ul>
+ *   <li><tt>NAME_SERVICE_HOST</tt></li>
+ *   <li><tt>NAME_SERVICE_PORT</tt></li>
+ * </ul>
+ * in other words the service uses <tt>_SERVICE_HOST</tt> and <tt>_SERVICE_PORT</tt> as prefix.
+ * <p/>
+ * This implementation is to return the host part only.
+ *
+ * @see ServicePropertiesFunction
+ * @see ServicePortPropertiesFunction
+ */
+public class ServiceHostPropertiesFunction implements PropertiesFunction {
+
+    private static final String HOST_PREFIX = "_SERVICE_HOST";
+
+    @Override
+    public String getName() {
+        return "service.host";
+    }
+
+    @Override
+    public String apply(String remainder) {
+        String key = remainder;
+        String defaultValue = null;
+
+        if (remainder.contains(":")) {
+            key = ObjectHelper.before(remainder, ":");
+            defaultValue = ObjectHelper.after(remainder, ":");
+        }
+
+        // make sure to use upper case
+        if (key != null) {
+            // make sure to use underscore as dash is not supported as ENV variables
+            key = key.toUpperCase(Locale.ENGLISH).replace('-', '_');
+
+            // a service should have both the host and port defined
+            String host = System.getenv(key + HOST_PREFIX);
+
+            if (host != null) {
+                return host;
+            } else {
+                return defaultValue;
+            }
+        }
+
+        return defaultValue;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/69068911/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java b/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
new file mode 100644
index 0000000..8761c33
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
@@ -0,0 +1,76 @@
+/**
+ * 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.component.properties;
+
+import java.util.Locale;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * A {@link org.apache.camel.component.properties.PropertiesFunction} that lookup the property value from
+ * OS environment variables using the service idiom.
+ * <p/>
+ * A service is defined using two environment variables where name is name of the service:
+ * <ul>
+ *   <li><tt>NAME_SERVICE_HOST</tt></li>
+ *   <li><tt>NAME_SERVICE_PORT</tt></li>
+ * </ul>
+ * in other words the service uses <tt>_SERVICE_HOST</tt> and <tt>_SERVICE_PORT</tt> as prefix.
+ * <p/>
+ * This implementation is to return the port part only.
+ *
+ * @see ServicePropertiesFunction
+ * @see ServiceHostPropertiesFunction
+ */
+public class ServicePortPropertiesFunction implements PropertiesFunction {
+
+    private static final String PORT_PREFIX = "_SERVICE_PORT";
+
+    @Override
+    public String getName() {
+        return "service.port";
+    }
+
+    @Override
+    public String apply(String remainder) {
+        String key = remainder;
+        String defaultValue = null;
+
+        if (remainder.contains(":")) {
+            key = ObjectHelper.before(remainder, ":");
+            defaultValue = ObjectHelper.after(remainder, ":");
+        }
+
+        // make sure to use upper case
+        if (key != null) {
+            // make sure to use underscore as dash is not supported as ENV variables
+            key = key.toUpperCase(Locale.ENGLISH).replace('-', '_');
+
+            // a service should have both the host and port defined
+            String port = System.getenv(key + PORT_PREFIX);
+
+            if (port != null) {
+                return port;
+            } else {
+                return defaultValue;
+            }
+        }
+
+        return defaultValue;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/69068911/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java
new file mode 100644
index 0000000..ec92663
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostPortTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentServiceHostPortTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:FOO}}:{{service.port:FOO}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        String body = System.getenv("FOO_SERVICE_HOST") + ":" + System.getenv("FOO_SERVICE_PORT");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived(body);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testFunctionGetOrElse() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:BAR:myotherserver}}:{{service.port:BAR:8888}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("myotherserver:8888");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/69068911/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java
new file mode 100644
index 0000000..cfa3ce0
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServiceHostTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentServiceHostTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:FOO}}:8888")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        String body = System.getenv("FOO_SERVICE_HOST") + ":8888";
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived(body);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testFunctionGetOrElse() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("{{service.host:BAR:myotherserver}}:8888")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("myotherserver:8888");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/69068911/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java
new file mode 100644
index 0000000..e303be0
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentServicePortTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentServicePortTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("someserver:{{service.port:FOO}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        String body = "someserver:" + System.getenv("FOO_SERVICE_PORT");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived(body);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testFunctionGetOrElse() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("mock:foo")
+                        .transform().constant("myotherserver:{{service.port:BAR:8888}}")
+                        .to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("myotherserver:8888");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}