📄 cimexportclient.cpp
字号:
void CIMExportClient::disconnect(){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::disconnect()"); _disconnect(); _authenticator.clear(); _connectSSLContext.reset(); PEG_METHOD_EXIT();}void CIMExportClient::exportIndication( const String& url, const CIMInstance& instanceName, const ContentLanguageList& contentLanguages){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::exportIndication()"); try { // encode request // l10n CIMRequestMessage* request = new CIMExportIndicationRequestMessage( String::EMPTY, url, instanceName, QueueIdStack(), String::EMPTY, String::EMPTY); request->operationContext.set (ContentLanguageListContainer(contentLanguages)); Message* message = _doRequest(request, CIM_EXPORT_INDICATION_RESPONSE_MESSAGE); CIMExportIndicationResponseMessage* response = (CIMExportIndicationResponseMessage*)message; AutoPtr<CIMExportIndicationResponseMessage> ap(response); } catch (const Exception & e) { PEG_TRACE_STRING (TRC_DISCARDED_DATA, Tracer::LEVEL4, "Failed to export indication: " + e.getMessage ()); throw; } catch (...) { PEG_TRACE_STRING (TRC_DISCARDED_DATA, Tracer::LEVEL4, "Failed to export indication"); throw; } PEG_METHOD_EXIT();}Message* CIMExportClient::_doRequest( CIMRequestMessage * request, const Uint32 expectedResponseMessageType){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::_doRequest()"); if (!_connected) { delete request; PEG_METHOD_EXIT(); throw NotConnectedException(); } String messageId = XmlWriter::getNextMessageId(); const_cast<String &>(request->messageId) = messageId; _authenticator.setRequestMessage(0); // ATTN-RK-P2-20020416: We should probably clear out the queue first. PEGASUS_ASSERT(getCount() == 0); // Shouldn't be any messages in our queue // // Set HTTP method in request to POST // request->setHttpMethod (HTTP_METHOD__POST); _requestEncoder->enqueue(request); Uint64 startMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); Uint64 nowMilliseconds = startMilliseconds; Uint64 stopMilliseconds = nowMilliseconds + _timeoutMilliseconds; while (nowMilliseconds < stopMilliseconds) { // // Wait until the timeout expires or an event occurs: // _monitor->run(Uint32(stopMilliseconds - nowMilliseconds)); // // Check to see if incoming queue has a message // Message* response = dequeue(); if (response) { // Shouldn't be any more messages in our queue PEGASUS_ASSERT(getCount() == 0); // // Future: If M-POST is used and HTTP response is 501 Not // Implemented or 510 Not Extended, retry with POST method // // // Reconnect to reset the connection // if Server response contained a Connection: Close Header // if (response->getCloseConnect() == true){ _reconnect(); response->setCloseConnect(false); } if (response->getType() == CLIENT_EXCEPTION_MESSAGE) { Exception* clientException = ((ClientExceptionMessage*)response)->clientException; delete response; PEG_TRACE_STRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4, "Client Exception Message received."); AutoPtr<Exception> d(clientException); // // Determine and throw the specific class of client exception // CIMClientMalformedHTTPException* malformedHTTPException = dynamic_cast<CIMClientMalformedHTTPException*>( clientException); if (malformedHTTPException) { PEG_METHOD_EXIT(); throw *malformedHTTPException; } CIMClientHTTPErrorException* httpErrorException = dynamic_cast<CIMClientHTTPErrorException*>( clientException); if (httpErrorException) { PEG_METHOD_EXIT(); throw *httpErrorException; } CIMClientXmlException* xmlException = dynamic_cast<CIMClientXmlException*>(clientException); if (xmlException) { PEG_METHOD_EXIT(); throw *xmlException; } CIMClientResponseException* responseException = dynamic_cast<CIMClientResponseException*>(clientException); if (responseException) { PEG_METHOD_EXIT(); throw *responseException; } PEG_METHOD_EXIT(); throw *clientException; } else if (response->getType() == expectedResponseMessageType) { PEG_TRACE_STRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4, "Received expected indication response message."); CIMResponseMessage* cimResponse = (CIMResponseMessage*)response; if (cimResponse->messageId != messageId) { // l10n // CIMClientResponseException responseException( // String("Mismatched response message ID: Got \"") + // cimResponse->messageId + "\", expected \"" + // messageId + "\"."); MessageLoaderParms mlParms("ExportClient.CIMExportClient.MISMATCHED_RESPONSE_ID", "Mismatched response message ID: Got \"$0\", expected \"$1\".", cimResponse->messageId, messageId); String mlString(MessageLoader::getMessage(mlParms)); CIMClientResponseException responseException(mlString); delete response; PEG_METHOD_EXIT(); throw responseException; } if (cimResponse->cimException.getCode() != CIM_ERR_SUCCESS) { PEG_TRACE_STRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4, "Received indication failure message."); CIMException cimException( cimResponse->cimException.getCode(), cimResponse->cimException.getMessage()); delete response; PEG_METHOD_EXIT(); throw cimException; } PEG_METHOD_EXIT(); return response; } else if (dynamic_cast<CIMRequestMessage*>(response) != 0) { // Respond to an authentication challenge _requestEncoder->enqueue(response); nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); stopMilliseconds = nowMilliseconds + _timeoutMilliseconds; continue; } else { // l10n // CIMClientResponseException responseException( // "Mismatched response message type."); MessageLoaderParms mlParms("ExportClient.CIMExportClient.MISMATCHED_RESPONSE", "Mismatched response message type."); String mlString(MessageLoader::getMessage(mlParms)); CIMClientResponseException responseException(mlString); delete response; PEG_TRACE_STRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4, mlString); PEG_METHOD_EXIT(); throw responseException; } } nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); Threads::yield(); } // // Reconnect to reset the connection (disregard late response) // try { PEG_TRACE_STRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4, "Doing a _reconnect()..."); _reconnect(); } catch (...) { } PEG_TRACE_STRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4, "Connection to the listener timed out."); PEG_METHOD_EXIT(); // // Throw timed out exception: // throw ConnectionTimeoutException();}PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -