Skip to content

Commit

Permalink
Twilio native support
Browse files Browse the repository at this point in the history
Fixes #1633
  • Loading branch information
jamesnetherton committed Oct 28, 2020
1 parent b7cde86 commit ff9dcf0
Show file tree
Hide file tree
Showing 23 changed files with 568 additions and 155 deletions.
14 changes: 10 additions & 4 deletions docs/modules/ROOT/pages/reference/extensions/twilio.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
= Twilio
:cq-artifact-id: camel-quarkus-twilio
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-description: Interact with Twilio REST APIs using Twilio Java SDK.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.4.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.4.0##

Interact with Twilio REST APIs using Twilio Java SDK.

Expand All @@ -31,3 +31,9 @@ Please refer to the above link for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== SSL in native mode

This extension auto-enables SSL support in native mode. Hence you do not need to add
`quarkus.ssl.native=true` to your `application.properties` yourself. See also
https://quarkus.io/guides/native-and-ssl[Quarkus SSL guide].
6 changes: 3 additions & 3 deletions docs/modules/ROOT/partials/reference/components/twilio.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-twilio
:cq-artifact-id-base: twilio
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.4.0
:cq-camel-part-name: twilio
:cq-camel-part-title: Twilio
:cq-camel-part-description: Interact with Twilio REST APIs using Twilio Java SDK.
Expand Down
1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
<module>stub</module>
<module>syslog</module>
<module>thrift</module>
<module>twilio</module>
<module>web3j</module>
<module>weka</module>
<module>wordpress</module>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<module>telegram</module>
<module>tika</module>
<module>timer</module>
<module>twilio</module>
<module>twitter</module>
<module>univocity-parsers</module>
<module>validator</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<name>Camel Quarkus :: Twilio :: Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-httpclient-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.quarkus.component.twilio.deployment;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import com.twilio.base.Creator;
import com.twilio.base.Deleter;
import com.twilio.base.Fetcher;
import com.twilio.base.Reader;
import com.twilio.base.Updater;
import com.twilio.type.Endpoint;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.joda.time.DateTimeZone;

class TwilioProcessor {

private static final String FEATURE = "camel-twilio";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
ExtensionSslNativeSupportBuildItem activateSslNativeSupport() {
return new ExtensionSslNativeSupportBuildItem(FEATURE);
}

@BuildStep
AdditionalApplicationArchiveMarkerBuildItem boxArchiveMarker() {
return new AdditionalApplicationArchiveMarkerBuildItem("com/twilio");
}

@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem combinedIndex) {
IndexView index = combinedIndex.getIndex();

// Register Twilio API CRUD generator classes for reflection
String[] reflectiveClasses = Stream.of(Creator.class, Deleter.class, Fetcher.class, Reader.class, Updater.class)
.map(aClass -> aClass.getName())
.map(DotName::createSimple)
.flatMap(dotName -> index.getAllKnownSubclasses(dotName).stream())
.map(classInfo -> classInfo.name().toString())
.filter(className -> className.startsWith("com.twilio.rest.api.v2010"))
.toArray(String[]::new);
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, reflectiveClasses));

// Register Twilio Endpoint implementors for reflection
String[] endpointImplementors = index.getAllKnownImplementors(DotName.createSimple(Endpoint.class.getName()))
.stream()
.map(classInfo -> classInfo.name().toString())
.toArray(String[]::new);

reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, endpointImplementors));
}

@BuildStep
NativeImageResourceBuildItem nativeImageResources() {
// Add Joda timezone resources into the native image as it is required by com.twilio.converter.DateConverter
List<String> timezones = new ArrayList<>();
for (String timezone : DateTimeZone.getAvailableIDs()) {
String[] zoneParts = timezone.split("/");
if (zoneParts.length == 2) {
timezones.add(String.format("org/joda/time/tz/data/%s/%s", zoneParts[0], zoneParts[1]));
}
}
return new NativeImageResourceBuildItem(timezones);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>1.4.0</camel.quarkus.nativeSince>
</properties>

<dependencyManagement>
Expand All @@ -47,6 +48,14 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
name: "Camel Twilio"
description: "Interact with Twilio REST APIs using Twilio Java SDK"
metadata:
unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/twilio.html"
categories:
- "integration"
status:
- "preview"
- "stable"
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<module>tarfile</module>
<module>telegram</module>
<module>tika</module>
<module>twilio</module>
<module>twitter</module>
<module>univocity-parsers</module>
<module>validator</module>
Expand Down
22 changes: 22 additions & 0 deletions integration-tests/twilio/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
== Camel Quarkus Twilio Integration Tests

By default the Twilio integration tests use WireMock to stub the API interactions.

To run the `camel-quarkus-twilio` integration tests against the real API, you must first create a Twilio account https://www.twilio.com/try-twilio.

Then find your API https://www.twilio.com/docs/iam/test-credentials[test credentials] and set the following environment variables:

[source,shell]
----
export TWILIO_USERNAME=your-user-name
export TWILIO_PASSWORD=your-password
export TWILIO_ACCOUNT_SID=your-account-sid
----

If the WireMock stub recordings need updating, then remove the existing files from `src/test/resources/mappings` and run tests with either:

System property `-Dwiremock.record=true`

Or

Set environment variable `WIREMOCK_RECORD=true`

0 comments on commit ff9dcf0

Please sign in to comment.