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 2016/02/21 13:58:11 UTC
camel git commit: Upgrade camel-spark-rest component
Repository: camel
Updated Branches:
refs/heads/master 2ded240dd -> ac3b44099
Upgrade 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/ac3b4409
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ac3b4409
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ac3b4409
Branch: refs/heads/master
Commit: ac3b44099b7b82ac728d6f79b6c5a3ae10973c5f
Parents: 2ded240
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 21 13:57:50 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 21 13:58:04 2016 +0100
----------------------------------------------------------------------
.../camel/component/sparkrest/CamelSpark.java | 35 +++++++++++++--
.../sparkrest/ServletSparkApplication.java | 37 ----------------
.../component/sparkrest/SparkComponent.java | 13 +++---
.../sparkrest/SparkServletContextListener.java | 46 --------------------
parent/pom.xml | 4 +-
5 files changed, 40 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ac3b4409/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/CamelSpark.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/CamelSpark.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/CamelSpark.java
index 533ce3c..b67dcab 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/CamelSpark.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/CamelSpark.java
@@ -5,9 +5,9 @@
* 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
- *
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
* 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.
@@ -24,6 +24,35 @@ public final class CamelSpark {
private CamelSpark() {
}
+ /**
+ * Stops the Spark Server
+ */
+ public static void stop() {
+ Spark.stop();
+ }
+
+ /**
+ * Configures the port number to use
+ */
+ public static void port(int port) {
+ Spark.port(port);
+ }
+
+ /**
+ * Configures the IP address to use
+ */
+ public static void ipAddress(String ip) {
+ Spark.ipAddress(ip);
+ }
+
+ /**
+ * Adds a Spark REST verb that routes to the given Camel route
+ *
+ * @param verb the HTTP verb
+ * @param path the context path
+ * @param accept the accept header
+ * @param route the Camel route
+ */
public static void spark(String verb, String path, String accept, Route route) {
if ("get".equals(verb)) {
if (accept != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/ac3b4409/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/ServletSparkApplication.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/ServletSparkApplication.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/ServletSparkApplication.java
deleted file mode 100644
index 5df4cd0..0000000
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/ServletSparkApplication.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.sparkrest;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import spark.Access;
-import spark.servlet.SparkApplication;
-
-/**
- * A {@link spark.servlet.SparkApplication} to run in servlet mode.
- */
-public class ServletSparkApplication implements SparkApplication {
-
- private static final Logger LOG = LoggerFactory.getLogger(ServletSparkApplication.class);
-
- @Override
- public void init() {
- LOG.info("init");
- // force spark to be in Servlet mode
- Access.runFromServlet();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ac3b4409/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 8850346..19cabcd 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
@@ -31,13 +31,12 @@ import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
-import spark.SparkBase;
public class SparkComponent extends UriEndpointComponent implements RestConsumerFactory {
private final Pattern pattern = Pattern.compile("\\{(.*?)\\}");
- private int port = SparkBase.SPARK_DEFAULT_PORT;
+ private int port = 4567;
private String ipAddress;
private SparkConfiguration sparkConfiguration = new SparkConfiguration();
private SparkBinding sparkBinding = new DefaultSparkBinding();
@@ -116,18 +115,18 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
protected void doStart() throws Exception {
super.doStart();
- if (getPort() != SparkBase.SPARK_DEFAULT_PORT) {
- SparkBase.setPort(getPort());
+ if (getPort() != 4567) {
+ CamelSpark.port(getPort());
} else {
// if no explicit port configured, then use port from rest configuration
RestConfiguration config = getCamelContext().getRestConfiguration("spark-rest", true);
int port = config.getPort();
if (port > 0) {
- SparkBase.setPort(port);
+ CamelSpark.port(port);
}
}
if (getIpAddress() != null) {
- SparkBase.setIpAddress(getIpAddress());
+ CamelSpark.ipAddress(getIpAddress());
}
// configure component options
@@ -141,7 +140,7 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
@Override
protected void doShutdown() throws Exception {
super.doShutdown();
- SparkBase.stop();
+ CamelSpark.stop();
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/ac3b4409/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkServletContextListener.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkServletContextListener.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkServletContextListener.java
deleted file mode 100644
index 1d1987a..0000000
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkServletContextListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.sparkrest;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import spark.Access;
-
-/**
- * A {@link javax.servlet.ServletContextListener} to ensure we initialize Spark in servlet mode.
- */
-public class SparkServletContextListener implements ServletContextListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(ServletSparkApplication.class);
-
- @Override
- public void contextInitialized(ServletContextEvent event) {
- LOG.info("contextInitialized");
- // force spark to be in Servlet mode
- Access.runFromServlet();
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent event) {
- LOG.info("contextDestroyed");
- // noop
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ac3b4409/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 0efbb35..6ef7835 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -483,8 +483,8 @@
<solr-bundle-version>5.3.1_1</solr-bundle-version>
<solr-version>5.3.1</solr-version>
<solr-version-range>[5,6)</solr-version-range>
- <spark-rest-version>2.2</spark-rest-version>
- <spark-rest-bundle-version>2.2_1</spark-rest-bundle-version>
+ <spark-rest-version>2.3</spark-rest-version>
+ <spark-rest-bundle-version>2.3_1</spark-rest-bundle-version>
<splunk-version>1.5.0.0_1</splunk-version>
<spring-batch-version>3.0.4.RELEASE</spring-batch-version>
<spring-batch-bundle-version>3.0.4.RELEASE_1</spring-batch-bundle-version>