From 782460550fd68598ca6beec00c7ecbe2939b584c Mon Sep 17 00:00:00 2001 From: Nicolas Filotto Date: Mon, 5 Dec 2022 19:32:14 +0100 Subject: [PATCH] Ref #4220: Add the camel-swift extension --- .../ROOT/examples/dataformats/swiftMt.yml | 13 ++ .../ROOT/examples/dataformats/swiftMx.yml | 13 ++ docs/modules/ROOT/nav.adoc | 1 + .../pages/reference/extensions/swift.adoc | 56 ++++++ extensions/pom.xml | 1 + extensions/swift/deployment/pom.xml | 67 +++++++ .../swift/deployment/SwiftProcessor.java | 100 ++++++++++ extensions/swift/pom.xml | 39 ++++ extensions/swift/runtime/pom.xml | 104 ++++++++++ .../runtime/src/main/doc/limitations.adoc | 4 + .../resources/META-INF/quarkus-extension.yaml | 31 +++ integration-tests/pom.xml | 1 + integration-tests/swift/pom.xml | 131 +++++++++++++ .../swift/mt/it/SwiftMtResource.java | 78 ++++++++ .../component/swift/mt/it/SwiftMtRoutes.java | 32 +++ .../swift/mx/it/SwiftMxResource.java | 103 ++++++++++ .../component/swift/mx/it/SwiftMxRoutes.java | 40 ++++ .../component/swift/mt/it/SwiftMtIT.java | 24 +++ .../component/swift/mt/it/SwiftMtTest.java | 68 +++++++ .../component/swift/mx/it/SwiftMxIT.java | 26 +++ .../component/swift/mx/it/SwiftMxTest.java | 89 +++++++++ .../swift/src/test/resources/mt/message1.txt | 55 ++++++ .../swift/src/test/resources/mt/message2.json | 128 ++++++++++++ .../swift/src/test/resources/mt/message2.txt | 20 ++ .../swift/src/test/resources/mx/message1.xml | 38 ++++ .../swift/src/test/resources/mx/message2.json | 184 ++++++++++++++++++ .../swift/src/test/resources/mx/message2.xml | 129 ++++++++++++ .../swift/src/test/resources/mx/message3.xml | 43 ++++ poms/bom/pom.xml | 15 ++ .../src/main/generated/flattened-full-pom.xml | 15 ++ .../main/generated/flattened-reduced-pom.xml | 15 ++ .../flattened-reduced-verbose-pom.xml | 15 ++ tooling/scripts/test-categories.yaml | 1 + 33 files changed, 1679 insertions(+) create mode 100644 docs/modules/ROOT/examples/dataformats/swiftMt.yml create mode 100644 docs/modules/ROOT/examples/dataformats/swiftMx.yml create mode 100644 docs/modules/ROOT/pages/reference/extensions/swift.adoc create mode 100644 extensions/swift/deployment/pom.xml create mode 100644 extensions/swift/deployment/src/main/java/org/apache/camel/quarkus/component/swift/deployment/SwiftProcessor.java create mode 100644 extensions/swift/pom.xml create mode 100644 extensions/swift/runtime/pom.xml create mode 100644 extensions/swift/runtime/src/main/doc/limitations.adoc create mode 100644 extensions/swift/runtime/src/main/resources/META-INF/quarkus-extension.yaml create mode 100644 integration-tests/swift/pom.xml create mode 100644 integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtResource.java create mode 100644 integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtRoutes.java create mode 100644 integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mx/it/SwiftMxResource.java create mode 100644 integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mx/it/SwiftMxRoutes.java create mode 100644 integration-tests/swift/src/test/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtIT.java create mode 100644 integration-tests/swift/src/test/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtTest.java create mode 100644 integration-tests/swift/src/test/java/org/apache/camel/quarkus/component/swift/mx/it/SwiftMxIT.java create mode 100644 integration-tests/swift/src/test/java/org/apache/camel/quarkus/component/swift/mx/it/SwiftMxTest.java create mode 100644 integration-tests/swift/src/test/resources/mt/message1.txt create mode 100644 integration-tests/swift/src/test/resources/mt/message2.json create mode 100644 integration-tests/swift/src/test/resources/mt/message2.txt create mode 100644 integration-tests/swift/src/test/resources/mx/message1.xml create mode 100644 integration-tests/swift/src/test/resources/mx/message2.json create mode 100644 integration-tests/swift/src/test/resources/mx/message2.xml create mode 100644 integration-tests/swift/src/test/resources/mx/message3.xml diff --git a/docs/modules/ROOT/examples/dataformats/swiftMt.yml b/docs/modules/ROOT/examples/dataformats/swiftMt.yml new file mode 100644 index 000000000000..d408659fecf1 --- /dev/null +++ b/docs/modules/ROOT/examples/dataformats/swiftMt.yml @@ -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 diff --git a/docs/modules/ROOT/examples/dataformats/swiftMx.yml b/docs/modules/ROOT/examples/dataformats/swiftMx.yml new file mode 100644 index 000000000000..35bc055967b3 --- /dev/null +++ b/docs/modules/ROOT/examples/dataformats/swiftMx.yml @@ -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 diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index 55b6f8ef0192..d723a520204a 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -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] diff --git a/docs/modules/ROOT/pages/reference/extensions/swift.adoc b/docs/modules/ROOT/pages/reference/extensions/swift.adoc new file mode 100644 index 000000000000..dfd5704aa397 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/swift.adoc @@ -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] +---- + + org.apache.camel.quarkus + camel-quarkus-swift + +---- +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. + diff --git a/extensions/pom.xml b/extensions/pom.xml index 0c9bb9cf1eee..93adf57c2eba 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -225,6 +225,7 @@ stax stream stringtemplate + swift syslog tarfile telegram diff --git a/extensions/swift/deployment/pom.xml b/extensions/swift/deployment/pom.xml new file mode 100644 index 000000000000..a8dcc0665383 --- /dev/null +++ b/extensions/swift/deployment/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-swift-parent + 3.0.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-swift-deployment + Camel Quarkus :: SWIFT :: Deployment + + + + org.apache.camel.quarkus + camel-quarkus-core-deployment + + + org.apache.camel.quarkus + camel-quarkus-jaxb-deployment + + + org.apache.camel.quarkus + camel-quarkus-swift + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + diff --git a/extensions/swift/deployment/src/main/java/org/apache/camel/quarkus/component/swift/deployment/SwiftProcessor.java b/extensions/swift/deployment/src/main/java/org/apache/camel/quarkus/component/swift/deployment/SwiftProcessor.java new file mode 100644 index 000000000000..af36412a9ca3 --- /dev/null +++ b/extensions/swift/deployment/src/main/java/org/apache/camel/quarkus/component/swift/deployment/SwiftProcessor.java @@ -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 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 reflectiveClass) { + + reflectiveClass.produce( + ReflectiveClassBuildItem + .builder(Tag.class, UnparsedTextList.class, MessageStandardType.class, Narrative.class, + StructuredNarrative.class) + .fields() + .build()); + + } + + @BuildStep + void registerMessageTypesForReflection(BuildProducer reflectiveClass, + CombinedIndexBuildItem combinedIndex) { + reflectiveClass.produce(ReflectiveClassBuildItem.builder(AbstractMessage.class) + .methods().fields().build()); + registerForReflection(combinedIndex, AbstractMessage.class.getName(), reflectiveClass); + } + + @BuildStep + void registerFieldTypesForReflection(BuildProducer reflectiveClass, + CombinedIndexBuildItem combinedIndex) { + + registerForReflection(combinedIndex, Field.class.getName(), reflectiveClass); + } + + @BuildStep + void registerSwiftBlocksForReflection(BuildProducer 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 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()); + } +} diff --git a/extensions/swift/pom.xml b/extensions/swift/pom.xml new file mode 100644 index 000000000000..289fa8cd1285 --- /dev/null +++ b/extensions/swift/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-extensions + 3.0.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-swift-parent + Camel Quarkus :: SWIFT + pom + + + deployment + runtime + + diff --git a/extensions/swift/runtime/pom.xml b/extensions/swift/runtime/pom.xml new file mode 100644 index 000000000000..9427c2d0e88f --- /dev/null +++ b/extensions/swift/runtime/pom.xml @@ -0,0 +1,104 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-swift-parent + 3.0.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-swift + Camel Quarkus :: SWIFT :: Runtime + Encode and decode SWIFT messages. + + + 3.0.0 + 3.0.0 + + + + + org.apache.camel.quarkus + camel-quarkus-core + + + org.apache.camel.quarkus + camel-quarkus-jaxb + + + org.apache.camel + camel-swift + + + + + + + io.quarkus + quarkus-extension-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + + + full + + + !quickly + + + + + + org.apache.camel.quarkus + camel-quarkus-maven-plugin + + + update-extension-doc-page + + update-extension-doc-page + + process-classes + + + + + + + + diff --git a/extensions/swift/runtime/src/main/doc/limitations.adoc b/extensions/swift/runtime/src/main/doc/limitations.adoc new file mode 100644 index 000000000000..0448a2e631ad --- /dev/null +++ b/extensions/swift/runtime/src/main/doc/limitations.adoc @@ -0,0 +1,4 @@ +=== 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. diff --git a/extensions/swift/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/swift/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 000000000000..8cad8b67a4ad --- /dev/null +++ b/extensions/swift/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,31 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel SWIFT" +description: "Encode and decode SWIFT messages" +metadata: + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/swift.html" + categories: + - "integration" + status: + - "stable" diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 285767dce0ac..7379b11fe16f 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -213,6 +213,7 @@ ssh stax stringtemplate + swift syslog tarfile diff --git a/integration-tests/swift/pom.xml b/integration-tests/swift/pom.xml new file mode 100644 index 000000000000..db4b21b2f360 --- /dev/null +++ b/integration-tests/swift/pom.xml @@ -0,0 +1,131 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-build-parent-it + 3.0.0-SNAPSHOT + ../../poms/build-parent-it/pom.xml + + + camel-quarkus-integration-test-swift + Camel Quarkus :: Integration Tests :: SWIFT + Integration tests for Camel Quarkus SWIFT extension + + + + org.apache.camel.quarkus + camel-quarkus-swift + + + io.quarkus + quarkus-resteasy + + + commons-io + commons-io + + + org.apache.camel.quarkus + camel-quarkus-direct + runtime + + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + maven-surefire-plugin + + --add-opens java.base/java.time=ALL-UNNAMED + + + + + + + + native + + + native + + + + native + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + + + virtualDependencies + + + !noVirtualDependencies + + + + + + org.apache.camel.quarkus + camel-quarkus-swift-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + diff --git a/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtResource.java b/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtResource.java new file mode 100644 index 000000000000..612d38710729 --- /dev/null +++ b/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtResource.java @@ -0,0 +1,78 @@ +/* + * 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.mt.it; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import com.prowidesoftware.swift.model.mt.mt1xx.MT103; +import com.prowidesoftware.swift.model.mt.mt5xx.MT515; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import org.apache.camel.ProducerTemplate; + +@Path("/swift-mt") +@ApplicationScoped +public class SwiftMtResource { + + @Inject + ProducerTemplate producerTemplate; + + @Path("/unmarshal") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String unmarshal(byte[] message) { + final MT515 response = producerTemplate.requestBody("direct:mt.unmarshal", message, MT515.class); + return response.getMessageType(); + } + + @Path("/unmarshaldsl") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String unmarshalDsl(byte[] message) { + final MT515 response = producerTemplate.requestBody("direct:mt.unmarshaldsl", message, MT515.class); + return response.getMessageType(); + } + + @Path("/marshal") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String marshal(byte[] body) throws IOException { + MT103 message = MT103.parse(new ByteArrayInputStream(body)); + final Object response = producerTemplate.requestBody("direct:mt.marshal", message); + MT103 actual = MT103.parse((InputStream) response); + return actual.getMessageType(); + } + + @Path("/marshalJson") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.APPLICATION_JSON) + public Object marshalJson(byte[] body) throws IOException { + MT103 message = MT103.parse(new ByteArrayInputStream(body)); + return producerTemplate.requestBody("direct:mt.marshalJson", message); + } +} diff --git a/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtRoutes.java b/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtRoutes.java new file mode 100644 index 000000000000..9c6ecc956e74 --- /dev/null +++ b/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mt/it/SwiftMtRoutes.java @@ -0,0 +1,32 @@ +/* + * 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.mt.it; + +import jakarta.enterprise.context.ApplicationScoped; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.dataformat.SwiftMtDataFormat; + +@ApplicationScoped +public class SwiftMtRoutes extends RouteBuilder { + @Override + public void configure() { + from("direct:mt.unmarshal").unmarshal(new SwiftMtDataFormat()); + from("direct:mt.unmarshaldsl").unmarshal().swiftMt(); + from("direct:mt.marshal").marshal(new SwiftMtDataFormat()); + from("direct:mt.marshalJson").marshal(new SwiftMtDataFormat("true")); + } +} diff --git a/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mx/it/SwiftMxResource.java b/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mx/it/SwiftMxResource.java new file mode 100644 index 000000000000..520520429e66 --- /dev/null +++ b/integration-tests/swift/src/main/java/org/apache/camel/quarkus/component/swift/mx/it/SwiftMxResource.java @@ -0,0 +1,103 @@ +/* + * 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.mx.it; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +import com.prowidesoftware.swift.model.mx.MxCamt04800103; +import com.prowidesoftware.swift.model.mx.MxPacs00800107; +import com.prowidesoftware.swift.model.mx.sys.MxXsys01100102; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import org.apache.camel.ProducerTemplate; +import org.apache.commons.io.IOUtils; + +@Path("/swift-mx") +@ApplicationScoped +public class SwiftMxResource { + + @Inject + ProducerTemplate producerTemplate; + + @Path("/unmarshal") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String unmarshal(byte[] message) { + final MxCamt04800103 response = producerTemplate.requestBody("direct:mx.unmarshal", message, MxCamt04800103.class); + return response.getMxId().id(); + } + + @Path("/unmarshaldsl") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String unmarshalDsl(byte[] message) { + final MxCamt04800103 response = producerTemplate.requestBody("direct:mx.unmarshaldsl", message, MxCamt04800103.class); + return response.getMxId().id(); + } + + @Path("/unmarshalFull") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String unmarshalFull(byte[] message) { + final MxXsys01100102 response = producerTemplate.requestBody("direct:mx.unmarshalFull", message, MxXsys01100102.class); + return response.getMxId().id(); + } + + @Path("/marshal") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String marshal(byte[] body) throws IOException { + MxPacs00800107 message = MxPacs00800107.parse(new String(body)); + final Object response = producerTemplate.requestBody("direct:mx.marshal", message); + MxPacs00800107 actual = MxPacs00800107.parse(IOUtils.toString((InputStream) response, StandardCharsets.UTF_8)); + return actual.getMxId().id(); + } + + @Path("/marshalFull") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public boolean marshalFull(byte[] body) throws IOException { + MxPacs00800107 message = MxPacs00800107.parse(new String(body)); + final Object response = producerTemplate.requestBody("direct:mx.marshalFull", message); + BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) response, StandardCharsets.UTF_8)); + String line = reader.readLine(); + return line.contains(" + + + + + 001 + + + + + CARE + + + + + + 1234.0 + + + + diff --git a/integration-tests/swift/src/test/resources/mx/message2.json b/integration-tests/swift/src/test/resources/mx/message2.json new file mode 100644 index 000000000000..861256c1cf18 --- /dev/null +++ b/integration-tests/swift/src/test/resources/mx/message2.json @@ -0,0 +1,184 @@ +{ + "fiToFICstmrCdtTrf": { + "grpHdr": { + "msgId": "823823423", + "creDtTm": { + "dateTime": { + "date": { + "year": 2019, + "month": 10, + "day": 19 + }, + "time": { + "hour": 21, + "minute": 0, + "second": 45, + "nano": 0 + } + }, + "offset": { + "totalSeconds": 0 + } + }, + "btchBookg": false, + "nbOfTxs": "1", + "ctrlSum": 10000, + "ttlIntrBkSttlmAmt": { + "value": 10000, + "ccy": "USD" + }, + "intrBkSttlmDt": { + "year": 2019, + "month": 10, + "day": 28 + }, + "sttlmInf": { + "sttlmMtd": "INDA" + }, + "instgAgt": { + "finInstnId": { + "bicfi": "CITTGB2LPBG", + "nm": "Lionel Messi", + "othr": { + "id": "2342342342", + "issr": "FOOISSUER" + } + } + }, + "instdAgt": { + "finInstnId": { + "bicfi": "ICBCUS4CXXX", + "nm": "Manu Ginobili", + "pstlAdr": { + "adrTp": "PBOX", + "dept": "1", + "subDept": "DFGH", + "strtNm": "My Street", + "bldgNb": "1122", + "pstCd": "10002", + "twnNm": "Los Angeles", + "ctrySubDvsn": "ABCD" + } + } + } + }, + "cdtTrfTxInf": [ + { + "pmtId": { + "instrId": "2233445566", + "endToEndId": "987654321987654321", + "txId": "123456789", + "clrSysRef": "SDSDS333" + }, + "intrBkSttlmAmt": { + "value": 5000, + "ccy": "USD" + }, + "intrBkSttlmDt": { + "year": 2019, + "month": 7, + "day": 31 + }, + "sttlmPrty": "URGT", + "accptncDtTm": { + "dateTime": { + "date": { + "year": 2019, + "month": 4, + "day": 28 + }, + "time": { + "hour": 20, + "minute": 54, + "second": 39, + "nano": 0 + } + }, + "offset": { + "totalSeconds": 0 + } + }, + "poolgAdjstmntDt": { + "year": 2019, + "month": 4, + "day": 29 + }, + "instdAmt": { + "value": 5000, + "ccy": "USD" + }, + "chrgBr": "SHAR", + "dbtr": { + "nm": "Jhon Doe", + "pstlAdr": { + "adrTp": "HOME", + "dept": "ABCD", + "subDept": "1", + "strtNm": "Foo Street", + "bldgNb": "1", + "pstCd": "1234", + "twnNm": "Buenos Aires", + "ctrySubDvsn": "CABA", + "ctry": "AR" + }, + "ctryOfRes": "AR" + }, + "dbtrAgt": { + "finInstnId": { + "bicfi": "ITUSUSP1XXX", + "nm": "Foo Corp" + } + }, + "cdtrAgt": { + "finInstnId": { + "bicfi": "USTBUS31XXX" + } + }, + "cdtr": { + "nm": "Mike Smith" + } + } + ] + }, + "appHdr": { + "fr": { + "fiId": { + "finInstnId": { + "bicfi": "ABCDUS33XXX" + } + } + }, + "to": { + "fiId": { + "finInstnId": { + "bicfi": "EFGHUS33XXX" + } + } + }, + "bizMsgIdr": "12312312312", + "msgDefIdr": "pacs.008.001.07", + "creDt": { + "dateTime": { + "date": { + "year": 2019, + "month": 10, + "day": 19 + }, + "time": { + "hour": 20, + "minute": 53, + "second": 13, + "nano": 0 + } + }, + "offset": { + "totalSeconds": 0 + } + }, + "pssblDplct": false, + "namespace": "urn:iso:std:iso:20022:tech:xsd:head.001.001.01" + }, + "type": "MX", + "@xmlns": "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.07", + "identifier": "pacs.008.001.07" +} diff --git a/integration-tests/swift/src/test/resources/mx/message2.xml b/integration-tests/swift/src/test/resources/mx/message2.xml new file mode 100644 index 000000000000..c2bba9db1138 --- /dev/null +++ b/integration-tests/swift/src/test/resources/mx/message2.xml @@ -0,0 +1,129 @@ + + + + + + + + ABCDUS33XXX + + + + + + + EFGHUS33XXX + + + + 12312312312 + pacs.008.001.07 + 2019-10-19T20:53:13Z + false + + + + + 823823423 + 2019-10-19T21:00:45Z + false + 1 + 10000 + 10000 + 2019-10-28 + + INDA + + + + CITTGB2LPBG + Lionel Messi + + 2342342342 + FOOISSUER + + + + + + ICBCUS4CXXX + Manu Ginobili + + PBOX + 1 + DFGH + My Street + 1122 + 10002 + Los Angeles + ABCD + + + + + + + 2233445566 + 987654321987654321 + 123456789 + SDSDS333 + + 5000 + 2019-07-31 + URGT + 2019-04-28T20:54:39Z + 2019-04-29 + 5000 + SHAR + + Jhon Doe + + HOME + ABCD + 1 + Foo Street + 1 + 1234 + Buenos Aires + CABA + AR + + AR + + + + ITUSUSP1XXX + Foo Corp + + + + + USTBUS31XXX + + + + Mike Smith + + + + + diff --git a/integration-tests/swift/src/test/resources/mx/message3.xml b/integration-tests/swift/src/test/resources/mx/message3.xml new file mode 100644 index 000000000000..e0caa4cf6992 --- /dev/null +++ b/integration-tests/swift/src/test/resources/mx/message3.xml @@ -0,0 +1,43 @@ + + + + + + swf00000-2020-07-28T15:11:11.123456Z + InterAct + Accepted + 2020-07-28T15:11:08Z + 2020-07-28T15:11:08Z + + cn=gtxdev,o=rtbsgb2l,o=swift + cn=gtxdev,o=rtbsgb2l,o=swift + swift.finplus!pc + seev.047.001.01 + Normal + FOO123456 + + + PlaceAndName + XtnsnEnvlp + + + + diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 51fb3ff3794b..24776b687241 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -2371,6 +2371,11 @@ camel-support ${camel.version} + + org.apache.camel + camel-swift + ${camel.version} + org.apache.camel camel-syslog @@ -5546,6 +5551,16 @@ camel-quarkus-support-xalan-deployment ${camel-quarkus.version} + + org.apache.camel.quarkus + camel-quarkus-swift + ${camel-quarkus.version} + + + org.apache.camel.quarkus + camel-quarkus-swift-deployment + ${camel-quarkus.version} + org.apache.camel.quarkus camel-quarkus-syslog diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index 39fd9be78973..5e667989fa55 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -2309,6 +2309,11 @@ camel-support 4.0.0-SNAPSHOT + + org.apache.camel + camel-swift + 4.0.0-SNAPSHOT + org.apache.camel camel-syslog @@ -5472,6 +5477,16 @@ camel-quarkus-support-xalan-deployment 3.0.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-swift + 3.0.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-swift-deployment + 3.0.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-syslog diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index 68f0f150ce7e..29e39bf10990 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -2309,6 +2309,11 @@ camel-support 4.0.0-SNAPSHOT + + org.apache.camel + camel-swift + 4.0.0-SNAPSHOT + org.apache.camel camel-syslog @@ -5472,6 +5477,16 @@ camel-quarkus-support-xalan-deployment 3.0.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-swift + 3.0.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-swift-deployment + 3.0.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-syslog diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index 38d5e5e5a989..2d0bf5c1f6cd 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -2309,6 +2309,11 @@ camel-support 4.0.0-SNAPSHOT + + org.apache.camel + camel-swift + 4.0.0-SNAPSHOT + org.apache.camel camel-syslog @@ -5472,6 +5477,16 @@ camel-quarkus-support-xalan-deployment 3.0.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-swift + 3.0.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-swift-deployment + 3.0.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-syslog diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 28f41a234df4..9e2501c65a0f 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -160,6 +160,7 @@ group-10: - main-unknown-args-ignore - platform-http-proxy - platform-http-proxy-ssl + - swift group-11: - compression-grouped - disruptor