Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twilio native support #1964

Merged
merged 2 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<module>test-support</module>
<module>testcontainers-support</module>
<module>mock-backend</module>
<module>wiremock</module>
</modules>

</project>
48 changes: 48 additions & 0 deletions integration-tests-support/wiremock/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
== WireMock test support

This module provides test support for http://wiremock.org/[WireMock]. This enables the HTTP interactions between Camel & third party services to be
stubbed, recorded & replayed.

=== Usage

Add the following test scoped dependency into the extension integration test pom.xml:

[source,xml]
----
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-wiremock-support</artifactId>
<scope>test</scope>
</dependency>
----

Next create a class that extends the abstract `WireMockTestResourceLifecycleManager`. You'll need to implement abstract methods:

* `getRecordTargetBaseUrl` - To specify the base URL of the service interactions to be recorded
* `isMockingEnabled` - To determine whether the test should start the mock server or invoke the real service

You can also override the `start` method to perform custom initialization logic and return additional configuration properties that Camel components may need.

`WireMockTestResourceLifecycleManager` sets a system property named `wiremock.url`, which is the base URL to the running WireMock server.
In playback mode, you'll need to configure the Camel component under test to direct its API calls to this URL.

==== Recording HTTP interactions

The fundamentals of WireMock record and playback are documented http://wiremock.org/docs/record-playback/[here]. Setup of the `WireMockServer` is already handled by
`WireMockTestResourceLifecycleManager`. All you need to do is ensure directory `src/test/resources/mappings` exists and to trigger recording by either:

System property `-Dwiremock.record=true`

Or

Environment variable `WIREMOCK_RECORD=true`

When all tests complete, the recorded HTTP interactions will show up in the 'mappings' directory. The recorded stub file names are quite complex, feel free
to update them to something more human friendly.

By default, stub mapping files are not saved when requests return an unsuccessful response code. You can alter this behaviour by overriding method `isDeleteRecordedMappingsOnError`.

It's important to inspect the recorded files for the presence of any real API keys, secrets or passwords and replace them with made up values.

WireMock generates new stub files on each recording, so it's a good idea to remove the existing contents from the 'mappings' directory
before a recording run.