使用wso2/soap模块在ballerina中发送基本授权
我正在使用ballerina,我想连接WSO2 identity server进行身份验证 我无法使用wso2/soap添加基本授权 有人能举个例子吗使用wso2/soap模块在ballerina中发送基本授权,soap,wso2,ballerina,Soap,Wso2,Ballerina,我正在使用ballerina,我想连接WSO2 identity server进行身份验证 我无法使用wso2/soap添加基本授权 有人能举个例子吗 xml body = xml `<tes:insert_employee_operation xmlns:tes="http://teste.cv"> <tes:name>{{username}}</tes:name> <tes:age>10</tes:age>
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);
}
xml body=xml`
{{username}}
10
25
`;
soap:SoapRequest SoapRequest={
soapAction:“urn:insert\u employee\u操作”,
有效载荷:车身
};
io:println(soapRequest);
var details=soapClient->sendReceive(“/services/EmployeeService”,soapRequest);
比赛细节{
soap:SoapResponse SoapResponse=>{
io:println(soapResponse);
xml respostaXml=soapResponse.payload;
json respostaJson=respostaXml.toJSON({});
setJsonPayload(respostaJson);
_=呼叫方->响应(响应);
}
soap:SoapError SoapError=>io:println(SoapError);
}
在
soap:SoapRequst
对象中有更多字段可用。看
如果您的意思是ws-security,那么可以使用以下方法:
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"
}
}
};
这将把授权
头添加到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);
}
}
导入ballerina/http;
进口芭蕾舞演员/io;
输入芭蕾舞演员/原木;
进口wso2/soap;
端点soap:客户端soapClient{
客户端配置:{
url:“http://localhost:9000",
认证:{
方案:http:BASIC\u AUTH,
用户名:“是您的用户名”,
密码:“是您的密码”
}
}
};
公共函数main(字符串…参数){
xml body=xml`
{{username}}
10
25
`;
soap:SoapRequest SoapRequest={
soapAction:“urn:insert\u employee\u操作”,
有效载荷:车身
};
io:println(soapRequest);
var details=soapClient->sendReceive(“/services/EmployeeService”,soapRequest);
比赛细节{
soap:SoapResponse SoapResponse=>{
io:println(soapResponse);
xml respostaXml=soapResponse.payload;
json respostaJson=respostaXml.toJSON({});
setJsonPayload(respostaJson);
_=呼叫方->响应(响应);
}
soap:SoapError SoapError=>io:println(SoapError);
}
}