Repository: camel Updated Branches: refs/heads/master c0387103c -> c94c61982
CAMEL-11003: camel-google-calendar - Easier to configure scopes Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c94c6198 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c94c6198 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c94c6198 Branch: refs/heads/master Commit: c94c619828781277282bf5c6ae80d545466fdbc2 Parents: c038710 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Mar 13 13:54:17 2017 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Mar 13 17:04:06 2017 +0100 ---------------------------------------------------------------------- .../src/main/docs/google-calendar-component.adoc | 2 +- .../google/calendar/GoogleCalendarComponent.java | 13 ++++++++++++- .../google/calendar/GoogleCalendarConfiguration.java | 11 ++++++----- .../src/test/resources/log4j2.properties | 9 +++++++-- 4 files changed, 26 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c94c6198/components/camel-google-calendar/src/main/docs/google-calendar-component.adoc ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/docs/google-calendar-component.adoc b/components/camel-google-calendar/src/main/docs/google-calendar-component.adoc index 4ca05e4..8e55fbc 100644 --- a/components/camel-google-calendar/src/main/docs/google-calendar-component.adoc +++ b/components/camel-google-calendar/src/main/docs/google-calendar-component.adoc @@ -86,7 +86,7 @@ with the following path and query parameters: | inBody | common | | String | Sets the name of a parameter to be passed in the exchange In Body | p12FileName | common | | String | The name of the p12 file which has the private key to use with the Google Service Account. | refreshToken | common | | String | 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. -| scopes | common | https://www.googleapis.com/auth/calendar | List | Specifies the level of permissions you want a calendar application to have to a user account. See https://developers.google.com/google-apps/calendar/auth for more info. +| scopes | common | https://www.googleapis.com/auth/calendar | String | Specifies the level of permissions you want a calendar application to have to a user account. You can separate multiple scopes by comma. See https://developers.google.com/google-apps/calendar/auth for more info. | user | common | | String | The email address of the user the application is trying to impersonate in the service account flow | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN or ERROR level and ignored. | exceptionHandler | consumer (advanced) | | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN or ERROR level and ignored. http://git-wip-us.apache.org/repos/asf/camel/blob/c94c6198/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java index 109fdf5..040eb56 100644 --- a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarComponent.java @@ -16,6 +16,10 @@ */ package org.apache.camel.component.google.calendar; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import com.google.api.services.calendar.Calendar; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; @@ -49,8 +53,15 @@ public class GoogleCalendarComponent extends AbstractApiComponent<GoogleCalendar public Calendar getClient(GoogleCalendarConfiguration config) { if (client == null) { + + List<String> list = null; + if (config.getScopes() != null) { + String[] arr = config.getScopes().split(","); + list = Arrays.asList(arr); + } + client = getClientFactory().makeClient(config.getClientId(), - config.getClientSecret(), config.getScopes(), + config.getClientSecret(), list, config.getApplicationName(), config.getRefreshToken(), config.getAccessToken(), config.getEmailAddress(), config.getP12FileName(), config.getUser()); http://git-wip-us.apache.org/repos/asf/camel/blob/c94c6198/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java index dae776c..250fc45 100644 --- a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java +++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConfiguration.java @@ -31,7 +31,6 @@ import org.apache.camel.spi.UriPath; */ @UriParams public class GoogleCalendarConfiguration { - private static final List<String> DEFAULT_SCOPES = Arrays.asList(CalendarScopes.CALENDAR); @UriPath @Metadata(required = "true") @@ -42,7 +41,7 @@ public class GoogleCalendarConfiguration { private String methodName; @UriParam(defaultValue = CalendarScopes.CALENDAR) - private List<String> scopes = DEFAULT_SCOPES; + private String scopes = CalendarScopes.CALENDAR; @UriParam private String clientId; @@ -156,14 +155,16 @@ public class GoogleCalendarConfiguration { this.applicationName = applicationName; } - public List<String> getScopes() { + public String getScopes() { return scopes; } /** - * Specifies the level of permissions you want a calendar application to have to a user account. See https://developers.google.com/google-apps/calendar/auth for more info. + * Specifies the level of permissions you want a calendar application to have to a user account. + * You can separate multiple scopes by comma. + * See https://developers.google.com/google-apps/calendar/auth for more info. */ - public void setScopes(List<String> scopes) { + public void setScopes(String scopes) { this.scopes = scopes; } http://git-wip-us.apache.org/repos/asf/camel/blob/c94c6198/components/camel-google-calendar/src/test/resources/log4j2.properties ---------------------------------------------------------------------- diff --git a/components/camel-google-calendar/src/test/resources/log4j2.properties b/components/camel-google-calendar/src/test/resources/log4j2.properties index 93d8e72..c271dfa 100644 --- a/components/camel-google-calendar/src/test/resources/log4j2.properties +++ b/components/camel-google-calendar/src/test/resources/log4j2.properties @@ -15,9 +15,14 @@ ## limitations under the License. ## --------------------------------------------------------------------------- +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-google-calendar-test.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n appender.out.type = Console appender.out.name = out appender.out.layout.type = PatternLayout -appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n rootLogger.level = INFO -rootLogger.appenderRef.out.ref = out +rootLogger.appenderRef.file.ref = file