33 boost::asio::io_context& getIoContext() {
37 const std::string& getEtpServerHost()
const {
return etpServerHost; }
38 const std::string& getEtpServerPort()
const {
return etpServerPort; }
39 const std::string& getEtpServerTarget()
const {
return etpServerTarget; }
40 const std::string& getEtpServerAuthorization()
const {
return etpServerAuthorization; }
41 const std::string& getProxyHost()
const {
return proxyHost; }
42 const std::string& getProxyPort()
const {
return proxyPort; }
43 const std::string& getProxyAuthorization()
const {
return proxyAuthorization; }
52 successfulConnection =
false;
56 resolver.async_resolve(
57 proxyHost.empty() ? etpServerHost : proxyHost,
58 proxyHost.empty() ? etpServerPort : proxyPort,
60 &ClientSession::on_resolve,
61 std::static_pointer_cast<ClientSession>(shared_from_this()),
62 std::placeholders::_1,
63 std::placeholders::_2));
69 return successfulConnection;
72 virtual void on_resolve(boost::system::error_code ec, tcp::resolver::results_type results) = 0;
73 virtual bool isTls()
const = 0;
75 void on_handshake(boost::system::error_code ec)
78 std::cerr <<
"on_handshake : " << ec.message() << std::endl;
79 std::cerr <<
"Sometimes some ETP server require a trailing slash at the end of their URL. Did you also check your optional \"data-partition-id\" additional Header Field?" << std::endl;
83 if (!responseType.count(boost::beast::http::field::sec_websocket_protocol) ||
84 responseType[boost::beast::http::field::sec_websocket_protocol] !=
"etp12.energistics.org")
85 std::cerr <<
"The client MUST specify the Sec-Websocket-Protocol header value of etp12.energistics.org, and the server MUST reply with the same" << std::endl;
87 successfulConnection =
true;
88 webSocketSessionClosed =
false;
90 send(requestSession, 0, 0x02);
95 boost::asio::io_context ioc;
96 tcp::resolver resolver;
97 std::string etpServerHost;
98 std::string etpServerPort;
99 std::string etpServerTarget;
100 std::string etpServerAuthorization;
101 std::string proxyHost;
102 std::string proxyPort;
103 std::string proxyAuthorization;
104 std::map<std::string, std::string> additionalHandshakeHeaderFields_;
105 websocket::response_type responseType;
107 bool successfulConnection =
false;
116 InitializationParameters
const* initializationParams,
const std::string& target,
const std::string& etpServerAuth,
const std::string& proxyAuth =
"") :
119 etpServerHost(initializationParams->getEtpServerHost()),
120 etpServerPort(std::to_string(initializationParams->getEtpServerPort())),
121 etpServerTarget(target),
122 etpServerAuthorization(etpServerAuth),
123 proxyHost(initializationParams->getProxyHost()),
124 proxyPort(std::to_string(initializationParams->getProxyPort())),
125 proxyAuthorization(proxyAuth)
129 initializationParams->postSessionCreationOperation(
this);
132 requestSession.applicationName = initializationParams->getApplicationName();
133 requestSession.applicationVersion = initializationParams->getApplicationVersion();
135 std::copy(initializationParams->getInstanceId().begin(), initializationParams->getInstanceId().end(), requestSession.clientInstanceId.array.begin());
137 requestSession.requestedProtocols = initializationParams->makeSupportedProtocols();
138 requestSession.supportedDataObjects = initializationParams->makeSupportedDataObjects();
139 requestSession.supportedFormats.push_back(
"xml");
140 requestSession.currentDateTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
142 auto caps = initializationParams->makeEndpointCapabilities();
144 requestSession.endpointCapabilities = caps;
147 maxWebSocketMessagePayloadSize = initializationParams->getMaxWebSocketMessagePayloadSize();