You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/09/06 13:10:32 UTC
[camel] 01/05: CAMEL-12784 - Create a Camel-google-calendar-stream
component
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 021dfd40aa0531d3629cab2eafd1b093db700f9a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Sep 6 13:44:03 2018 +0200
CAMEL-12784 - Create a Camel-google-calendar-stream component
---
.../stream/GoogleCalendarStreamComponent.java | 94 ++++++++++
.../stream/GoogleCalendarStreamConfiguration.java | 179 ++++++++++++++++++
.../stream/GoogleCalendarStreamConstants.java | 30 ++++
.../stream/GoogleCalendarStreamConsumer.java | 117 ++++++++++++
.../stream/GoogleCalendarStreamEndpoint.java | 96 ++++++++++
.../apache/camel/component/google-calendar-stream | 17 ++
.../AbstractGoogleCalendarStreamTestSupport.java | 72 ++++++++
...oogleCalendarStreamConsumerIntegrationTest.java | 45 +++++
.../src/test/resources/test-options.properties | 2 +-
...leCalendarStreamComponentAutoConfiguration.java | 130 ++++++++++++++
...GoogleCalendarStreamComponentConfiguration.java | 199 +++++++++++++++++++++
.../src/main/resources/META-INF/spring.factories | 4 +-
12 files changed, 983 insertions(+), 2 deletions(-)
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamComponent.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamComponent.java
new file mode 100644
index 0000000..82c6d10
--- /dev/null
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamComponent.java
@@ -0,0 +1,94 @@
+/**
+ * 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.google.calendar.stream;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.google.calendar.BatchGoogleCalendarClientFactory;
+import org.apache.camel.component.google.calendar.GoogleCalendarClientFactory;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+
+import com.google.api.services.calendar.Calendar;
+
+/**
+ * Represents the component that manages {@link GoogleCalendarStreamEndpoint}.
+ */
+public class GoogleCalendarStreamComponent extends DefaultComponent {
+
+ @Metadata(label = "advanced")
+ private Calendar client;
+ @Metadata(label = "advanced")
+ private GoogleCalendarClientFactory clientFactory;
+ @Metadata(label = "advanced")
+ private GoogleCalendarStreamConfiguration configuration;
+
+ public GoogleCalendarStreamComponent() {
+ this(null);
+ }
+
+ public GoogleCalendarStreamComponent(CamelContext context) {
+ super(context);
+
+ this.configuration = new GoogleCalendarStreamConfiguration();
+ }
+
+ public Calendar getClient(GoogleCalendarStreamConfiguration googleMailConfiguration) {
+ if (client == null) {
+ client = getClientFactory().makeClient(googleMailConfiguration.getClientId(), googleMailConfiguration.getClientSecret(), configuration.getScopes(),
+ googleMailConfiguration.getApplicationName(), googleMailConfiguration.getRefreshToken(),
+ googleMailConfiguration.getAccessToken(), null, null, "me");
+ }
+ return client;
+ }
+
+ /**
+ * The client Factory
+ */
+ public GoogleCalendarClientFactory getClientFactory() {
+ if (clientFactory == null) {
+ clientFactory = new BatchGoogleCalendarClientFactory();
+ }
+ return clientFactory;
+ }
+
+ public GoogleCalendarStreamConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * The configuration
+ */
+ public void setConfiguration(GoogleCalendarStreamConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public void setClientFactory(GoogleCalendarClientFactory clientFactory) {
+ this.clientFactory = clientFactory;
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ final GoogleCalendarStreamConfiguration configuration = this.configuration.copy();
+ setProperties(configuration, parameters);
+ GoogleCalendarStreamEndpoint endpoint = new GoogleCalendarStreamEndpoint(uri, this, configuration);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+}
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConfiguration.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConfiguration.java
new file mode 100644
index 0000000..25396fb
--- /dev/null
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConfiguration.java
@@ -0,0 +1,179 @@
+/**
+ * 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.google.calendar.stream;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.google.api.services.calendar.CalendarScopes;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
+
+/**
+ * Component configuration for GoogleCalendar stream component.
+ */
+@UriParams
+public class GoogleCalendarStreamConfiguration implements Cloneable {
+ private static final List<String> DEFAULT_SCOPES = Arrays.asList(CalendarScopes.CALENDAR);
+
+ @UriPath
+ private String index;
+
+ @UriParam
+ private List<String> scopes = DEFAULT_SCOPES;
+
+ @UriParam
+ private String clientId;
+
+ @UriParam
+ private String clientSecret;
+
+ @UriParam
+ private String accessToken;
+
+ @UriParam
+ private String refreshToken;
+
+ @UriParam
+ private String applicationName;
+
+ @UriParam
+ private String query;
+
+ @UriParam(defaultValue = "10")
+ private int maxResults = 10;
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ /**
+ * Client ID of the mail application
+ */
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ public String getClientSecret() {
+ return clientSecret;
+ }
+
+ /**
+ * Client secret of the mail application
+ */
+ public void setClientSecret(String clientSecret) {
+ this.clientSecret = clientSecret;
+ }
+
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ /**
+ * OAuth 2 access token. This typically expires after an hour so
+ * refreshToken is recommended for long term usage.
+ */
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ public String getRefreshToken() {
+ return refreshToken;
+ }
+
+ /**
+ * OAuth 2 refresh token. Using this, the Google Calendar component can
+ * obtain a new accessToken whenever the current one expires - a necessity
+ * if the application is long-lived.
+ */
+ public void setRefreshToken(String refreshToken) {
+ this.refreshToken = refreshToken;
+ }
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ /**
+ * Google mail application name. Example would be "camel-google-mail/1.0"
+ */
+ public void setApplicationName(String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ public List<String> getScopes() {
+ return scopes;
+ }
+
+ /**
+ * Specifies the level of permissions you want a mail application to have to
+ * a user account. See https://developers.google.com/gmail/api/auth/scopes
+ * for more info.
+ */
+ public void setScopes(List<String> scopes) {
+ this.scopes = scopes;
+ }
+
+ public String getIndex() {
+ return index;
+ }
+
+ /**
+ * Specifies an index for the endpoint
+ */
+ public void setIndex(String index) {
+ this.index = index;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ /**
+ * The query to execute on gmail box
+ */
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+ public int getMaxResults() {
+ return maxResults;
+ }
+
+ /**
+ * Max results to be returned
+ */
+ public void setMaxResults(int maxResults) {
+ this.maxResults = maxResults;
+ }
+
+ // *************************************************
+ //
+ // *************************************************
+
+ public GoogleCalendarStreamConfiguration copy() {
+ try {
+ return (GoogleCalendarStreamConfiguration)super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
+
+}
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConstants.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConstants.java
new file mode 100644
index 0000000..c671c54
--- /dev/null
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConstants.java
@@ -0,0 +1,30 @@
+/**
+ * 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.google.calendar.stream;
+
+/**
+ * Constants used in Camel Google Calendar Stream
+ */
+public interface GoogleCalendarStreamConstants {
+
+ String MAIL_TO = "CamelGoogleMailStreamTo";
+ String MAIL_FROM = "CamelGoogleMailStreamFrom";
+ String MAIL_CC = "CamelGoogleMailStreamCc";
+ String MAIL_BCC = "CamelGoogleMailStreamBcc";
+ String MAIL_SUBJECT = "CamelGoogleMailStreamSubject";
+ String MAIL_ID = "CamelGoogleMailId";
+}
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumer.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumer.java
new file mode 100644
index 0000000..25797b5
--- /dev/null
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumer.java
@@ -0,0 +1,117 @@
+/**
+ * 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.google.calendar.stream;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.ScheduledBatchPollingConsumer;
+import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.api.client.util.DateTime;
+import com.google.api.services.calendar.Calendar;
+import com.google.api.services.calendar.model.Event;
+import com.google.api.services.calendar.model.Events;
+
+/**
+ * The GoogleCalendar consumer.
+ */
+public class GoogleCalendarStreamConsumer extends ScheduledBatchPollingConsumer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GoogleCalendarStreamConsumer.class);
+
+ public GoogleCalendarStreamConsumer(Endpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+
+ protected GoogleCalendarStreamConfiguration getConfiguration() {
+ return getEndpoint().getConfiguration();
+ }
+
+ protected Calendar getClient() {
+ return getEndpoint().getClient();
+ }
+
+ @Override
+ public GoogleCalendarStreamEndpoint getEndpoint() {
+ return (GoogleCalendarStreamEndpoint)super.getEndpoint();
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ Date date = new Date();
+ com.google.api.services.calendar.Calendar.Events.List request = getClient().events().list("primary").setOrderBy("updated").setTimeMin(new DateTime(date));
+ if (ObjectHelper.isNotEmpty(getConfiguration().getQuery())) {
+ request.setQ(getConfiguration().getQuery());
+ }
+ if (ObjectHelper.isNotEmpty(getConfiguration().getMaxResults())) {
+ request.setMaxResults(getConfiguration().getMaxResults());
+ }
+
+ Queue<Exchange> answer = new LinkedList<>();
+
+ Events c = request.execute();
+
+ if (c != null) {
+ List<Event> list = c.getItems();
+ for (Event event : list) {
+ Exchange exchange = getEndpoint().createExchange(getEndpoint().getExchangePattern(), event);
+ answer.add(exchange);
+ }
+ }
+
+ return processBatch(CastUtils.cast(answer));
+ }
+
+ @Override
+ public int processBatch(Queue<Object> exchanges) throws Exception {
+ int total = exchanges.size();
+
+ for (int index = 0; index < total && isBatchAllowed(); index++) {
+ // only loop if we are started (allowed to run)
+ final Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll());
+ // add current index and total as properties
+ exchange.setProperty(Exchange.BATCH_INDEX, index);
+ exchange.setProperty(Exchange.BATCH_SIZE, total);
+ exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1);
+
+ // update pending number of exchanges
+ pendingExchanges = total - index - 1;
+
+ getAsyncProcessor().process(exchange, new AsyncCallback() {
+ @Override
+ public void done(boolean doneSync) {
+ LOG.trace("Processing exchange done");
+ }
+ });
+ }
+
+ return total;
+ }
+
+}
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java
new file mode 100644
index 0000000..952c476
--- /dev/null
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java
@@ -0,0 +1,96 @@
+/**
+ * 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.google.calendar.stream;
+
+import java.io.UnsupportedEncodingException;
+
+import com.google.api.services.calendar.Calendar;
+import com.google.api.services.calendar.model.Event;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.google.calendar.GoogleCalendarClientFactory;
+import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+/**
+ * The google-mail component provides access to Google Mail.
+ */
+@UriEndpoint(firstVersion = "2.23.0",
+ scheme = "google-calendar-stream",
+ title = "Google Calendar Stream",
+ syntax = "google-calendar-stream:index",
+ consumerClass = GoogleCalendarStreamConsumer.class,
+ consumerOnly = true,
+ label = "api,cloud")
+public class GoogleCalendarStreamEndpoint extends ScheduledPollEndpoint {
+
+ @UriParam
+ private GoogleCalendarStreamConfiguration configuration;
+
+ public GoogleCalendarStreamEndpoint(String uri, GoogleCalendarStreamComponent component, GoogleCalendarStreamConfiguration endpointConfiguration) {
+ super(uri, component);
+ this.configuration = endpointConfiguration;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ throw new UnsupportedOperationException("The camel google mail stream component doesn't support producer");
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ final GoogleCalendarStreamConsumer consumer = new GoogleCalendarStreamConsumer(this, processor);
+ configureConsumer(consumer);
+ return consumer;
+ }
+
+ public Calendar getClient() {
+ return ((GoogleCalendarStreamComponent)getComponent()).getClient(configuration);
+ }
+
+ public GoogleCalendarClientFactory getClientFactory() {
+ return ((GoogleCalendarStreamComponent)getComponent()).getClientFactory();
+ }
+
+ public void setClientFactory(GoogleCalendarClientFactory clientFactory) {
+ ((GoogleCalendarStreamComponent)getComponent()).setClientFactory(clientFactory);
+ }
+
+ public GoogleCalendarStreamConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public Exchange createExchange(ExchangePattern pattern, Event event) throws UnsupportedEncodingException {
+
+ Exchange exchange = super.createExchange();
+ Message message = exchange.getIn();
+ message.setBody(event);
+ System.err.println("Ciao " + message.getBody().toString());
+ return exchange;
+ }
+}
diff --git a/components/camel-google-calendar/src/main/resources/META-INF/services/org/apache/camel/component/google-calendar-stream b/components/camel-google-calendar/src/main/resources/META-INF/services/org/apache/camel/component/google-calendar-stream
new file mode 100644
index 0000000..1e548d6
--- /dev/null
+++ b/components/camel-google-calendar/src/main/resources/META-INF/services/org/apache/camel/component/google-calendar-stream
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+class=org.apache.camel.component.google.calendar.stream.GoogleCalendarStreamComponent
diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/stream/AbstractGoogleCalendarStreamTestSupport.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/stream/AbstractGoogleCalendarStreamTestSupport.java
new file mode 100644
index 0000000..6cf4a25
--- /dev/null
+++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/stream/AbstractGoogleCalendarStreamTestSupport.java
@@ -0,0 +1,72 @@
+/**
+ * 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.google.calendar.stream;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.IntrospectionSupport;
+
+/**
+ * Abstract base class for GoogleMail Integration tests generated by Camel API
+ * component maven plugin.
+ */
+public class AbstractGoogleCalendarStreamTestSupport extends CamelTestSupport {
+
+ // userid of the currently authenticated user
+ protected static final String CURRENT_USERID = "me";
+ private static final String TEST_OPTIONS_PROPERTIES = "/test-options.properties";
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+
+ final CamelContext context = super.createCamelContext();
+
+ // read GoogleMail component configuration from TEST_OPTIONS_PROPERTIES
+ final Properties properties = new Properties();
+ try {
+ properties.load(getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES));
+ } catch (Exception e) {
+ throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
+ }
+
+ Map<String, Object> options = new HashMap<>();
+ for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+ options.put(entry.getKey().toString(), entry.getValue());
+ }
+
+ final GoogleCalendarStreamConfiguration configuration = new GoogleCalendarStreamConfiguration();
+ IntrospectionSupport.setProperties(configuration, options);
+
+ // add GoogleMailComponent to Camel context
+ final GoogleCalendarStreamComponent component = new GoogleCalendarStreamComponent(context);
+ component.setConfiguration(configuration);
+ context.addComponent("google-calendar-stream", component);
+
+ return context;
+ }
+
+ @Override
+ public boolean isCreateCamelContextPerClass() {
+ // only create the context once for this class
+ return true;
+ }
+}
diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumerIntegrationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumerIntegrationTest.java
new file mode 100644
index 0000000..c58ef0d
--- /dev/null
+++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumerIntegrationTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.google.calendar.stream;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class GoogleCalendarStreamConsumerIntegrationTest extends AbstractGoogleCalendarStreamTestSupport {
+
+ @Test
+ public void testConsumePrefixedMessages() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ Thread.sleep(10000);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
+ from("google-calendar-stream://test?delay=5000&maxResults=5").to("mock:result");
+
+ }
+ };
+ }
+}
diff --git a/components/camel-google-calendar/src/test/resources/test-options.properties b/components/camel-google-calendar/src/test/resources/test-options.properties
index 3d7125f..eb80178 100644
--- a/components/camel-google-calendar/src/test/resources/test-options.properties
+++ b/components/camel-google-calendar/src/test/resources/test-options.properties
@@ -22,7 +22,7 @@
clientId=
clientSecret=
applicationName=camel-google-calendar/1.0
-#accessToken=
+accessToken=
refreshToken=
emailAddress=
p12FileName=
diff --git a/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentAutoConfiguration.java
new file mode 100644
index 0000000..91bf169
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentAutoConfiguration.java
@@ -0,0 +1,130 @@
+/**
+ * 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.google.calendar.stream.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.google.calendar.stream.GoogleCalendarStreamComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ GoogleCalendarStreamComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ GoogleCalendarStreamComponentConfiguration.class})
+public class GoogleCalendarStreamComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(GoogleCalendarStreamComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private GoogleCalendarStreamComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<GoogleCalendarStreamComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.google-calendar-stream");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "google-calendar-stream-component")
+ @ConditionalOnMissingBean(GoogleCalendarStreamComponent.class)
+ public GoogleCalendarStreamComponent configureGoogleCalendarStreamComponent()
+ throws Exception {
+ GoogleCalendarStreamComponent component = new GoogleCalendarStreamComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ CamelPropertiesHelper.setCamelProperties(camelContext,
+ nestedProperty, nestedParameters, false);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ CamelPropertiesHelper.setCamelProperties(camelContext, component,
+ parameters, false);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<GoogleCalendarStreamComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator
+ .evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.google-calendar-stream.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator
+ .evaluate(applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.google-calendar-stream.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentConfiguration.java
new file mode 100644
index 0000000..e1ed7ac
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentConfiguration.java
@@ -0,0 +1,199 @@
+/**
+ * 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.google.calendar.stream.springboot;
+
+import java.util.List;
+import javax.annotation.Generated;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * The google-mail component provides access to Google Mail.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.google-calendar-stream")
+public class GoogleCalendarStreamComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * Whether to enable auto configuration of the google-calendar-stream
+ * component. This is enabled by default.
+ */
+ private Boolean enabled;
+ /**
+ * The configuration
+ */
+ private GoogleCalendarStreamConfigurationNestedConfiguration configuration;
+ /**
+ * The client Factory. The option is a
+ * org.apache.camel.component.google.calendar.GoogleCalendarClientFactory
+ * type.
+ */
+ private String clientFactory;
+ /**
+ * Whether the component should resolve property placeholders on itself when
+ * starting. Only properties which are of String type can use property
+ * placeholders.
+ */
+ private Boolean resolvePropertyPlaceholders = true;
+
+ public GoogleCalendarStreamConfigurationNestedConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(
+ GoogleCalendarStreamConfigurationNestedConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public String getClientFactory() {
+ return clientFactory;
+ }
+
+ public void setClientFactory(String clientFactory) {
+ this.clientFactory = clientFactory;
+ }
+
+ public Boolean getResolvePropertyPlaceholders() {
+ return resolvePropertyPlaceholders;
+ }
+
+ public void setResolvePropertyPlaceholders(
+ Boolean resolvePropertyPlaceholders) {
+ this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+ }
+
+ public static class GoogleCalendarStreamConfigurationNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.google.calendar.stream.GoogleCalendarStreamConfiguration.class;
+ /**
+ * Client ID of the mail application
+ */
+ private String clientId;
+ /**
+ * Client secret of the mail application
+ */
+ private String clientSecret;
+ /**
+ * OAuth 2 access token. This typically expires after an hour so
+ * refreshToken is recommended for long term usage.
+ */
+ private String accessToken;
+ /**
+ * OAuth 2 refresh token. Using this, the Google Calendar component can
+ * obtain a new accessToken whenever the current one expires - a
+ * necessity if the application is long-lived.
+ */
+ private String refreshToken;
+ /**
+ * Google mail application name. Example would be camel-google-mail/1.0
+ */
+ private String applicationName;
+ /**
+ * Specifies the level of permissions you want a mail application to
+ * have to a user account. See
+ * https://developers.google.com/gmail/api/auth/scopes for more info.
+ */
+ private List scopes;
+ /**
+ * Specifies an index for the endpoint
+ */
+ private String index;
+ /**
+ * The query to execute on gmail box
+ */
+ private String query;
+ /**
+ * Max results to be returned
+ */
+ private Integer maxResults = 10;
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ public String getClientSecret() {
+ return clientSecret;
+ }
+
+ public void setClientSecret(String clientSecret) {
+ this.clientSecret = clientSecret;
+ }
+
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ public String getRefreshToken() {
+ return refreshToken;
+ }
+
+ public void setRefreshToken(String refreshToken) {
+ this.refreshToken = refreshToken;
+ }
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ public void setApplicationName(String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ public List getScopes() {
+ return scopes;
+ }
+
+ public void setScopes(List scopes) {
+ this.scopes = scopes;
+ }
+
+ public String getIndex() {
+ return index;
+ }
+
+ public void setIndex(String index) {
+ this.index = index;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+ public Integer getMaxResults() {
+ return maxResults;
+ }
+
+ public void setMaxResults(Integer maxResults) {
+ this.maxResults = maxResults;
+ }
+ }
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/resources/META-INF/spring.factories
index b3e3850..91e8028 100644
--- a/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/resources/META-INF/spring.factories
@@ -15,4 +15,6 @@
## limitations under the License.
## ---------------------------------------------------------------------------
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.google.calendar.springboot.GoogleCalendarComponentAutoConfiguration
+org.apache.camel.component.google.calendar.springboot.GoogleCalendarComponentAutoConfiguration,\
+org.apache.camel.component.google.calendar.stream.springboot.GoogleCalendarStreamComponentAutoConfiguration
+