Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the client provider on windows #2

Open
remioukrat opened this issue Jan 19, 2021 · 7 comments
Open

Problem with the client provider on windows #2

remioukrat opened this issue Jan 19, 2021 · 7 comments

Comments

@remioukrat
Copy link

When we run the service on windows.

If we try to do :

curl -X GET "https://localhost:8443/api/get" --insecure

we have always an internal server error 500.
It happens only on the endpoint where there is a redirection.

@lganzzzo
Copy link
Member

Hello @remioukrat ,

Please share your endpoint code and the full error message.

@remioukrat
Copy link
Author

It’s just the sample for the redirection:

	ENDPOINT_ASYNC("GET", "/api/get", TestApiGet)
	{

		ENDPOINT_ASYNC_INIT(TestApiGet)

		Action act() override {
			return controller->myClient->apiGetAsync().callbackTo(&TestApiGet::onResponse);
		}

		Action onResponse(const std::shared_ptr<IncomingResponse>&response) {
			return response->readBodyToStringAsync().callbackTo(&TestApiGet::returnResult);
		}

		Action returnResult(const oatpp::String & body) {
			return _return(controller->createResponse(Status::CODE_200, body));
		}

	};

and the error returned

$ curl -X GET "https://localhost:8443/api/get" --insecure
server=oatpp/1.2.0
code=500
description=Internal Server Error
message=[oatpp::network::tcp::client::ConnectionProvider::getConnectionAsync()]: Error. Can't connect.

@lganzzzo
Copy link
Member

Hey @remioukrat ,

From your code and from the error message - it's clear that the ApiClient is not able to connect to remote service.

Check that the client connection provider is set up correctly.

@remioukrat
Copy link
Author

Hi @lganzzzo

For the connection provider I have used the code available in the example :

  OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, sslClientConnectionProvider) ("clientConnectionProvider", [] {
    auto config = oatpp::libressl::Config::createShared();
    tls_config_insecure_noverifycert(config->getTLSConfig());
    tls_config_insecure_noverifyname(config->getTLSConfig());
    return oatpp::libressl::client::ConnectionProvider::createShared(config, {"httpbin.org", 443});
  }());
  
  OATPP_CREATE_COMPONENT(std::shared_ptr<MyApiClient>, myApiClient)([] {
    OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider, "clientConnectionProvider");
    OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper);
    auto requestExecutor = oatpp::web::client::HttpRequestExecutor::createShared(connectionProvider);
    return MyApiClient::createShared(requestExecutor, objectMapper);
  }());

And for the client it’s the same:

#ifndef MyApiClient_hpp
#define MyApiClient_hpp

#include "oatpp/web/client/ApiClient.hpp"
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"

#include OATPP_CODEGEN_BEGIN(ApiClient)

class MyApiClient : public oatpp::web::client::ApiClient {
  
  API_CLIENT_INIT(MyApiClient)
  
  API_CALL("GET", "/get", apiGet)
  
  API_CALL_ASYNC("GET", "/get", apiGetAsync)

};

#include OATPP_CODEGEN_END(ApiClient)

#endif /* MyApiClient_hpp */

@lganzzzo
Copy link
Member

@remioukrat ,

Ok, I see. It might be some kind of LibreSSL config that is missing on Windows.
Questions:

  • Are you trying to hit httpbin.org or are you using a different service in your code?
  • Have you tried this example on Linux/Mac, is it working for you?

Apart from that, I would recommend (it's not related to the issue):

@remioukrat
Copy link
Author

@lganzzzo ,

No, I have just tryed to hit httpbin.org. This example works in a linux docker but not on Windows.
For Windows I  use vcpkg packages. For the moment I use LibreSSL, but I have to test with OpenSSL too.

@lganzzzo
Copy link
Member

@remioukrat ,

That's sounds interesting. I can't check on windows at the moment.

I would suggest making sure that httpbin.org is accessible from within the widows VM, and that you are hitting the right port 443.
Also, it's possible that you have to additionally configure the TLS somehow on windows, by calling LibreSSL'stls_config_<...>.
Example:

tls_config_insecure_noverifycert(config->getTLSConfig());
tls_config_insecure_noverifyname(config->getTLSConfig());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants