无法在Ballerinalang中调用localhost https REST服务并发出超时错误?

时间:2017-11-03 18:28:40

标签: wso2ei ballerina

我已经实施了Ballerina(芭蕾舞女演员0.91)服务来调用在localhost上运行的https REST服务。我使用http:ClientConnector来调用该服务。这是我的示例代码。

http:ClientConnector clientConnector = create http:ClientConnector("https://localhost:9445/");
string token = "admin:admin";
string auth = utils:base64encode(token);
message request = {};
messages:setHeader(request,"Basic ",auth);
message response = clientConnector.get("bpmn/runtime/process-instances/",request);

顺便说一下,我在WSO2 EI中与业务流程进行交互。

问题是,当我正常拨打此服务时,它没有回复或发出如下错误。

error: ballerina.lang.errors:Error, message: failed to invoke 'get' action in ClientConnector. response was not received within sender timeout of 180 seconds
    at ballerina.net.http:ClientConnector.get(<native>:0)
    at org.wso2.ballerina.connectors.basicauth:ClientConnector.get(org/wso2/ballerina/connectors/basicauth/ClientConnector.bal:28)
    at .:main(MainFile.bal:21)

2 个答案:

答案 0 :(得分:2)

这是0.95.0的工作样本。我使用postman基本auth端点:

import ballerina.net.http;
function main(string[] args) {
   endpoint<http:HttpClient> httpConnector{
       create http:HttpClient("https://postman-echo.com",{});
   }
http:Request req = {};
http:Response resp = {};
req.addHeader("Authorization", "Basic cG9zdG1hbjpwYXNzd29yZA==");
resp,_ = httpConnector.get("/basic-auth",req);
println("Auth request:");
println(resp.getJsonPayload());
}

答案 1 :(得分:2)

我通过将WSO2-EI证书添加到Ballerina client-truststore.jks文件中解决了我的问题。