-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from MadhukaHarith92/basic-client
Add basic soap client and test case
- Loading branch information
Showing
14 changed files
with
275 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.