diff --git a/smacc2_client_library/http_client/CMakeLists.txt b/smacc2_client_library/http_client/CMakeLists.txt index 31b7fb596..7859afaa2 100644 --- a/smacc2_client_library/http_client/CMakeLists.txt +++ b/smacc2_client_library/http_client/CMakeLists.txt @@ -21,14 +21,22 @@ include_directories( file(GLOB_RECURSE SRC_FILES src *.cpp) +add_library(http_session + src/http_client/ssl_http_session.cpp + src/http_client/http_session.cpp +) + add_library(${PROJECT_NAME} - ${SRC_FILES} + src/http_client/http_client.cpp ) -target_link_libraries(${PROJECT_NAME} ${smacc2_LIBRARIES}) -ament_target_dependencies(${PROJECT_NAME} smacc2) +target_link_libraries(${PROJECT_NAME} + http_session + ${smacc2_LIBRARIES} +) +ament_target_dependencies(${PROJECT_NAME} smacc2) ament_export_include_directories(include) -ament_export_libraries(${PROJECT_NAME}) +ament_export_libraries(${PROJECT_NAME} http_session) install( DIRECTORY include/ @@ -36,6 +44,7 @@ install( install(TARGETS ${PROJECT_NAME} + http_session DESTINATION lib/) ament_package() diff --git a/smacc2_client_library/http_client/include/http_client/http_client.hpp b/smacc2_client_library/http_client/include/http_client/http_client.hpp index 744d80c7d..9dbe0c3b8 100644 --- a/smacc2_client_library/http_client/include/http_client/http_client.hpp +++ b/smacc2_client_library/http_client/include/http_client/http_client.hpp @@ -24,7 +24,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -34,85 +37,80 @@ #include #include -namespace cl_http { -class ClHttp : public smacc2::ISmaccClient { - class http_session : public std::enable_shared_from_this { - public: - using TResponse = - boost::beast::http::response; - - // Objects are constructed with a strand to - // ensure that handlers do not execute concurrently. - http_session(boost::asio::io_context &ioc, - const std::function response); - - // Start the asynchronous operation - void run(const std::string &host, const std::string &target, - const std::string &port, - const boost::beast::http::verb http_method, const int &version); - - void on_resolve(boost::beast::error_code ec, - boost::asio::ip::tcp::resolver::results_type results); - - private: - void fail(boost::beast::error_code ec, char const *what); - void on_connect( - boost::beast::error_code ec, - boost::asio::ip::tcp::resolver::results_type::endpoint_type); - void on_write(boost::beast::error_code ec, std::size_t bytes_transferred); - void on_read(boost::beast::error_code ec, std::size_t bytes_transferred); - - std::function onResponse; - - boost::asio::ip::tcp::resolver resolver_; - boost::beast::tcp_stream stream_; - boost::beast::flat_buffer buffer_; // (Must persist between reads) - boost::beast::http::request req_; - boost::beast::http::response res_; +namespace cl_http +{ +class ClHttp : public smacc2::ISmaccClient +{ + class Server + { + public: + explicit Server(const std::string & server_name) : server_name_{server_name}, ssl_{true} + { + if (!server_name_.substr(0, 7).compare("http://")) + { + ssl_ = false; + server_name_.erase(0, 7); + } + else if (!server_name_.substr(0, 8).compare("https://")) + { + server_name_.erase(0, 8); + ssl_ = true; + } + } + + bool isSSL() const { return ssl_; } + + std::string getPort() const { return ssl_ ? "443" : "80"; } + + std::string getServerName() const { return server_name_; } + + private: + std::string server_name_; + bool ssl_; }; - public: - enum class kHttpRequestMethod { +public: + enum class kHttpRequestMethod + { GET = static_cast(boost::beast::http::verb::get), POST = static_cast(boost::beast::http::verb::post), PUT = static_cast(boost::beast::http::verb::put), }; - using TResponse = http_session::TResponse; + using TResponse = http_session_base::TResponse; template - boost::signals2::connection onResponseReceived( - void (T::*callback)(const TResponse&), T *object) { - return this->getStateMachine()->createSignalConnection(onResponseReceived_, - callback, object); + boost::signals2::connection onResponseReceived(void (T::*callback)(const TResponse &), T * object) + { + return this->getStateMachine()->createSignalConnection(onResponseReceived_, callback, object); } - explicit ClHttp(const std::string &server, const int &timeout = 1500); + explicit ClHttp(const std::string & server, const int & timeout = 1500); virtual ~ClHttp(); void onInitialize() override; - void makeRequest(const kHttpRequestMethod http_method, - const std::string &path = "/"); + void makeRequest(const kHttpRequestMethod http_method, const std::string & path = "/"); - private: +private: const int HTTP_VERSION = 11; bool initialized_; bool is_ssl_; int timeout_; - std::string server_name_; + + Server server_; boost::asio::io_context io_context_; - boost::asio::executor_work_guard - worker_guard_; + boost::asio::executor_work_guard worker_guard_; std::thread tcp_connection_runner_; + boost::asio::ssl::context ssl_context_; + smacc2::SmaccSignal onResponseReceived_; - std::function callbackHandler = [&](const TResponse& res) { - onResponseReceived_(res); - }; + std::function callbackHandler = [&](const TResponse & res) + { onResponseReceived_(res); }; }; } // namespace cl_http diff --git a/smacc2_client_library/http_client/include/http_client/http_session.hpp b/smacc2_client_library/http_client/include/http_client/http_session.hpp new file mode 100644 index 000000000..2e482cd34 --- /dev/null +++ b/smacc2_client_library/http_client/include/http_client/http_session.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace cl_http +{ +class http_session : public std::enable_shared_from_this, public http_session_base +{ +public: + // Objects are constructed with a strand to + // ensure that handlers do not execute concurrently. + http_session( + boost::asio::any_io_executor ioc, const std::function response); + + virtual ~http_session() {} + + // Start the asynchronous operation + void run( + const std::string & host, const std::string & target, + const boost::beast::http::verb http_method, const int & version) override; + + std::string getPort() override { return kPort; } + +private: + const std::string kPort = "80"; + + void on_resolve( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results) override; + void fail(boost::beast::error_code ec, const char * what) override; + void on_connect( + boost::beast::error_code ec, + boost::asio::ip::tcp::resolver::results_type::endpoint_type) override; + void on_write(boost::beast::error_code ec, std::size_t bytes_transferred) override; + void on_read(boost::beast::error_code ec, std::size_t bytes_transferred) override; + + std::function onResponse; + + boost::asio::ip::tcp::resolver resolver_; + boost::beast::tcp_stream stream_; + boost::beast::flat_buffer buffer_; // (Must persist between reads) + boost::beast::http::request req_; + boost::beast::http::response res_; +}; +} // namespace cl_http diff --git a/smacc2_client_library/http_client/include/http_client/http_session_base.hpp b/smacc2_client_library/http_client/include/http_client/http_session_base.hpp new file mode 100644 index 000000000..c86bb48b1 --- /dev/null +++ b/smacc2_client_library/http_client/include/http_client/http_session_base.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace cl_http +{ +class http_session_base +{ +public: + virtual ~http_session_base() {} + + using TResponse = boost::beast::http::response; + + // Start the asynchronous operation + virtual void run( + const std::string & host, const std::string & target, + const boost::beast::http::verb http_method, const int & version) = 0; + + virtual std::string getPort() = 0; + +protected: + virtual void on_resolve( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results) = 0; + virtual void fail(boost::beast::error_code ec, const char * what) = 0; + virtual void on_connect( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type::endpoint_type) = 0; + virtual void on_write(boost::beast::error_code ec, std::size_t bytes_transferred) = 0; + virtual void on_read(boost::beast::error_code ec, std::size_t bytes_transferred) = 0; + + // Optional, needed for SSL connections + virtual void on_handshake(boost::beast::error_code ec) {} + virtual void on_shutdown(boost::beast::error_code ec) {} +}; +} // namespace cl_http diff --git a/smacc2_client_library/http_client/include/http_client/ssl_http_session.hpp b/smacc2_client_library/http_client/include/http_client/ssl_http_session.hpp new file mode 100644 index 000000000..b9fd88140 --- /dev/null +++ b/smacc2_client_library/http_client/include/http_client/ssl_http_session.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace cl_http +{ +class ssl_http_session : public std::enable_shared_from_this, + public http_session_base +{ +public: + // Objects are constructed with a strand to + // ensure that handlers do not execute concurrently. + ssl_http_session( + boost::asio::any_io_executor ioc, boost::asio::ssl::context & ssl_context, + const std::function response); + + virtual ~ssl_http_session() {} + + // Start the asynchronous operation + void run( + const std::string & host, const std::string & target, + const boost::beast::http::verb http_method, const int & version) override; + + std::string getPort() override { return kPort; } + +private: + const std::string kPort = "443"; + + void on_resolve( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results) override; + void fail(boost::beast::error_code ec, const char * what) override; + void on_connect( + boost::beast::error_code ec, + boost::asio::ip::tcp::resolver::results_type::endpoint_type) override; + void on_handshake(boost::beast::error_code ec) override; + void on_write(boost::beast::error_code ec, std::size_t bytes_transferred) override; + void on_read(boost::beast::error_code ec, std::size_t bytes_transferred) override; + void on_shutdown(boost::beast::error_code ec) override; + + std::function onResponse; + + boost::asio::ip::tcp::resolver resolver_; + // boost::beast::tcp_stream stream_; + boost::beast::ssl_stream stream_; + boost::beast::flat_buffer buffer_; // (Must persist between reads) + boost::beast::http::request req_; + boost::beast::http::response res_; +}; +} // namespace cl_http diff --git a/smacc2_client_library/http_client/src/http_client/http_client.cpp b/smacc2_client_library/http_client/src/http_client/http_client.cpp index c46dc1f91..eaca71427 100644 --- a/smacc2_client_library/http_client/src/http_client/http_client.cpp +++ b/smacc2_client_library/http_client/src/http_client/http_client.cpp @@ -21,18 +21,14 @@ #include namespace cl_http { - -/////////////////////////// -// ClHttp implementation // -/////////////////////////// - -ClHttp::ClHttp(const std::string &server, const int &timeout) +ClHttp::ClHttp(const std::string& server_name, const int& timeout) : initialized_{false}, timeout_{timeout}, - server_name_{server}, - worker_guard_{boost::asio::make_work_guard(io_context_.get_executor())} { - // User explicitly using http - is_ssl_ = server.substr(0, 8).compare("https://") ? false : true; + server_{server_name}, + worker_guard_{boost::asio::make_work_guard(io_context_.get_executor())}, + ssl_context_{boost::asio::ssl::context::tlsv12_client} { + ssl_context_.set_default_verify_paths(); + ssl_context_.set_verify_mode(boost::asio::ssl::verify_peer); } ClHttp::~ClHttp() { @@ -48,105 +44,29 @@ void ClHttp::onInitialize() { } void ClHttp::makeRequest(const kHttpRequestMethod http_method, - const std::string &path) { - RCLCPP_INFO(this->getLogger(), "SSL? %d", is_ssl_); - std::make_shared(io_context_, callbackHandler) - ->run(server_name_, path, is_ssl_ ? "443" : "80", - static_cast(http_method), HTTP_VERSION); -} - -///////////////////////////////// -// http_session implementation // -///////////////////////////////// - -ClHttp::http_session::http_session( - boost::asio::io_context &ioc, - const std::function response) - : onResponse{response}, - resolver_{boost::asio::make_strand(ioc)}, - stream_{boost::asio::make_strand(ioc)} {} - -void ClHttp::http_session::run(const std::string &host, - const std::string &target, - const std::string &port, - const boost::beast::http::verb http_method, - const int &version) { - // Set up an HTTP request - req_.version(version); - req_.method(http_method); - req_.target(target); - req_.set(boost::beast::http::field::host, host); - req_.set(boost::beast::http::field::user_agent, BOOST_BEAST_VERSION_STRING); - - // Look up the domain name - resolver_.async_resolve(host.c_str(), port.c_str(), - boost::beast::bind_front_handler( - &http_session::on_resolve, shared_from_this())); -} - -void ClHttp::http_session::on_resolve( - boost::beast::error_code ec, - boost::asio::ip::tcp::resolver::results_type results) { - if (ec) return fail(ec, "resolve"); - - // Set a timeout on the operation - stream_.expires_after(std::chrono::seconds(1)); - - // Make the connection on the IP address we get from a lookup - stream_.async_connect( - results, boost::beast::bind_front_handler(&http_session::on_connect, - shared_from_this())); -} -void ClHttp::http_session::fail(boost::beast::error_code ec, char const *what) { - std::cout << "Failure!..." << std::endl; - std::cerr << what << ": " << ec.message() << "\n"; - res_.result(boost::beast::http::status::bad_request); - res_.reason() = ec.message(); - onResponse(res_); -} - -void ClHttp::http_session::on_connect( - boost::beast::error_code ec, - boost::asio::ip::tcp::resolver::results_type::endpoint_type) { - if (ec) return fail(ec, "connect"); - - // Set a timeout on the operation - stream_.expires_after(std::chrono::seconds(1)); - - // Send the HTTP request to the remote host - boost::beast::http::async_write( - stream_, req_, - boost::beast::bind_front_handler(&http_session::on_write, - shared_from_this())); -} - -void ClHttp::http_session::on_write(boost::beast::error_code ec, - std::size_t bytes_transferred) { - boost::ignore_unused(bytes_transferred); - - if (ec) return fail(ec, "write"); - - // Receive the HTTP response - boost::beast::http::async_read( - stream_, buffer_, res_, - boost::beast::bind_front_handler(&http_session::on_read, - shared_from_this())); -} - -void ClHttp::http_session::on_read(boost::beast::error_code ec, - std::size_t bytes_transferred) { - boost::ignore_unused(bytes_transferred); - - if (ec) return fail(ec, "read"); - - // Gracefully close the socket - stream_.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); - - // not_connected happens sometimes so don't bother reporting it. - if (ec && ec != boost::beast::errc::not_connected) - return fail(ec, "shutdown"); + const std::string& path) { + auto path_used = path; + if (path[0] != '/') { + std::reverse(path_used.begin(), path_used.end()); + path_used += '/'; + std::reverse(path_used.begin(), path_used.end()); + } - // If we get here then the connection is closed gracefully - onResponse(res_); + RCLCPP_INFO(this->getLogger(), "SSL? %d", server_.isSSL()); + RCLCPP_INFO(this->getLogger(), "Server %s", server_.getServerName().c_str()); + RCLCPP_INFO(this->getLogger(), "Path %s", path_used.c_str()); + RCLCPP_INFO(this->getLogger(), "Port %s", server_.getPort().c_str()); + + if (server_.isSSL()) { + std::make_shared(boost::asio::make_strand(io_context_), + ssl_context_, callbackHandler) + ->run(server_.getServerName(), path_used, + static_cast(http_method), HTTP_VERSION); + } else { + std::make_shared(boost::asio::make_strand(io_context_), + callbackHandler) + ->run(server_.getServerName(), path_used, + static_cast(http_method), HTTP_VERSION); + } } } // namespace cl_http diff --git a/smacc2_client_library/http_client/src/http_client/http_session.cpp b/smacc2_client_library/http_client/src/http_client/http_session.cpp new file mode 100644 index 000000000..fc84e6e36 --- /dev/null +++ b/smacc2_client_library/http_client/src/http_client/http_session.cpp @@ -0,0 +1,91 @@ +#include + +namespace cl_http +{ + +http_session::http_session( + boost::asio::any_io_executor ioc, const std::function response) +: onResponse{response}, resolver_{ioc}, stream_{ioc} +{ +} + +void http_session::run( + const std::string & host, const std::string & target, const boost::beast::http::verb http_method, + const int & version) +{ + // Set up an HTTP request + req_.version(version); + req_.method(http_method); + req_.target(target); + req_.set(boost::beast::http::field::host, host); + req_.set(boost::beast::http::field::user_agent, BOOST_BEAST_VERSION_STRING); + + // Look up the domain name + resolver_.async_resolve( + host.c_str(), kPort.c_str(), + boost::beast::bind_front_handler(&http_session::on_resolve, shared_from_this())); +} + +void http_session::on_resolve( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results) +{ + if (ec) return fail(ec, "resolve"); + + // Set a timeout on the operation + stream_.expires_after(std::chrono::seconds(1)); + + // Make the connection on the IP address we get from a lookup + stream_.async_connect( + results, boost::beast::bind_front_handler(&http_session::on_connect, shared_from_this())); +} + +void http_session::fail(boost::beast::error_code ec, char const * what) +{ + std::cout << "Failure!..." << std::endl; + std::cerr << what << ": " << ec.message() << "\n"; + res_.result(boost::beast::http::status::bad_request); + res_.reason() = ec.message(); + onResponse(res_); +} + +void http_session::on_connect( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type::endpoint_type) +{ + if (ec) return fail(ec, "connect"); + + // Set a timeout on the operation + stream_.expires_after(std::chrono::seconds(1)); + + // Send the HTTP request to the remote host + boost::beast::http::async_write( + stream_, req_, boost::beast::bind_front_handler(&http_session::on_write, shared_from_this())); +} + +void http_session::on_write(boost::beast::error_code ec, std::size_t bytes_transferred) +{ + boost::ignore_unused(bytes_transferred); + + if (ec) return fail(ec, "write"); + + // Receive the HTTP response + boost::beast::http::async_read( + stream_, buffer_, res_, + boost::beast::bind_front_handler(&http_session::on_read, shared_from_this())); +} + +void http_session::on_read(boost::beast::error_code ec, std::size_t bytes_transferred) +{ + boost::ignore_unused(bytes_transferred); + + if (ec) return fail(ec, "read"); + + // Gracefully close the socket + stream_.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); + + // not_connected happens sometimes so don't bother reporting it. + if (ec && ec != boost::beast::errc::not_connected) return fail(ec, "shutdown"); + + // If we get here then the connection is closed gracefully + onResponse(res_); +} +} // namespace cl_http diff --git a/smacc2_client_library/http_client/src/http_client/ssl_http_session.cpp b/smacc2_client_library/http_client/src/http_client/ssl_http_session.cpp new file mode 100644 index 000000000..c3373720f --- /dev/null +++ b/smacc2_client_library/http_client/src/http_client/ssl_http_session.cpp @@ -0,0 +1,119 @@ +#include + +namespace cl_http +{ + +ssl_http_session::ssl_http_session( + boost::asio::any_io_executor ioc, boost::asio::ssl::context & ssl_context, + const std::function response) +: onResponse{response}, resolver_{ioc}, stream_{ioc, ssl_context} +{ +} + +void ssl_http_session::run( + const std::string & host, const std::string & target, const boost::beast::http::verb http_method, + const int & version) +{ + // Set up an HTTP request + req_.version(version); + req_.method(http_method); + req_.target(target); + req_.set(boost::beast::http::field::host, host); + req_.set(boost::beast::http::field::user_agent, BOOST_BEAST_VERSION_STRING); + + // Look up the domain name + resolver_.async_resolve( + host.c_str(), kPort.c_str(), + boost::beast::bind_front_handler(&ssl_http_session::on_resolve, shared_from_this())); +} + +void ssl_http_session::on_resolve( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results) +{ + if (ec) return fail(ec, "resolve"); + + // Set a timeout on the operation + boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(1)); + + // Make the connection on the IP address we get from a lookup + boost::beast::get_lowest_layer(stream_).async_connect( + results, boost::beast::bind_front_handler(&ssl_http_session::on_connect, shared_from_this())); +} + +void ssl_http_session::fail(boost::beast::error_code ec, char const * what) +{ + std::cout << "Failure!..." << std::endl; + std::cerr << what << ": " << ec.message() << "\n"; + res_.result(boost::beast::http::status::bad_request); + res_.reason() = ec.message(); + onResponse(res_); +} + +void ssl_http_session::on_connect( + boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type::endpoint_type) +{ + if (ec) return fail(ec, "connect"); + + // Set a timeout on the operation + boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(1)); + + // Send the HTTP request to the remote host + stream_.async_handshake( + boost::asio::ssl::stream_base::client, + boost::beast::bind_front_handler(&ssl_http_session::on_handshake, shared_from_this())); +} + +void ssl_http_session::on_handshake(boost::beast::error_code ec) +{ + if (ec) return fail(ec, "handshake"); + + // Set a timeout on the operation + boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(1)); + + // Send the HTTP request to the remote host + boost::beast::http::async_write( + stream_, req_, + boost::beast::bind_front_handler(&ssl_http_session::on_write, shared_from_this())); +} + +void ssl_http_session::on_write(boost::beast::error_code ec, std::size_t bytes_transferred) +{ + boost::ignore_unused(bytes_transferred); + + if (ec) return fail(ec, "write"); + + // Receive the HTTP response + boost::beast::http::async_read( + stream_, buffer_, res_, + boost::beast::bind_front_handler(&ssl_http_session::on_read, shared_from_this())); +} + +void ssl_http_session::on_read(boost::beast::error_code ec, std::size_t bytes_transferred) +{ + boost::ignore_unused(bytes_transferred); + + if (ec) return fail(ec, "read"); + + boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(1)); + + // Gracefully close the socket + // stream_.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); + stream_.async_shutdown( + boost::beast::bind_front_handler(&ssl_http_session::on_shutdown, shared_from_this())); +} + +void ssl_http_session::on_shutdown(boost::beast::error_code ec) +{ + // not_connected happens sometimes so don't bother reporting it. + if (ec == boost::asio::error::eof) + { + // Rationale: + // http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error + ec = {}; + } + // if (ec) return fail(ec, "shutdown"); + + // If we get here then the connection is closed gracefully + onResponse(res_); +} +} // namespace cl_http diff --git a/smacc2_sm_reference_library/sm_atomic_http/CMakeLists.txt b/smacc2_sm_reference_library/sm_atomic_http/CMakeLists.txt index 69e912187..cdc2b7869 100644 --- a/smacc2_sm_reference_library/sm_atomic_http/CMakeLists.txt +++ b/smacc2_sm_reference_library/sm_atomic_http/CMakeLists.txt @@ -16,6 +16,7 @@ find_package(smacc2 REQUIRED) find_package(ros_timer_client REQUIRED) find_package(http_client REQUIRED) find_package(Boost COMPONENTS thread REQUIRED) +find_package(OpenSSL REQUIRED) include_directories(include ${smacc2_INCLUDE_DIRS} @@ -31,6 +32,8 @@ target_link_libraries(${PROJECT_NAME}_node ${ros_timer_client_LIBRARIES} ${http_client_LIBRARIES} ${Boost_LIBRARIES} + OpenSSL::SSL + OpenSSL::Crypto ) ament_target_dependencies(${PROJECT_NAME}_node smacc2) diff --git a/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/clients/client_behaviors/cb_http_request.hpp b/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/clients/client_behaviors/cb_http_request.hpp index 6ec5fbb10..3c0cdf9f2 100644 --- a/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/clients/client_behaviors/cb_http_request.hpp +++ b/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/clients/client_behaviors/cb_http_request.hpp @@ -20,11 +20,10 @@ #pragma once +#include #include #include -#include - namespace sm_atomic_http { template @@ -47,15 +46,14 @@ class CbHttpRequest : public smacc2::SmaccClientBehavior { void onResponseReceived(const cl_http::ClHttp::TResponse& response) { RCLCPP_INFO_STREAM(this->getLogger(), "ON RESPONSE"); - // RCLCPP_INFO_STREAM(this->getLogger(), response); + RCLCPP_INFO_STREAM(this->getLogger(), response.body()); triggerTranstition(); } void onEntry() override { RCLCPP_INFO(this->getLogger(), "On Entry!"); - cl_http_->makeRequest( - cl_http::ClHttp::kHttpRequestMethod::GET); + cl_http::ClHttp::kHttpRequestMethod::GET); } void onExit() override { RCLCPP_INFO(this->getLogger(), "Cb on exit!"); } diff --git a/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/orthogonals/or_http.hpp b/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/orthogonals/or_http.hpp index 2f43da5fe..136f28a31 100644 --- a/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/orthogonals/or_http.hpp +++ b/smacc2_sm_reference_library/sm_atomic_http/include/sm_atomic_http/orthogonals/or_http.hpp @@ -23,7 +23,7 @@ class OrHttp : public smacc2::Orthogonal { void onInitialize() override { auto http_client = this->createClient( - "https://www.google.com"); + "https://example.com"); } }; } // namespace sm_atomic_http