Skip to content

Commit

Permalink
Ref apache#4220: Add the camel-swift extension (apache#4315)
Browse files Browse the repository at this point in the history
## Motivation

There is a new component (dataformat) called `camel-swift` that we would like to add to the project.

## Modifications:

* Creates the new extension thanks to the maven plugin
* Adds support of the JVM mode for both types of messages (MX and MT)
* Adds support of the native mode to MT messages only because MX messages bring too many classes, methods, and fields to access by reflection which slows down the native image build
  • Loading branch information
essobedo authored and JiriOndrusek committed Jun 27, 2023
1 parent 38a5512 commit 9b89149
Show file tree
Hide file tree
Showing 33 changed files with 1,686 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/modules/ROOT/examples/dataformats/swiftMt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Do not edit directly!
# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
cqArtifactId: camel-quarkus-swift
cqArtifactIdBase: swift
cqNativeSupported: true
cqStatus: Stable
cqDeprecated: false
cqJvmSince: 3.0.0
cqNativeSince: 3.0.0
cqCamelPartName: swiftMt
cqCamelPartTitle: SWIFT MT
cqCamelPartDescription: Encode and decode SWIFT MT messages.
cqExtensionPageTitle: SWIFT
13 changes: 13 additions & 0 deletions docs/modules/ROOT/examples/dataformats/swiftMx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Do not edit directly!
# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
cqArtifactId: camel-quarkus-swift
cqArtifactIdBase: swift
cqNativeSupported: true
cqStatus: Stable
cqDeprecated: false
cqJvmSince: 3.0.0
cqNativeSince: 3.0.0
cqCamelPartName: swiftMx
cqCamelPartTitle: SWIFT MX
cqCamelPartDescription: Encode and decode SWIFT MX messages.
cqExtensionPageTitle: SWIFT
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
*** xref:reference/extensions/soap.adoc[SOAP dataformat]
*** xref:reference/extensions/sql.adoc[SQL]
*** xref:reference/extensions/ssh.adoc[SSH]
*** xref:reference/extensions/swift.adoc[SWIFT]
*** xref:reference/extensions/saga.adoc[Saga]
*** xref:reference/extensions/salesforce.adoc[Salesforce]
*** xref:reference/extensions/scheduler.adoc[Scheduler]
Expand Down
56 changes: 56 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/swift.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
[id="extensions-swift"]
= SWIFT
:linkattrs:
:cq-artifact-id: camel-quarkus-swift
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: Encode and decode SWIFT messages.
:cq-deprecated: false
:cq-jvm-since: 3.0.0
:cq-native-since: 3.0.0

ifeval::[{doc-show-badges} == true]
[.badges]
[.badge-key]##JVM since##[.badge-supported]##3.0.0## [.badge-key]##Native since##[.badge-supported]##3.0.0##
endif::[]

Encode and decode SWIFT messages.

[id="extensions-swift-whats-inside"]
== What's inside

* xref:{cq-camel-components}:dataformats:swiftMt-dataformat.adoc[SWIFT MT data format]
* xref:{cq-camel-components}:dataformats:swiftMx-dataformat.adoc[SWIFT MX data format]

Please refer to the above links for usage and configuration details.

[id="extensions-swift-maven-coordinates"]
== Maven coordinates

https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-swift[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-swift</artifactId>
</dependency>
----
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]

[id="extensions-swift-camel-quarkus-limitations"]
== Camel Quarkus limitations

[id="extensions-swift-limitations-mx-types"]
=== MX types

The MX message types are not supported in native mode because it drastically slows down the native image build due to an
excessive amount of classes, methods, and fields to access by reflection that need to be registered.

1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
<module>stax</module>
<module>stream</module>
<module>stringtemplate</module>
<module>swift</module>
<module>syslog</module>
<module>tarfile</module>
<module>telegram</module>
Expand Down
67 changes: 67 additions & 0 deletions extensions/swift/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-swift-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-swift-deployment</artifactId>
<name>Camel Quarkus :: SWIFT :: Deployment</name>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jaxb-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-swift</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.swift.deployment;

import com.prowidesoftware.swift.model.AbstractMessage;
import com.prowidesoftware.swift.model.MessageStandardType;
import com.prowidesoftware.swift.model.SwiftBlock;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.UnparsedTextList;
import com.prowidesoftware.swift.model.field.Field;
import com.prowidesoftware.swift.model.field.Narrative;
import com.prowidesoftware.swift.model.field.StructuredNarrative;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;

class SwiftProcessor {

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

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

@BuildStep
void indexDependencies(BuildProducer<IndexDependencyBuildItem> indexedDependency) {
// The dependency for MX message types
// Adding this dependency slows down drastically the native image build since it brings a lot of reflection
// indexedDependency.produce(new IndexDependencyBuildItem("com.prowidesoftware", "pw-iso20022"));
// The dependency for MT message types
indexedDependency.produce(new IndexDependencyBuildItem("com.prowidesoftware", "pw-swift-core"));
}

@BuildStep
void registerOtherTypesForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {

reflectiveClass.produce(
ReflectiveClassBuildItem
.builder(Tag.class, UnparsedTextList.class, MessageStandardType.class, Narrative.class,
StructuredNarrative.class)
.fields()
.build());

}

@BuildStep
void registerMessageTypesForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
CombinedIndexBuildItem combinedIndex) {
reflectiveClass.produce(ReflectiveClassBuildItem.builder(AbstractMessage.class)
.methods().fields().build());
registerForReflection(combinedIndex, AbstractMessage.class.getName(), reflectiveClass);
}

@BuildStep
void registerFieldTypesForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
CombinedIndexBuildItem combinedIndex) {

registerForReflection(combinedIndex, Field.class.getName(), reflectiveClass);
}

@BuildStep
void registerSwiftBlocksForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
CombinedIndexBuildItem combinedIndex) {
reflectiveClass.produce(ReflectiveClassBuildItem.builder(SwiftBlock.class).fields().build());
registerForReflection(combinedIndex, SwiftBlock.class.getName(), reflectiveClass);
}

private static void registerForReflection(CombinedIndexBuildItem combinedIndex, String className,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
IndexView index = combinedIndex.getIndex();

String[] classes = index.getAllKnownSubclasses(DotName.createSimple(className))
.stream()
.map(classInfo -> classInfo.name().toString())
.toArray(String[]::new);

// Register classes for refection
reflectiveClass.produce(ReflectiveClassBuildItem.builder(classes).fields().build());
}
}
39 changes: 39 additions & 0 deletions extensions/swift/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-extensions</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-swift-parent</artifactId>
<name>Camel Quarkus :: SWIFT</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
Loading

0 comments on commit 9b89149

Please sign in to comment.