Skip to content

Commit

Permalink
Format the code according to the coding conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Sep 15, 2023
1 parent 8ab5a6a commit 259f52d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions ballerina/soap.bal
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public isolated client class Client {
# + action - SOAP action as a `string`
# + headers - SOAP headers as a `map<string|string[]>`
# + return - If successful, returns the response. Else, returns an error
remote function sendReceive(xml|mime:Entity[] body, string? action = (), map<string|string[]> headers = {})returns xml|mime:Entity[]|Error {
remote function sendReceive(xml|mime:Entity[] body, string? action = (),
map<string|string[]> headers = {})returns xml|mime:Entity[]|Error {
return sendReceive(self.soapVersion, body, self.soapClient, action, headers);
}

Expand All @@ -75,7 +76,8 @@ public isolated client class Client {
# + action - SOAP action as a `string`
# + headers - SOAP headers as a `map<string|string[]>`
# + return - If successful, returns `nil`. Else, returns an error
remote function sendOnly(xml|mime:Entity[] body, string? action = (), map<string|string[]> headers = {}) returns Error? {
remote function sendOnly(xml|mime:Entity[] body, string? action = (),
map<string|string[]> headers = {}) returns Error? {
return sendOnly(self.soapVersion, body, self.soapClient, action, headers);
}
}
11 changes: 6 additions & 5 deletions ballerina/soap_utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import ballerina/mime;
# + soapVersion - The SOAP version of the request
# + headers - SOAP headers as a `map<string|string[]>`
# + return - The SOAP Request sent as `http:Request`
function createHttpRequest(SoapVersion soapVersion, xml|mime:Entity[] body, string? soapAction, map<string|string[]> headers = {})
returns http:Request {
function createHttpRequest(SoapVersion soapVersion, xml|mime:Entity[] body,
string? soapAction, map<string|string[]> headers = {}) returns http:Request {
http:Request req = new;
if body is xml {
req.setXmlPayload(body);
Expand Down Expand Up @@ -53,7 +53,6 @@ returns http:Request {
foreach string key in headers.keys() {
req.addHeader(key, headers[key].toBalString());
}

return req;
}

Expand All @@ -72,7 +71,8 @@ function createSoapResponse(http:Response response, SoapVersion soapVersion) ret

string path = "";

function sendReceive(SoapVersion soapVersion, xml|mime:Entity[] body, http:Client httpClient, string? soapAction = (), map<string|string[]> headers = {}) returns xml|Error {
function sendReceive(SoapVersion soapVersion, xml|mime:Entity[] body, http:Client httpClient,
string? soapAction = (), map<string|string[]> headers = {}) returns xml|Error {
http:Request req = createHttpRequest(soapVersion, body, soapAction, headers);
http:Response response;
do {
Expand All @@ -87,7 +87,8 @@ function sendReceive(SoapVersion soapVersion, xml|mime:Entity[] body, http:Clien
}
}

function sendOnly(SoapVersion soapVersion, xml|mime:Entity[] body, http:Client httpClient, string? soapAction = (), map<string|string[]> headers = {}) returns Error? {
function sendOnly(SoapVersion soapVersion, xml|mime:Entity[] body, http:Client httpClient,
string? soapAction = (), map<string|string[]> headers = {}) returns Error? {
http:Request req = createHttpRequest(SOAP11, body, soapAction, headers);
do {
http:Response _ = check httpClient->post(path, req);
Expand Down
6 changes: 4 additions & 2 deletions ballerina/tests/basic_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function testSendReceive11WithHeaders() returns error? {
</soap:Body>
</soap:Envelope>`;

xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add", {foo: ["bar1", "bar2"]});
xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add",
{foo: ["bar1", "bar2"]});

xml expected = xml `<soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><AddResponse xmlns="http://tempuri.org/"><AddResult>5</AddResult></AddResponse></soap:Body>`;
test:assertEquals(response, expected);
Expand All @@ -131,7 +132,8 @@ function testSendReceive12WithHeaders() returns error? {
</soap:Body>
</soap:Envelope>`;

xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add", {foo: ["bar1", "bar2"]});
xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add",
{foo: ["bar1", "bar2"]});

xml expected = xml `<soap:Body xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><AddResponse xmlns="http://tempuri.org/"><AddResult>5</AddResult></AddResponse></soap:Body>`;
test:assertEquals(response, expected);
Expand Down

0 comments on commit 259f52d

Please sign in to comment.