Skip to content

Commit

Permalink
Add resource functions to send mime:Entity[] payloads in mock services
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Nov 1, 2023
1 parent c99139f commit a9fdd66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
34 changes: 24 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,6 +35,19 @@ 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;
Expand All @@ -45,18 +59,18 @@ service / on new http:Listener(9090) {
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);
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);
http:Response response = new;
response.setPayload(securedEnv);
return response;
Expand Down
34 changes: 24 additions & 10 deletions ballerina/modules/soap12/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,6 +35,19 @@ 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;
Expand All @@ -45,18 +59,18 @@ service / on new http:Listener(9090) {
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);
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);
http:Response response = new;
response.setPayload(securedEnv);
return response;
Expand Down

0 comments on commit a9fdd66

Please sign in to comment.