Skip to content

Commit

Permalink
Merge pull request #82 from MadhukaHarith92/basic-client
Browse files Browse the repository at this point in the history
Add basic soap client and test case
  • Loading branch information
MadhukaHarith92 authored Aug 10, 2023
2 parents 4fd0564 + 71705fa commit 4d3edf9
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 659 deletions.
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "soap"
version = "0.1.0"
version = "0.2.0"
authors = ["Ballerina"]
keywords = ["soap"]
repository = "https://github.com/ballerina-platform/module-ballerina-soap"
Expand Down
95 changes: 34 additions & 61 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.5.0"
distribution-version = "2201.8.0-20230726-145300-b2bdf796"

[[package]]
org = "ballerina"
name = "auth"
version = "2.7.0"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "regex"}
{org = "ballerina", name = "log"}
]

[[package]]
org = "ballerina"
name = "cache"
version = "3.4.0"
version = "3.6.0"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -34,27 +33,24 @@ dependencies = [
[[package]]
org = "ballerina"
name = "constraint"
version = "1.1.0"
version = "1.3.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "crypto"
version = "2.3.1"
version = "2.4.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerina", packageName = "crypto", moduleName = "crypto"}
]

[[package]]
org = "ballerina"
name = "file"
version = "1.7.1"
version = "1.8.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -65,7 +61,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.7.0"
version = "2.9.1"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand All @@ -78,25 +74,26 @@ dependencies = [
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.decimal"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "lang.regexp"},
{org = "ballerina", name = "lang.runtime"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "oauth2"},
{org = "ballerina", name = "observe"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "time"},
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
org = "ballerina"
name = "io"
version = "1.4.1"
version = "1.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand All @@ -110,15 +107,14 @@ version = "0.0.0"
[[package]]
org = "ballerina"
name = "jwt"
version = "2.7.0"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "time"}
]

Expand Down Expand Up @@ -148,6 +144,15 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.int"
Expand Down Expand Up @@ -210,21 +215,18 @@ modules = [
[[package]]
org = "ballerina"
name = "log"
version = "2.7.1"
version = "2.8.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerina", packageName = "log", moduleName = "log"}
]

[[package]]
org = "ballerina"
name = "mime"
version = "2.7.1"
version = "2.8.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -237,7 +239,7 @@ modules = [
[[package]]
org = "ballerina"
name = "oauth2"
version = "2.7.0"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
Expand All @@ -250,42 +252,29 @@ dependencies = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.0.7"
version = "1.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "os"
version = "1.6.0"
version = "1.7.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "regex"
version = "1.4.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.string"}
]

[[package]]
org = "ballerina"
name = "soap"
version = "0.1.0"
version = "0.2.0"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.xml"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
{org = "ballerina", name = "uuid"}
{org = "ballerina", name = "test"}
]
modules = [
{org = "ballerina", packageName = "soap", moduleName = "soap"}
Expand All @@ -294,7 +283,7 @@ modules = [
[[package]]
org = "ballerina"
name = "task"
version = "2.3.2"
version = "2.4.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -306,7 +295,8 @@ name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
Expand All @@ -315,33 +305,16 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.2.5"
version = "2.3.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "time", moduleName = "time"}
]

[[package]]
org = "ballerina"
name = "url"
version = "2.2.4"
version = "2.3.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "uuid"
version = "1.5.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerina", packageName = "uuid", moduleName = "uuid"}
]

18 changes: 18 additions & 0 deletions ballerina/error.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) 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.

# Defines the common error type for the module.
public type Error distinct error;
77 changes: 77 additions & 0 deletions ballerina/soap.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) 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.

import ballerina/http;
import ballerina/mime;

# Defines the supported SOAP versions.
public enum SoapVersion {
# Represents SOAP 1.1 version
SOAP11,
# Represents SOAP 1.2 version
SOAP12
}

# Soap client configurations.
#
# + soapVersion - SOAP version
public type ClientConfiguration record {|
*http:ClientConfiguration;
SoapVersion soapVersion = SOAP11;
|};

# Object for the basic SOAP client endpoint.
public isolated client class Client {
private final http:Client soapClient;
private final SoapVersion soapVersion;

# Gets invoked during object initialization.
#
# + url - URL endpoint
# + config - Configurations for SOAP client
# + return - `error` in case of errors or `()` otherwise
public function init(string url, *ClientConfiguration config) returns Error? {
self.soapVersion = config.soapVersion;
do {
self.soapClient = check new (url,retrieveHttpClientConfig(config));
} on fail var err {
return error Error("Failed to initialize soap client", err);
}
}

# Sends SOAP request and expects a response.
# ```ballerina
# xml|mime:Entity[] response = check soapClient->sendReceive(body);
# ```
#
# + body - SOAP request body as an `XML` or `mime:Entity[]` to work with SOAP attachments
# + return - If successful, returns the response. Else, returns an error
remote function sendReceive(xml|mime:Entity[] body) returns xml|mime:Entity[]|Error {
return sendReceive(self.soapVersion, body, self.soapClient);
}

# Fires and forgets requests. Sends the request without the possibility of any response from the
# service (even an error).
# ```ballerina
# check soapClient->sendOnly(body);
# ```
#
# + body - SOAP request body as an `XML` or `mime:Entity[]` to work with SOAP attachments
# + return - If successful, returns `nil`. Else, returns an error
remote function sendOnly(xml|mime:Entity[] body) returns Error? {
return sendOnly(self.soapVersion, body, self.soapClient);
}
}
Loading

0 comments on commit 4d3edf9

Please sign in to comment.