diff --git a/README.md b/README.md index 7cd54ae..f4bf0b8 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ This repository contains only the source code of the package. ### Set up the prerequisites -1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). +1. Download and install Java SE Development Kit (JDK) version 21 (from one of the following locations). - [Oracle](https://www.oracle.com/java/technologies/downloads/) - [OpenJDK](https://adoptium.net/) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index ddc699f..5e13cb0 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,40 +1,40 @@ [package] org = "ballerina" name = "soap" -version = "2.0.1" +version = "2.1.0" authors = ["Ballerina"] export=["soap", "soap.soap11", "soap.soap12"] keywords = ["soap"] repository = "https://github.com/ballerina-platform/module-ballerina-soap" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.10.0" +distribution = "2201.11.0-20241112-214900-6b80ab87" [build-options] observabilityIncluded = true -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "soap-native" -version = "2.0.1" -path = "../native/build/libs/soap-native-2.0.1-SNAPSHOT.jar" +version = "2.1.0" +path = "../native/build/libs/soap-native-2.1.0-SNAPSHOT.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "org.apache.wss4j" artifactId = "wss4j-ws-security-dom" version = "3.0.1" path = "./lib/wss4j-ws-security-dom-3.0.1.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "org.apache.wss4j" artifactId = "wss4j-ws-security-common" version = "3.0.1" path = "./lib/wss4j-ws-security-common-3.0.1.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "org.apache.santuario" artifactId = "xmlsec" version = "3.0.3" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 86e4ff5..09db1b2 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0" +distribution-version = "2201.11.0-20241112-214900-6b80ab87" [[package]] org = "ballerina" name = "auth" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -22,7 +22,7 @@ dependencies = [ [[package]] org = "ballerina" name = "cache" -version = "3.8.0" +version = "3.8.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, @@ -33,7 +33,7 @@ dependencies = [ [[package]] org = "ballerina" name = "constraint" -version = "1.5.0" +version = "1.6.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -41,7 +41,7 @@ dependencies = [ [[package]] org = "ballerina" name = "crypto" -version = "2.7.2" +version = "2.7.3" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -50,10 +50,19 @@ modules = [ {org = "ballerina", packageName = "crypto", moduleName = "crypto"} ] +[[package]] +org = "ballerina" +name = "data.jsondata" +version = "0.3.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + [[package]] org = "ballerina" name = "file" -version = "1.10.0" +version = "1.10.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -64,12 +73,13 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.3" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "data.jsondata"}, {org = "ballerina", name = "file"}, {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -96,7 +106,7 @@ modules = [ [[package]] org = "ballerina" name = "io" -version = "1.6.1" +version = "1.6.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} @@ -116,7 +126,7 @@ modules = [ [[package]] org = "ballerina" name = "jwt" -version = "2.13.0" +version = "2.13.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -216,7 +226,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.10.0" +version = "2.10.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -227,7 +237,7 @@ dependencies = [ [[package]] org = "ballerina" name = "mime" -version = "2.10.1" +version = "2.10.2" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -241,7 +251,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -254,7 +264,7 @@ dependencies = [ [[package]] org = "ballerina" name = "observe" -version = "1.3.0" +version = "1.4.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -262,7 +272,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.8.0" +version = "1.8.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} @@ -271,7 +281,7 @@ dependencies = [ [[package]] org = "ballerina" name = "soap" -version = "2.0.1" +version = "2.1.0" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "http"}, @@ -292,7 +302,7 @@ modules = [ [[package]] org = "ballerina" name = "task" -version = "2.5.0" +version = "2.5.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -314,7 +324,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.0" +version = "2.6.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -322,7 +332,7 @@ dependencies = [ [[package]] org = "ballerina" name = "url" -version = "2.4.0" +version = "2.4.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] diff --git a/ballerina/Package.md b/ballerina/Package.md deleted file mode 100644 index 4e44074..0000000 --- a/ballerina/Package.md +++ /dev/null @@ -1,222 +0,0 @@ -# Package overview - -This module offers a set of APIs that facilitate the transmission of XML requests to a SOAP backend. It excels in managing security policies within SOAP requests, ensuring the transmission of secured SOAP envelopes. Moreover, it possesses the capability to efficiently extract data from security-applied SOAP responses. - -SOAP module abstracts out the details of the creation of a SOAP envelope, headers, and the body in a SOAP message. - -## Client - -The `Client` is used to connect to and interact with `SOAP` endpoints. - -### SOAP 1.1 Client - -```ballerina -import ballerina/soap.soap11; - -soap11:Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL"); -``` - -### SOAP 1.2 Client - -```ballerina -import ballerina/soap.soap12; - -soap12:Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL"); -``` - -## APIs associated with SOAP - -- **Send & Receive**: Sends SOAP request and receives a response. -- **Send Only**: Fires and forgets requests. Sends the request without the possibility of any response from the service. - -The SOAP 1.1 specification requires the inclusion of the `action` parameter as a mandatory component within its APIs. In contrast, SOAP 1.2 relaxes this requirement, making the action parameter optional. - -### Example: Send & Receive - -```ballerina -import ballerina/soap.soap11; - -public function main() returns error? { - soap11:Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL"); - - xml envelope = xml ` - - - 2 - 3 - - - `; - xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add"); -} -``` - -### Example: Send Only - -```ballerina -import ballerina/soap.soap11; - -public function main() returns error? { - soap11:Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL"); - - xml envelope = xml ` - - - 2 - 3 - - - `; - check soapClient->sendOnly(envelope, "http://tempuri.org/Add"); -} -``` - -## Security - -The SOAP client module introduces a robust framework for configuring security measures in SOAP communication. Security is a critical concern when exchanging data via web services, and this module offers comprehensive options to fortify SOAP requests and responses. - -There are two primary security configurations available for SOAP clients: - -- `outboundSecurity`: This configuration applies WS-Security policies to outgoing SOAP messages. It supports multiple security options, such as Username Token, Timestamp Token, X.509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding. These can be used individually or in combination to secure the message. - -- `inboundSecurity`: This configuration handles the security of incoming SOAP messages. It decrypts encrypted data and verifies the digital signature to confirm the authenticity of the message. - -### Policies - -This library currently supports the following WS Security policies: - -- **Username Token**: Provides authentication through username and password credentials. -- **Timestamp Token**: Enhances message integrity by incorporating timestamp information. -- **X509 Token**: Allows the use of X.509 certificates for secure communication. -- **Symmetric Binding**: Enables symmetric key-based security mechanisms. -- **Asymmetric Binding**: Facilitates the use of asymmetric cryptography for enhanced security. - -These policies empower SOAP clients to enhance the security of their web service communications by selecting and implementing the appropriate security mechanisms to safeguard their SOAP envelopes. - -### Security Policy Configuration Types - -#### Outbound Security Configurations - -- `TimestampTokenConfig`: Represents the record for Timestamp Token policy. - - Fields: - - `int` timeToLive : The time to get expired - -- `UsernameTokenConfig`: Represents the record for Username Token policy. - - Fields: - - `string` username : The name of the user - - `string` password : The password of the user - - `PasswordType` passwordType : The password type of the username token - -- `SymmetricBindingConfig`: Represents the record for Symmetric Binding policy. - - Fields: - - `crypto:PrivateKey` symmetricKey : The key to sign and encrypt the SOAP envelope - - `crypto:PublicKey` servicePublicKey : The key to encrypt the symmetric key - - `SignatureAlgorithm` signatureAlgorithm : The algorithm to sign the SOAP envelope - - `EncryptionAlgorithm` encryptionAlgorithm : The algorithm to encrypt the SOAP envelope - - `string` x509Token : The path or token of the X509 certificate - -- `AsymmetricBindingConfig`: Represents the record for Asymmetric Binding policy. - - Fields: - - `SignatureConfig` signatureConfig : Configuration for applying digital signatures - - `EncryptionConfig` encryptionConfig : Configuration for applying encryption - - `string` x509Token : The path or token of the X509 certificate - -#### Inbound Security Configurations - -- `InboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes. - - Fields: - - `crypto:KeyStore` decryptKeystore - The keystore to decrypt the SOAP envelope - - `crypto:KeyStore` signatureKeystore - The keystore to verify the signature of the SOAP envelope - -### Apply Security Policies - -#### SOAP 1.1 Client: UsernameToken and TranportBinding Policy - -```ballerina -import ballerina/crypto; -import ballerina/mime; -import ballerina/soap; -import ballerina/soap.soap11; - -public function main() returns error? { - soap11:Client soapClient = check new ("https://www.secured-soap-endpoint.com", - { - outboundSecurity: [ - { - username: "username", - password: "password", - passwordType: soap:TEXT - }, - TRANSPORT_BINDING - ] - }); - - xml envelope = xml ` - - - 2 - 3 - - - `; - xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add"); -} -``` - -#### SOAP 1.2 Client with Asymmetric Binding and Outbound Security Configuration - -```ballerina -import ballerina/crypto; -import ballerina/mime; -import ballerina/soap; -import ballerina/soap.soap12; - -public function main() returns error? { - configurable crypto:PrivateKey clientPrivateKey = ?; - configurable crypto:PublicKey clientPublicKey = ?; - configurable ​crypto:PublicKey serverPublicKey = ?; - - soap12:Client soapClient = check new ("https://www.secured-soap-endpoint.com", - { - outboundSecurity: { - signatureConfig: { - keystore: { - path: KEY_STORE_PATH, - password: PASSWORD - }, - privateKeyAlias: ALIAS, - privateKeyPassword: PASSWORD, - canonicalizationAlgorithm: wssec:C14N_EXCL_OMIT_COMMENTS, - digestAlgorithm: wssec:SHA1 - }, - encryptionConfig: { - keystore: { - path: KEY_STORE_PATH_2, - password: PASSWORD - }, - publicKeyAlias: ALIAS, - encryptionAlgorithm: wssec:AES_128 - } - }, - inboundSecurity: { - decryptKeystore: { - path: KEY_STORE_PATH_2, - password: PASSWORD - }, - signatureKeystore: { - path: KEY_STORE_PATH, - password: PASSWORD - } - } - }); - xml envelope = xml ` - - - 2 - 3 - - - `; - xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add"); -} -``` diff --git a/ballerina/Module.md b/ballerina/README.md similarity index 100% rename from ballerina/Module.md rename to ballerina/README.md diff --git a/ballerina/modules/soap11/Module.md b/ballerina/modules/soap11/README.md similarity index 100% rename from ballerina/modules/soap11/Module.md rename to ballerina/modules/soap11/README.md diff --git a/ballerina/modules/soap11/tests/soap11_client_test.bal b/ballerina/modules/soap11/tests/soap11_client_test.bal index 705ab6c..ff74ebd 100644 --- a/ballerina/modules/soap11/tests/soap11_client_test.bal +++ b/ballerina/modules/soap11/tests/soap11_client_test.bal @@ -25,7 +25,7 @@ import ballerina/test; const string KEY_ALIAS = "wss40"; const string KEY_PASSWORD = "security"; const IMAGE_PATH = "../ballerina/icon.png"; -const FILE_PATH = "../ballerina/Module.md"; +const FILE_PATH = "../ballerina/README.md"; const string KEY_STORE_PATH = "modules/wssec/tests/resources/wss40.p12"; const string X509_KEY_STORE_PATH = "modules/wssec/tests/resources/x509_certificate.p12"; const string X509_KEY_STORE_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.p12"; diff --git a/ballerina/modules/soap12/Module.md b/ballerina/modules/soap12/README.md similarity index 100% rename from ballerina/modules/soap12/Module.md rename to ballerina/modules/soap12/README.md diff --git a/ballerina/modules/soap12/tests/soap12_client_test.bal b/ballerina/modules/soap12/tests/soap12_client_test.bal index 2c8dbe6..b705d07 100644 --- a/ballerina/modules/soap12/tests/soap12_client_test.bal +++ b/ballerina/modules/soap12/tests/soap12_client_test.bal @@ -25,7 +25,7 @@ import ballerina/test; const KEY_ALIAS = "wss40"; const KEY_PASSWORD = "security"; const IMAGE_PATH = "../ballerina/icon.png"; -const FILE_PATH = "../ballerina/Module.md"; +const FILE_PATH = "../ballerina/README.md"; const KEY_STORE_PATH = "modules/wssec/tests/resources/wss40.p12"; const X509_KEY_STORE_PATH = "modules/wssec/tests/resources/x509_certificate.p12"; const X509_KEY_STORE_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.p12"; diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index b55c963..174eae7 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -8,33 +8,33 @@ keywords = ["soap"] repository = "https://github.com/ballerina-platform/module-ballerina-soap" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.10.0" +distribution = "2201.11.0-20241112-214900-6b80ab87" [build-options] observabilityIncluded = true -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "soap-native" version = "@toml.version@" path = "../native/build/libs/soap-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "org.apache.wss4j" artifactId = "wss4j-ws-security-dom" version = "@wssecuritydom.version@" path = "./lib/wss4j-ws-security-dom-@wssecuritydom.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "org.apache.wss4j" artifactId = "wss4j-ws-security-common" version = "@wssecuritycommon.version@" path = "./lib/wss4j-ws-security-common-@wssecuritycommon.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "org.apache.santuario" artifactId = "xmlsec" version = "@xmlsec.version@" diff --git a/build.gradle b/build.gradle index 5d2e722..ddb8e0d 100644 --- a/build.gradle +++ b/build.gradle @@ -91,6 +91,7 @@ subprojects { ballerinaStdLibs "io.ballerina.stdlib:os-ballerina:${project.stdlibOsVersion}" ballerinaStdLibs "io.ballerina.stdlib:url-ballerina:${project.stdlibUrlVersion}" ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${project.stdlibIoVersion}" + ballerinaStdLibs "io.ballerina.lib:data.jsondata-ballerina:${stdlibDataJsonDataVersion}" externalJars (group: 'org.apache.wss4j', name: 'wss4j-ws-security-dom', version: "${wsSecurityDomVersion}") { transitive = false diff --git a/gradle.properties b/gradle.properties index eed1b8b..1962954 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,37 +1,38 @@ org.gradle.caching=true group=io.ballerina.stdlib -version=2.0.1-SNAPSHOT +version=2.1.0-SNAPSHOT checkstylePluginVersion=10.12.0 -spotbugsPluginVersion=5.0.14 +spotbugsPluginVersion=6.0.18 shadowJarPluginVersion=8.1.1 downloadPluginVersion=5.4.0 releasePluginVersion=2.8.0 ballerinaGradlePluginVersion=2.2.4 -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 -stdlibIoVersion=1.6.1 -stdlibTimeVersion=2.4.0 -stdlibUrlVersion=2.4.0 +stdlibIoVersion=1.6.2-20241112-233100-995cf5f +stdlibTimeVersion=2.6.0-20241113-073800-201b904 +stdlibUrlVersion=2.4.1-20241113-073900-335ff51 -stdlibConstraintVersion=1.5.0 -stdlibCryptoVersion=2.7.2 -stdlibLogVersion=2.10.0 -stdlibOsVersion=1.8.0 -stdlibRandomVersion=1.5.0 -stdlibTaskVersion=2.5.0 +stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5 +stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 +stdlibLogVersion=2.10.1-20241113-120000-4577868 +stdlibOsVersion=1.8.1-20241113-122000-cca973b +stdlibRandomVersion=1.5.1-20241113-122300-1bc770e +stdlibTaskVersion=2.5.1-20241113-123500-f905281 -stdlibCacheVersion=3.8.0 -stdlibFileVersion=1.10.0 -stdlibMimeVersion=2.10.0 -stdlibUuidVersion=1.8.0 +stdlibCacheVersion=3.8.1-20241113-125700-b75a1bf +stdlibFileVersion=1.10.1-20241113-151700-e1a2e38 +stdlibMimeVersion=2.10.2-20241113-154200-d953747 +stdlibUuidVersion=1.8.1-20241113-154400-443c67b -stdlibAuthVersion=2.12.0 -stdlibJwtVersion=2.13.0 -stdlibOAuth2Version=2.12.0 +stdlibAuthVersion=2.12.1-20241113-162300-ded40eb +stdlibDataJsonDataVersion=0.3.0-20241113-163100-6d332e1 +stdlibJwtVersion=2.13.1-20241113-162400-b59ccfa +stdlibOAuth2Version=2.12.1-20241113-162400-4c6ddfe -stdlibHttpVersion=2.12.0 +stdlibHttpVersion=2.13.0-20241114-182900-7e9f66a wsSecurityDomVersion=3.0.1 wsSecurityCommonVersion=3.0.1 @@ -39,5 +40,5 @@ xmlSecVersion=3.0.3 guavaVersion=32.1.1-jre # Ballerinax Observer -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +observeVersion=1.4.0-20241113-092000-b83ae74 +observeInternalVersion=1.3.1-20241113-101700-265054d diff --git a/native/build.gradle b/native/build.gradle index 59e48b9..cccfcf3 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -44,8 +44,11 @@ checkstyle { checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsMain { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/native/src/main/java/io/ballerina/lib/soap/ExecutionCallback.java b/native/src/main/java/io/ballerina/lib/soap/ExecutionCallback.java deleted file mode 100644 index 4f17f34..0000000 --- a/native/src/main/java/io/ballerina/lib/soap/ExecutionCallback.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. -// -// WSO2 LLC. 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 io.ballerina.lib.soap; - -import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.values.BError; - -/** - * Callback class for executing Ballerina dependently type methods. - */ -public class ExecutionCallback implements Callback { - private final Future future; - - ExecutionCallback(Future future) { - this.future = future; - } - @Override - public void notifySuccess(Object o) { - this.future.complete(o); - } - - @Override - public void notifyFailure(BError bError) { - bError.printStackTrace(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 - System.exit(1); - } -} diff --git a/native/src/main/java/io/ballerina/lib/soap/Soap.java b/native/src/main/java/io/ballerina/lib/soap/Soap.java index eb76da0..fd3ba02 100644 --- a/native/src/main/java/io/ballerina/lib/soap/Soap.java +++ b/native/src/main/java/io/ballerina/lib/soap/Soap.java @@ -17,47 +17,44 @@ package io.ballerina.lib.soap; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.async.StrandMetadata; -import io.ballerina.runtime.api.creators.TypeCreator; -import io.ballerina.runtime.api.types.UnionType; +import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import static org.wssec.ModuleUtils.getModule; - public class Soap { private static final String REMOTE_FUNCTION = "generateResponse"; - public static final StrandMetadata REMOTE_EXECUTION_STRAND = new StrandMetadata( - getModule().getOrg(), - getModule().getName(), - getModule().getMajorVersion(), - REMOTE_FUNCTION); public static Object sendReceive11(Environment env, BObject soap11, Object body, BString action, BMap headers, BString path, BTypedesc typeDesc) { - Future future = env.markAsync(); - ExecutionCallback executionCallback = new ExecutionCallback(future); - UnionType typeUnion = TypeCreator.createUnionType(PredefinedTypes.TYPE_XML, PredefinedTypes.TYPE_ANYDATA_ARRAY, - PredefinedTypes.TYPE_ERROR); - Object[] arguments = new Object[]{body, true, action, true, headers, true, path, true}; - env.getRuntime().invokeMethodAsyncConcurrently(soap11, REMOTE_FUNCTION, null, REMOTE_EXECUTION_STRAND, - executionCallback, null, typeUnion, arguments); - return null; + return env.yieldAndRun(() -> { + try { + Object[] arguments = new Object[]{body, action, headers, path}; + Object result = env.getRuntime().callMethod(soap11, REMOTE_FUNCTION, null, arguments); + if (result instanceof BError) { + ((BError) result).printStackTrace(); + } + return result; + } catch (BError bError) { + bError.printStackTrace(); + System.exit(1); + } + return null; + }); } public static Object sendReceive12(Environment env, BObject soap12, Object body, Object action, BMap headers, BString path, BTypedesc typeDesc) { - Future future = env.markAsync(); - ExecutionCallback executionCallback = new ExecutionCallback(future); - UnionType typeUnion = TypeCreator.createUnionType(PredefinedTypes.TYPE_XML, PredefinedTypes.TYPE_ANYDATA_ARRAY, - PredefinedTypes.TYPE_ERROR); - Object[] arguments = new Object[]{body, true, action, true, headers, true, path, true}; - env.getRuntime().invokeMethodAsyncConcurrently(soap12, REMOTE_FUNCTION, null, REMOTE_EXECUTION_STRAND, - executionCallback, null, typeUnion, arguments); - return null; + return env.yieldAndRun(() -> { + try { + Object[] arguments = new Object[]{body, action, headers, path}; + return env.getRuntime().callMethod(soap12, REMOTE_FUNCTION, null, arguments); + } catch (BError bError) { + bError.printStackTrace(); + System.exit(1); + } + return null; + }); } } diff --git a/native/src/main/java/org/wssec/DocumentBuilder.java b/native/src/main/java/org/wssec/DocumentBuilder.java index 6ef986b..35a41d7 100644 --- a/native/src/main/java/org/wssec/DocumentBuilder.java +++ b/native/src/main/java/org/wssec/DocumentBuilder.java @@ -31,13 +31,14 @@ import static org.wssec.Utils.createError; import static org.wssec.WsSecurityUtils.convertDocumentToString; -public class DocumentBuilder { +public final class DocumentBuilder { private final Document document; public DocumentBuilder(BObject documentBuilder, BXml xmlPayload) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); - this.document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xmlPayload.toString()))); + this.document = factory.newDocumentBuilder().parse(new InputSource( + new StringReader(xmlPayload.toString()))); documentBuilder.addNativeData(NATIVE_DOCUMENT, this.document); } diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index e22fda1..3af7dd8 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -17,7 +17,7 @@ --> - +