CAMEL-10381 - fix NPE from component configuration
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/37a12df6 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/37a12df6 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/37a12df6 Branch: refs/heads/camel-2.18.x Commit: 37a12df6a3d6780495b249b959a25966b62afb69 Parents: fa1789a Author: Jonathan Anstey <jans...@gmail.com> Authored: Tue Oct 11 16:39:15 2016 -0230 Committer: Jonathan Anstey <jans...@gmail.com> Committed: Tue Oct 11 16:41:00 2016 -0230 ---------------------------------------------------------------------- components-starter/pom.xml | 9 +++ .../google/mail/GoogleMailComponent.java | 10 ++- .../google/mail/GoogleMailEndpoint.java | 2 +- .../google/mail/GmailConfigurationTest.java | 73 ++++++++++++++++++++ 4 files changed, 90 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/37a12df6/components-starter/pom.xml ---------------------------------------------------------------------- diff --git a/components-starter/pom.xml b/components-starter/pom.xml index c284305..e8a168a 100644 --- a/components-starter/pom.xml +++ b/components-starter/pom.xml @@ -77,12 +77,14 @@ <module>camel-beanio-starter</module> <module>camel-beanstalk-starter</module> <module>camel-bindy-starter</module> + <module>camel-blueprint-starter</module> <module>camel-boon-starter</module> <module>camel-box-starter</module> <module>camel-braintree-starter</module> <module>camel-cache-starter</module> <module>camel-cassandraql-starter</module> <module>camel-castor-starter</module> + <module>camel-cdi-starter</module> <module>camel-chronicle-starter</module> <module>camel-chunk-starter</module> <module>camel-cm-sms-starter</module> @@ -105,6 +107,7 @@ <module>camel-dropbox-starter</module> <module>camel-eclipse-starter</module> <module>camel-ehcache-starter</module> + <module>camel-ejb-starter</module> <module>camel-elasticsearch-starter</module> <module>camel-elsql-starter</module> <module>camel-etcd-starter</module> @@ -140,6 +143,7 @@ <module>camel-http-starter</module> <module>camel-http4-starter</module> <module>camel-hystrix-starter</module> + <module>camel-ibatis-starter</module> <module>camel-ical-starter</module> <module>camel-ignite-starter</module> <module>camel-infinispan-starter</module> @@ -153,6 +157,7 @@ <module>camel-jaxb-starter</module> <module>camel-jbpm-starter</module> <module>camel-jcache-starter</module> + <module>camel-jclouds-starter</module> <module>camel-jcr-starter</module> <module>camel-jdbc-starter</module> <module>camel-jetty-common-starter</module> @@ -210,6 +215,7 @@ <module>camel-pgevent-starter</module> <module>camel-printer-starter</module> <module>camel-protobuf-starter</module> + <module>camel-quartz-starter</module> <module>camel-quartz2-starter</module> <module>camel-quickfix-starter</module> <module>camel-rabbitmq-starter</module> @@ -239,6 +245,7 @@ <module>camel-snmp-starter</module> <module>camel-soap-starter</module> <module>camel-solr-starter</module> + <module>camel-spark-rest-starter</module> <module>camel-spark-starter</module> <module>camel-splunk-starter</module> <module>camel-spring-batch-starter</module> @@ -262,6 +269,8 @@ <module>camel-tagsoup-starter</module> <module>camel-tarfile-starter</module> <module>camel-telegram-starter</module> + <module>camel-test-starter</module> + <module>camel-testng-starter</module> <module>camel-twitter-starter</module> <module>camel-undertow-starter</module> <module>camel-univocity-parsers-starter</module> http://git-wip-us.apache.org/repos/asf/camel/blob/37a12df6/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailComponent.java b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailComponent.java index b6896d6..7871a51 100644 --- a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailComponent.java +++ b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailComponent.java @@ -45,10 +45,11 @@ public class GoogleMailComponent extends AbstractApiComponent<GoogleMailApiName, return GoogleMailApiName.fromValue(apiNameStr); } - public Gmail getClient() { + public Gmail getClient(GoogleMailConfiguration googleMailConfiguration) { if (client == null) { - client = getClientFactory().makeClient(configuration.getClientId(), configuration.getClientSecret(), configuration.getScopes(), configuration.getApplicationName(), - configuration.getRefreshToken(), configuration.getAccessToken()); + client = getClientFactory().makeClient(googleMailConfiguration.getClientId(), googleMailConfiguration.getClientSecret(), + googleMailConfiguration.getScopes(), googleMailConfiguration.getApplicationName(), + googleMailConfiguration.getRefreshToken(), googleMailConfiguration.getAccessToken()); } return client; } @@ -70,6 +71,9 @@ public class GoogleMailComponent extends AbstractApiComponent<GoogleMailApiName, @Override public GoogleMailConfiguration getConfiguration() { + if (configuration == null) { + configuration = new GoogleMailConfiguration(); + } return super.getConfiguration(); } http://git-wip-us.apache.org/repos/asf/camel/blob/37a12df6/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java index b07cfde..7810839 100644 --- a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java +++ b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java @@ -107,7 +107,7 @@ public class GoogleMailEndpoint extends AbstractApiEndpoint<GoogleMailApiName, G } public Gmail getClient() { - return ((GoogleMailComponent) getComponent()).getClient(); + return ((GoogleMailComponent) getComponent()).getClient(configuration); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/37a12df6/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java b/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java new file mode 100644 index 0000000..cc53619 --- /dev/null +++ b/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java @@ -0,0 +1,73 @@ +/** + * 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.mail; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.google.mail.internal.GmailUsersMessagesApiMethod; +import org.apache.camel.component.google.mail.internal.GoogleMailApiCollection; +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test class for {@link com.google.api.services.gmail.Gmail$Users$Messages} + * APIs. + */ +public class GmailConfigurationTest extends AbstractGoogleMailTestSupport { + + // userid of the currently authenticated user + public static final String CURRENT_USERID = "me"; + private static final Logger LOG = LoggerFactory.getLogger(GmailConfigurationTest.class); + private static final String PATH_PREFIX = GoogleMailApiCollection.getCollection().getApiName(GmailUsersMessagesApiMethod.class).getName(); + private static final String TEST_URI = "google-mail://" + PATH_PREFIX + "/send?clientId=a&clientSecret=b&applicationName=c&accessToken=d&refreshToken=e"; + + @Override + protected CamelContext createCamelContext() throws Exception { + final CamelContext context = new DefaultCamelContext(createRegistry()); + + // add GoogleMailComponent to Camel context but don't set up configuration + final GoogleMailComponent component = new GoogleMailComponent(context); + context.addComponent("google-mail", component); + + return context; + } + + @Test + public void testConfiguration() throws Exception { + GoogleMailEndpoint endpoint = getMandatoryEndpoint(TEST_URI, GoogleMailEndpoint.class); + GoogleMailConfiguration configuration = endpoint.getConfiguration(); + assertNotNull(configuration); + assertEquals("a", configuration.getClientId()); + assertEquals("b", configuration.getClientSecret()); + assertEquals("c", configuration.getApplicationName()); + assertEquals("d", configuration.getAccessToken()); + assertEquals("e", configuration.getRefreshToken()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + // test route for send + from("direct://SEND").to(TEST_URI); + } + }; + } +}