Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply type inference in SOAP responses #112

Merged
merged 25 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
909a667
[Automated] Update the native jar versions
Nuvindu Oct 31, 2023
032b492
Fix returning mime:Entity[] responses
Nuvindu Oct 31, 2023
8fc4bb1
Fix identifying outbound configurations in SOAP responses
Nuvindu Nov 1, 2023
4ac220b
Fix sending SOAP 1.2 requests
Nuvindu Nov 1, 2023
9e8562d
Fix returning mime:Entity[] responses
Nuvindu Nov 1, 2023
e805bf1
Apply type inference to the SOAP responses
Nuvindu Nov 1, 2023
c99139f
Add test cases to validate type inference in responses
Nuvindu Nov 1, 2023
a9fdd66
Add resource functions to send mime:Entity[] payloads in mock services
Nuvindu Nov 1, 2023
4c9db80
Merge branch 'master' into type-inference
dilanSachi Nov 1, 2023
e547786
Fix test cases to get single type responses
Nuvindu Nov 1, 2023
9a88fbf
Add test cases to validate outbound security configs in mime:Entity[]…
Nuvindu Nov 1, 2023
246e8e5
Fix indenting according to coding conventions
Nuvindu Nov 1, 2023
47021d7
Merge branch 'type-inference' of https://github.com/Nuvindu/module-ba…
Nuvindu Nov 1, 2023
46fdf61
[Automated] Update the native jar versions
Nuvindu Nov 1, 2023
7a5e640
Apply changes to fix code coverage
Nuvindu Nov 1, 2023
8b7bb39
Fix applying encryption in SOAP 1.2 envelopes
Nuvindu Nov 1, 2023
35462c2
Merge branch 'master' of https://github.com/Nuvindu/module-ballerina-…
Nuvindu Nov 2, 2023
6f9026a
[Automated] Update the native jar versions
Nuvindu Nov 2, 2023
5ddaff4
[Automated] Update the native jar versions
Nuvindu Nov 2, 2023
7407153
[Automated] Update the native jar versions
Nuvindu Nov 2, 2023
74145ed
Apply suggestions from the review
Nuvindu Nov 2, 2023
81f0bf0
Update documentation to adhere new changes
Nuvindu Nov 2, 2023
cc94acb
Bump the package version to 0.9.0
Nuvindu Nov 2, 2023
c50a4a4
Apply suggestions from the review
Nuvindu Nov 3, 2023
14d1d13
Fix formatting in payloads
Nuvindu Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
}
```

Expand Down Expand Up @@ -172,7 +172,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
}
```

Expand Down Expand Up @@ -213,7 +213,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
}
```

Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "soap"
version = "0.8.1"
version = "0.9.0"
authors = ["Ballerina"]
export=["soap", "soap.soap11", "soap.soap12"]
keywords = ["soap"]
Expand All @@ -19,8 +19,8 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "soap-native"
version = "0.8.1"
path = "../native/build/libs/soap-native-0.8.1.jar"
version = "0.9.0"
path = "../native/build/libs/soap-native-0.9.0-SNAPSHOT.jar"

[[platform.java17.dependency]]
groupId = "org.apache.wss4j"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "soap"
version = "0.8.1"
version = "0.9.0"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "http"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
}
```

Expand Down Expand Up @@ -162,7 +162,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
}
```

Expand Down Expand Up @@ -202,7 +202,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
}
```

Expand Down
2 changes: 1 addition & 1 deletion ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
xml response = check soapClient->sendReceive(envelope, "http://tempuri.org/Add");
}
```

Expand Down
36 changes: 26 additions & 10 deletions ballerina/modules/soap11/soap11.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import ballerina/http;
import ballerina/mime;
import ballerina/jballerina.java;

# Object for the basic SOAP client endpoint.
# Object for the basic SOAP 1.1 client endpoint.
public isolated client class Client {
private final http:Client soapClient;
private final readonly & wssec:InboundSecurityConfig|wssec:InboundSecurityConfig[] inboundSecurity;
Expand All @@ -45,25 +46,35 @@

# Sends SOAP request and expects a response.
# ```ballerina
# xml|mime:Entity[] response = check soapClient->sendReceive(body, action);
# xml response = check soapClient->sendReceive(body, action);
# -- OR --
# mime:Entity[] response = check soapClient->sendReceive(body, action);
# ```
#
# + body - SOAP request body as an `XML` or `mime:Entity[]` to work with SOAP attachments
# + action - SOAP action as a `string`
# + headers - SOAP headers as a `map<string|string[]>`
# + path - The resource path
# + T - Default parameter use to infer the user specified type (`xml` or `mime:Entity[]`)
# + return - If successful, returns the response. Else, returns an error
remote isolated function sendReceive(xml|mime:Entity[] body, string action,
map<string|string[]> headers = {}, string path = "")
remote isolated function sendReceive(xml|mime:Entity[] body, string action, map<string|string[]> headers = {},
string path = "", typedesc<xml|mime:Entity[]> T = <>)
returns T|Error = @java:Method {
'class: "org.soap.Soap",
dilanSachi marked this conversation as resolved.
Show resolved Hide resolved
name: "sendReceive11"
} external;

isolated function generateResponse(xml|mime:Entity[] body, string action,
map<string|string[]> headers = {}, string path = "")

Check warning on line 68 in ballerina/modules/soap11/soap11.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/modules/soap11/soap11.bal#L68

