Reputation: 995
I've implemented a Ballerina(ballerina 0.91) service to invoke https REST service which running on localhost. I used http:ClientConnector to call that service. This is my sample code.
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);
By the way here I interact with a business process in WSO2 EI.
The problem is when I call this service normally it didn't respond or gave an error like below.
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)
Upvotes: 0
Views: 226
Reputation: 995
I sort out my problem from adding the certificate of WSO2-EI into Ballerina client-truststore.jks file.
Upvotes: 2
Reputation: 1714
Here is a working sample for 0.95.0. I'm using postman basic auth endpoint:
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());
}
Upvotes: 3