Skip to content

Commit

Permalink
Add basic soap client and test case
Browse files Browse the repository at this point in the history
  • Loading branch information
MadhukaHarith92 committed Jul 28, 2023
1 parent 4fd0564 commit 276bd63
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 221 deletions.
53 changes: 53 additions & 0 deletions ballerina/soap.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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;

# Object for the basic SOAP client endpoint.
public client class BasicClient {

http:Client soapClient;
SoapVersion version = SOAP11;

public function init(string url, http:ClientConfiguration? config = (), SoapVersion? version = ()) returns error? {
if config is http:ClientConfiguration {
self.soapClient = check new (url, config);
} else {
self.soapClient = check new (url);
}
if version is SoapVersion {
self.version = version;
}
}

# Sends SOAP request and expects a response.
#
# + soap - 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[] soap) returns xml|mime:Entity[]|error {
return sendReceive(self.version, soap, self.soapClient);
}

# Fire and forget requests. Sends the request without the possibility of any response from the
# service (even an error).
#
# + soap - 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[] soap) returns error? {
var _ = check sendOnly(self.version, soap, self.soapClient);
}
}
65 changes: 0 additions & 65 deletions ballerina/soap11_endpoint.bal

This file was deleted.

67 changes: 0 additions & 67 deletions ballerina/soap12_endpoint.bal

This file was deleted.

15 changes: 4 additions & 11 deletions ballerina/soap_utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ returns http:Request {
# + response - The request to be sent
# + soapVersion - The SOAP version of the request
# + return - The SOAP response created from the `http:Response` or the `error` object when reading the payload
function createSOAPResponse(http:Response response, SoapVersion soapVersion) returns @tainted SoapResponse | error {
function createSOAPResponse(http:Response response, SoapVersion soapVersion) returns xml | error {
xml payload = check response.getXmlPayload();
xmlns "http://schemas.xmlsoap.org/soap/envelope/" as soap11;
xmlns "http://www.w3.org/2003/05/soap-envelope" as soap12;
Expand All @@ -315,13 +315,7 @@ function createSOAPResponse(http:Response response, SoapVersion soapVersion) ret
} else {
soapResponsePayload = payload/<soap12:Body>;
}
SoapResponse soapResponse = {
headers: soapResponseHeaders,
payload: soapResponsePayload,
soapVersion: soapVersion,
httpResponse: response
};
return soapResponse;
return soapResponsePayload;
}

# Creates the password used in password digest usernameToken WS-Security.
Expand All @@ -339,9 +333,8 @@ function createDigestPassword(string nonce, string password, string createdTime)

string path = "";

function sendReceive(SoapVersion soapVersion, xml|mime:Entity[] body, http:Client httpClient, string? soapAction = (),
Options? options = ()) returns @tainted SoapResponse|error {
http:Request req = fillSOAPEnvelope(soapVersion, body, options = options, soapAction = soapAction);
function sendReceive(SoapVersion soapVersion, xml|mime:Entity[] body, http:Client httpClient, string? soapAction = ()) returns xml|error {
http:Request req = fillSOAPEnvelope(soapVersion, body, soapAction = soapAction);
http:Response response = check httpClient->post(path, req);
return createSOAPResponse(response, soapVersion);
}
Expand Down
39 changes: 0 additions & 39 deletions ballerina/tests/testSoap11.bal

This file was deleted.

39 changes: 0 additions & 39 deletions ballerina/tests/testSoap12.bal

This file was deleted.

0 comments on commit 276bd63

Please sign in to comment.