Added line #L68 was not covered by tests
returns xml|mime:Entity[]|Error {
do {
xml securedBody;
xml mimeEntity = body is xml ? body : check body[0].getXml();
lock {
xml envelope = body is xml ? body.clone() : mimeEntity.clone();
securedBody = check soap:applySecurityPolicies(self.inboundSecurity.clone(), envelope.clone());
securedBody = check soap:applySecurityPolicies(self.inboundSecurity.clone(), envelope.clone(), false);
}
xml response;
xml|mime:Entity[] response;
if body is mime:Entity[] {
body[0].setXml(securedBody);
response = check soap:sendReceive(body, self.soapClient, action, headers, path, false);
Expand All @@ -73,13 +84,18 @@
lock {
wssec:OutboundSecurityConfig? outboundSecurity = self.outboundSecurity.clone();
do {
if outboundSecurity is wssec:OutboundSecurityConfig {
return check soap:applyOutboundConfig(outboundSecurity.clone(), response.clone());
if outboundSecurity is wssec:OutboundSecurityConfig && outboundSecurity != {} {
if response is xml {
return check soap:applyOutboundConfig(outboundSecurity.clone(), response.clone(), false);
dilanSachi marked this conversation as resolved.
Show resolved Hide resolved
} else {
return check soap:applyOutboundConfig(outboundSecurity.clone(),
check response[0].getXml().clone(), false);
}
}
} on fail var e {
return error Error(INVALID_OUTBOUND_SECURITY_ERROR, e.cause());
}
return response.clone();
return response;
}
} on fail var e {
return error Error(SOAP_ERROR, e.cause());
Expand All @@ -104,7 +120,7 @@
xml mimeEntity = body is xml ? body : check body[0].getXml();
lock {
xml envelope = body is xml ? body.clone() : mimeEntity.clone();
securedBody = check soap:applySecurityPolicies(self.inboundSecurity.clone(), envelope.clone());
securedBody = check soap:applySecurityPolicies(self.inboundSecurity.clone(), envelope.clone(), false);
}
return check soap:sendOnly(securedBody, self.soapClient, action, headers, path, false);
} on fail var e {
Expand Down
62 changes: 52 additions & 10 deletions ballerina/modules/soap11/tests/http_soap_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import ballerina/crypto;
import ballerina/http;
import ballerina/mime;
import ballerina/soap;

const crypto:KeyStore serverKeyStore = {
Expand All @@ -34,29 +35,70 @@ service / on new http:Listener(9090) {
return response;
}

resource function post getMimePayload(http:Request request) returns http:Response|error {
http:Response response = new;
mime:Entity[] mtomMessage = [];
mime:Entity envelope = new;
check envelope.setContentType("application/xop+xml");
envelope.setContentId("<soap@envelope>");
envelope.setBody(check (check request.getBodyParts())[0].getXml());
mtomMessage.push(envelope);
response.setBodyParts(mtomMessage);
response.setPayload(mtomMessage);
return response;
}

resource function post getSamePayload(http:Request request) returns http:Response|error {
xml payload = check request.getXmlPayload();
http:Response response = new;
response.setPayload(payload);
return response;
}

resource function post getSecuredMimePayload(http:Request request) returns http:Response|error {
xml payload = check (check request.getBodyParts())[0].getXml();
xml applyOutboundConfig = check soap:applyOutboundConfig(
{
verificationKey: clientPublicKey,
signatureAlgorithm: soap:RSA_SHA256,
decryptionAlgorithm: soap:RSA_ECB,
decryptionKey: serverPrivateKey
}, payload, false);
xml securedEnv = check soap:applySecurityPolicies(
{
signatureAlgorithm: soap:RSA_SHA256,
encryptionAlgorithm: soap:RSA_ECB,
signatureKey: serverPrivateKey,
encryptionKey: clientPublicKey
}, applyOutboundConfig, false);
http:Response response = new;
mime:Entity[] mtomMessage = [];
mime:Entity envelope = new;
check envelope.setContentType("application/xop+xml");
envelope.setContentId("<soap@envelope>");
envelope.setBody(securedEnv);
mtomMessage.push(envelope);
response.setBodyParts(mtomMessage);
response.setPayload(mtomMessage);
return response;
}

resource function post getSecuredPayload(http:Request request) returns http:Response|error {
xml payload = check request.getXmlPayload();
xml applyOutboundConfig = check soap:applyOutboundConfig(
{
verificationKey: clientPublicKey,
signatureAlgorithm: soap:RSA_SHA256,
decryptionAlgorithm: soap:RSA_ECB,
decryptionKey: serverPrivateKey
}, payload);
verificationKey: clientPublicKey,
signatureAlgorithm: soap:RSA_SHA256,
decryptionAlgorithm: soap:RSA_ECB,
decryptionKey: serverPrivateKey
}, payload, false);
Nuvindu marked this conversation as resolved.
Show resolved Hide resolved
xml securedEnv = check soap:applySecurityPolicies(
{
signatureAlgorithm: soap:RSA_SHA256,
encryptionAlgorithm: soap:RSA_ECB,
signatureKey: serverPrivateKey,
encryptionKey: clientPublicKey
}, applyOutboundConfig);
signatureAlgorithm: soap:RSA_SHA256,
encryptionAlgorithm: soap:RSA_ECB,
signatureKey: serverPrivateKey,
encryptionKey: clientPublicKey
}, applyOutboundConfig, false);
Nuvindu marked this conversation as resolved.
Show resolved Hide resolved
http:Response response = new;
response.setPayload(securedEnv);
return response;
Expand Down
Loading
Loading