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 2013/06/12 17:25:22 UTC
[2/2] git commit: Added lat and lon option to camel-weather
Added lat and lon option to camel-weather
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/de9de108
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/de9de108
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/de9de108
Branch: refs/heads/master
Commit: de9de108bbf9f61ac8230f6b8938086e350d036a
Parents: c98b0d8
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 12 11:25:08 2013 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jun 12 11:25:08 2013 -0400
----------------------------------------------------------------------
.../component/weather/WeatherConfiguration.java | 37 ++++++++++++++++++--
.../component/weather/WeatherConsumer.java | 13 ++++++-
.../component/weather/WeatherProducer.java | 7 +++-
3 files changed, 53 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/de9de108/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java
index 52d3473..1142dd9 100644
--- a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java
+++ b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java
@@ -30,15 +30,22 @@ import static org.apache.camel.util.ObjectHelper.notNull;
public class WeatherConfiguration {
+ private final WeatherComponent component;
+
@UriParam
private String location = "";
@UriParam
+ private String lat;
+ @UriParam
+ private String lon;
+ @UriParam
private String period = "";
@UriParam
private WeatherMode mode = JSON;
@UriParam
private WeatherUnits units = METRIC;
- private final WeatherComponent component;
+ @UriParam
+ private String headerName;
public WeatherConfiguration(WeatherComponent component) {
this.component = notNull(component, "component");
@@ -85,6 +92,30 @@ public class WeatherConfiguration {
this.location = location;
}
+ public String getHeaderName() {
+ return headerName;
+ }
+
+ public void setHeaderName(String headerName) {
+ this.headerName = headerName;
+ }
+
+ public String getLat() {
+ return lat;
+ }
+
+ public void setLat(String lat) {
+ this.lat = lat;
+ }
+
+ public String getLon() {
+ return lon;
+ }
+
+ public void setLon(String lon) {
+ this.lon = lon;
+ }
+
public String getQuery() throws Exception {
return getQuery(getLocation());
}
@@ -92,7 +123,9 @@ public class WeatherConfiguration {
public String getQuery(String location) throws Exception {
String answer = "http://api.openweathermap.org/data/2.5/";
- if (isEmpty(location) || "current".equals(location)) {
+ if (lat != null && lon != null) {
+ location = "lat=" + lat + "&lon=" + lon;
+ } else if (isEmpty(location) || "current".equals(location)) {
location = getCurrentGeoLocation();
} else {
// assuming the location is a town or country
http://git-wip-us.apache.org/repos/asf/camel/blob/de9de108/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConsumer.java b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConsumer.java
index 881e36b..aec302b 100644
--- a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConsumer.java
+++ b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConsumer.java
@@ -36,6 +36,11 @@ public class WeatherConsumer extends ScheduledPollConsumer {
}
@Override
+ public WeatherEndpoint getEndpoint() {
+ return (WeatherEndpoint) super.getEndpoint();
+ }
+
+ @Override
protected int poll() throws Exception {
LOG.debug("Going to execute the Weather query {}", query);
String weather = getEndpoint().getCamelContext().getTypeConverter().mandatoryConvertTo(String.class, new URL(query));
@@ -45,8 +50,14 @@ public class WeatherConsumer extends ScheduledPollConsumer {
}
Exchange exchange = getEndpoint().createExchange();
- exchange.getIn().setBody(weather);
+ String header = getEndpoint().getConfiguration().getHeaderName();
+ if (header != null) {
+ exchange.getIn().setHeader(header, weather);
+ } else {
+ exchange.getIn().setBody(weather);
+ }
exchange.getIn().setHeader(WeatherConstants.WEATHER_QUERY, query);
+
getProcessor().process(exchange);
return 1;
http://git-wip-us.apache.org/repos/asf/camel/blob/de9de108/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherProducer.java b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherProducer.java
index afe1b85..346ace6 100644
--- a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherProducer.java
+++ b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherProducer.java
@@ -52,7 +52,12 @@ public class WeatherProducer extends DefaultProducer {
throw new IllegalStateException("Got the unexpected value '" + weather + "' as the result of the query '" + q + "'");
}
- exchange.getIn().setBody(weather);
+ String header = getEndpoint().getConfiguration().getHeaderName();
+ if (header != null) {
+ exchange.getIn().setHeader(header, weather);
+ } else {
+ exchange.getIn().setBody(weather);
+ }
exchange.getIn().setHeader(WeatherConstants.WEATHER_QUERY, q);
}
}