使用wso2/soap模块发送芭蕾舞演员的基本授权



我正在使用芭蕾舞演员,我想连接WSO2身份服务器进行身份验证。

我无法使用wso2/soap添加基本授权。

有人能举个例子吗?

xml body = xml `<tes:insert_employee_operation xmlns:tes="http://teste.cv">
<tes:name>{{username}}</tes:name>
<tes:age>10</tes:age>
<tes:ssn>25</tes:ssn>
</tes:insert_employee_operation>`;

soap:SoapRequest soapRequest = {
soapAction: "urn:insert_employee_operation",
payload: body
};
io:println(soapRequest);
var details = soapClient->sendReceive("/services/EmployeeService", soapRequest);
match details {
soap:SoapResponse soapResponse => {
io:println(soapResponse);
xml respostaXml = soapResponse.payload;
json respostaJson = respostaXml.toJSON({});
response.setJsonPayload(respostaJson);
_=caller->respond(response);
}
soap:SoapError soapError => io:println(soapError);
}

代码

soap:SoapRequst对象中还有更多可用字段。看见https://central.ballerina.io/wso2/soap#SoapRequest.

如果你的意思是ws安全,那么可以使用如下:

soap:SoapRequest soapRequest = {
soapAction: "urn:insert_employee_operation",
payload: body,
username: "foo",
password: "bar"
};

您还可以使用headers字段设置soap信封标头。

您可以在客户端端点配置下添加基本授权。

endpoint soap:Client soapClient {
clientConfig: {
url: "http://localhost:9000",
auth: {
scheme: http:BASIC_AUTH,
username: "is_username",
password: "is_password"
}
}
};

这将把Authorization头添加到HTTP请求中。完整的代码如下所示:

import ballerina/http;
import ballerina/io;
import ballerina/log;
import wso2/soap;
endpoint soap:Client soapClient {
clientConfig: {
url: "http://localhost:9000",
auth: {
scheme: http:BASIC_AUTH,
username: "is_username",
password: "is_password"
}
}
};
public function main(string... args) {
xml body = xml `<tes:insert_employee_operation xmlns:tes="http://teste.cv">
<tes:name>{{username}}</tes:name>
<tes:age>10</tes:age>
<tes:ssn>25</tes:ssn>
</tes:insert_employee_operation>`;

soap:SoapRequest soapRequest = {
soapAction: "urn:insert_employee_operation",
payload: body
};
io:println(soapRequest);
var details = soapClient->sendReceive("/services/EmployeeService", soapRequest);
match details {
soap:SoapResponse soapResponse => {
io:println(soapResponse);
xml respostaXml = soapResponse.payload;
json respostaJson = respostaXml.toJSON({});
response.setJsonPayload(respostaJson);
_ = caller->respond(response);
}
soap:SoapError soapError => io:println(soapError);
}
}

最新更新