You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/08/31 04:28:12 UTC

git commit: Add setIpAddress to camel-spark-rest component

Repository: camel
Updated Branches:
  refs/heads/master 4769d97f1 -> 69a93a1e8


Add setIpAddress to camel-spark-rest component


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

Branch: refs/heads/master
Commit: 69a93a1e8d130a5aeb93ec913db9a34075cf3b37
Parents: 4769d97
Author: Willem Jiang <wi...@gmail.com>
Authored: Sun Aug 31 10:27:04 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Sun Aug 31 10:27:19 2014 +0800

----------------------------------------------------------------------
 .../camel/component/sparkrest/SparkComponent.java       | 12 ++++++++++++
 .../apache/camel/component/sparkrest/BaseSparkTest.java |  5 ++++-
 .../camel/component/sparkrest/CamelSparkAcceptTest.java |  4 ++--
 .../sparkrest/RestCamelSparkPojoInOutTest.java          |  4 ++--
 .../sparkrest/RestConfigurationCamelSparkTest.java      |  8 ++++----
 5 files changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/69a93a1e/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
index 2dafa9d..61b68c1 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
@@ -39,6 +39,7 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
     private final Pattern pattern = Pattern.compile("\\{(.*?)\\}");
 
     private int port = SparkBase.SPARK_DEFAULT_PORT;
+    private String ipAddress;
     private SparkConfiguration sparkConfiguration = new SparkConfiguration();
     private SparkBinding sparkBinding = new DefaultSparkBinding();
 
@@ -54,6 +55,14 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
         this.port = port;
     }
 
+    public String getIpAddress() {
+        return ipAddress;
+    }
+
+    public void setIpAddress(String ipAddress) {
+        this.ipAddress = ipAddress;
+    }
+
     public SparkConfiguration getSparkConfiguration() {
         return sparkConfiguration;
     }
@@ -106,6 +115,9 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
                 }
             }
         }
+        if (getIpAddress() != null) {
+            Spark.setIpAddress(getIpAddress());
+        }
 
         // configure component options
         RestConfiguration config = getCamelContext().getRestConfiguration();

http://git-wip-us.apache.org/repos/asf/camel/blob/69a93a1e/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/BaseSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/BaseSparkTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/BaseSparkTest.java
index 2edf49a1..b7a6c08 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/BaseSparkTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/BaseSparkTest.java
@@ -21,6 +21,7 @@ import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 
 public abstract class BaseSparkTest extends CamelTestSupport {
+    //static int count;
 
     protected int port;
 
@@ -30,7 +31,8 @@ public abstract class BaseSparkTest extends CamelTestSupport {
 
     @Override
     public void setUp() throws Exception {
-        port = AvailablePortFinder.getNextAvailable(24500);
+        //count++;
+        port = AvailablePortFinder.getNextAvailable(4500);
         super.setUp();
     }
 
@@ -40,6 +42,7 @@ public abstract class BaseSparkTest extends CamelTestSupport {
 
         SparkComponent spark = context.getComponent("spark-rest", SparkComponent.class);
         spark.setPort(port);
+        spark.setIpAddress("127.0.0.1");
 
         return context;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/69a93a1e/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkAcceptTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkAcceptTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkAcceptTest.java
index e68785b..27cd72a 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkAcceptTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkAcceptTest.java
@@ -28,14 +28,14 @@ public class CamelSparkAcceptTest extends BaseSparkTest {
         getMockEndpoint("mock:foo").expectedMessageCount(1);
 
         try {
-            template.requestBodyAndHeader("http://0.0.0.0:" + getPort() + "/hello", null, "Accept", "text/plain", String.class);
+            template.requestBodyAndHeader("http://127.0.0.1:" + getPort() + "/hello", null, "Accept", "text/plain", String.class);
             fail("Should fail");
         } catch (CamelExecutionException e) {
             HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
             assertEquals(404, cause.getStatusCode());
         }
 
-        String out2 = template.requestBodyAndHeader("http://0.0.0.0:" + getPort() + "/hello", null, "Accept", "application/json", String.class);
+        String out2 = template.requestBodyAndHeader("http://127.0.0.1:" + getPort() + "/hello", null, "Accept", "application/json", String.class);
         assertEquals("{ \"reply\": \"Bye World\" }", out2);
 
         assertMockEndpointsSatisfied();

http://git-wip-us.apache.org/repos/asf/camel/blob/69a93a1e/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkPojoInOutTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkPojoInOutTest.java
index 4a97600..faa3dfa 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkPojoInOutTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkPojoInOutTest.java
@@ -25,7 +25,7 @@ public class RestCamelSparkPojoInOutTest extends BaseSparkTest {
     @Test
     public void testRestletPojoInOut() throws Exception {
         String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
-        String out = template.requestBody("http://localhost:" + getPort() + "/users/lives", body, String.class);
+        String out = template.requestBody("http://127.0.0.1:" + getPort() + "/users/lives", body, String.class);
 
         assertNotNull(out);
         assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
@@ -38,7 +38,7 @@ public class RestCamelSparkPojoInOutTest extends BaseSparkTest {
             public void configure() throws Exception {
                 // configure to use spark on localhost with the given port
                 // and enable auto binding mode
-                restConfiguration().component("spark-rest").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+                restConfiguration().component("spark-rest").host("127.0.0.1").port(getPort()).bindingMode(RestBindingMode.auto);
 
                 // use the rest DSL to define the rest services
                 rest("/users/")

http://git-wip-us.apache.org/repos/asf/camel/blob/69a93a1e/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java
index b6811af..adcf2a5 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java
@@ -27,13 +27,13 @@ public class RestConfigurationCamelSparkTest extends CamelTestSupport {
 
     @Test
     public void testSparkHello() throws Exception {
-        String out = template.requestBody("http://0.0.0.0:" + port + "/spark/hello", null, String.class);
+        String out = template.requestBody("http://127.0.0.1:" + port + "/spark/hello", null, String.class);
         assertEquals("Hello World", out);
     }
 
     @Test
     public void testSparkBye() throws Exception {
-        String out = template.requestBody("http://0.0.0.0:" + port + "/spark/bye", null, String.class);
+        String out = template.requestBody("http://127.0.0.1:" + port + "/spark/bye", null, String.class);
         assertEquals("Bye World", out);
     }
 
@@ -41,7 +41,7 @@ public class RestConfigurationCamelSparkTest extends CamelTestSupport {
     public void testSparkPost() throws Exception {
         getMockEndpoint("mock:update").expectedBodiesReceived("I did this");
 
-        template.requestBody("http://0.0.0.0:" + port + "/spark/bye", "I did this", String.class);
+        template.requestBody("http://127.0.0.1:" + port + "/spark/bye", "I did this", String.class);
 
         assertMockEndpointsSatisfied();
     }
@@ -51,7 +51,7 @@ public class RestConfigurationCamelSparkTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                port = AvailablePortFinder.getNextAvailable(24500);
+                port = AvailablePortFinder.getNextAvailable(4510);
 
                 // configure port on rest configuration which spark-rest will pickup and use
                 restConfiguration().component("spark-rest").port(port);