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

时间:2018-11-16 13:26:27

标签: soap wso2 ballerina

我正在使用芭蕾舞女演员,我想与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);
}

code

2 个答案:

答案 0 :(得分:2)

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

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);
    }
}

答案 1 :(得分:1)

soap:SoapRequst对象中还有更多字段可用。参见to_datetime

如果您的意思是ws-security,则可以使用以下方法:

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

您还可以使用标题字段设置肥皂信封标题。