Message* CIMClientRep::_doRequest( AutoPtr<CIMRequestMessage>& request, const Uint32 expectedResponseMessageType ) { if (!_connected) { request.reset(); 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 // //Bug 478/418 - Change this to do post call, not mpost request->setHttpMethod (HTTP_METHOD__POST); // l10n // Set the Accept-Languages and Content-Languages into // the request message request->operationContext.set(AcceptLanguageListContainer(requestAcceptLanguages)); request->operationContext.set(ContentLanguageListContainer(requestContentLanguages)); //gathering statistical information about client operation ClientPerfDataStore* perfDataStore = ClientPerfDataStore::Instance(); perfDataStore->reset(); perfDataStore->setOperationType(request->getType()); perfDataStore->setMessageID(request->messageId); // Sending a new request, so clear out the response Content-Languages responseContentLanguages = ContentLanguages::EMPTY; _requestEncoder->enqueue(request.get()); request.release(); 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); // // Reconnect to reset the connection // if Server response contained a Connection: Close Header // if (response->getCloseConnect() == true) { _reconnect(); response->setCloseConnect(false); } // // Future: If M-POST is used and HTTP response is 501 Not // Implemented or 510 Not Extended, retry with POST method // if (response->getType() == CLIENT_EXCEPTION_MESSAGE) { Exception* clientException = ((ClientExceptionMessage*)response)->clientException; delete response; AutoPtr<Exception> d(clientException); // Make the ContentLanguage of the exception available through // the CIMClient API (its also available in the exception). responseContentLanguages = clientException->getContentLanguages(); // // Determine and throw the specific class of client exception // CIMClientMalformedHTTPException* malformedHTTPException = dynamic_cast<CIMClientMalformedHTTPException*>( clientException); if (malformedHTTPException) { throw *malformedHTTPException; } CIMClientHTTPErrorException* httpErrorException = dynamic_cast<CIMClientHTTPErrorException*>( clientException); if (httpErrorException) { throw *httpErrorException; } CIMClientXmlException* xmlException = dynamic_cast<CIMClientXmlException*>(clientException); if (xmlException) { throw *xmlException; } CIMClientResponseException* responseException = dynamic_cast<CIMClientResponseException*>(clientException); if (responseException) { throw *responseException; } CIMException* cimException = dynamic_cast<CIMException*>(clientException); if (cimException) { throw *cimException; } throw *clientException; } else if (response->getType() == expectedResponseMessageType) { CIMResponseMessage* cimResponse = (CIMResponseMessage*)response; if (cimResponse->messageId != messageId) { // l10n // CIMClientResponseException responseException( // String("Mismatched response message ID: Got \"") + // cimResponse->messageId + "\", expected \"" + // messageId + "\"."); MessageLoaderParms mlParms( "Client.CIMClient.MISMATCHED_RESPONSE", "Mismatched response message ID: Got \"$0\", " "expected \"$1\".", cimResponse->messageId, messageId); String mlString(MessageLoader::getMessage(mlParms)); CIMClientResponseException responseException(mlString); delete response; throw responseException; } // l10n // Get the Content-Languages from the response's operationContext // and make available through the CIMClient API responseContentLanguages = ((ContentLanguageListContainer)cimResponse->operationContext.get (ContentLanguageListContainer::NAME)).getLanguages(); if (cimResponse->cimException.getCode() != CIM_ERR_SUCCESS) { CIMException cimException( cimResponse->cimException.getCode(), cimResponse->cimException.getMessage()); cimException.setContentLanguages(responseContentLanguages); delete response; throw cimException; } /* if excicution gets here everytihng is working correctly and a proper response was generated and recived */ //check that client side statistics are valid before handing them to the // client application via a call back Boolean re_check = perfDataStore->checkMessageIDandType(cimResponse->messageId, cimResponse->getType()); if (re_check && !perfDataStore->getStatError() && perfDataStore->isClassRegistered()) { //if callback method throws an exception it will be seen by the client //no try/catch block is used here intentionaly - becasue exceptions //come from the client application so client app. should handle them ClientOpPerformanceData item = perfDataStore->createPerfDataStruct(); perfDataStore->handler_prt->handleClientOpPerformanceData(item); }//end of if statmet that call the callback method 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( "Client.CIMOperationResponseDecoder.MISMATCHED_RESPONSE_TYPE", "Mismatched response message type."); String mlString(MessageLoader::getMessage(mlParms)); CIMClientResponseException responseException(mlString); delete response; throw responseException; } } nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); pegasus_yield(); } // // Reconnect to reset the connection (disregard late response) // try { _reconnect(); } catch (...) { } // // Throw timed out exception: // throw ConnectionTimeoutException(); }
Message* CIMExportClient::_doRequest( CIMRequestMessage* pRequest, MessageType expectedResponseMessageType) { PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::_doRequest()"); AutoPtr<CIMRequestMessage> request(pRequest); if (!_connected && !_doReconnect) { PEG_METHOD_EXIT(); throw NotConnectedException(); } if (_doReconnect) { try { _connect(); _doReconnect = false; } catch (const Exception& e) { PEG_TRACE((TRC_EXPORT_CLIENT, Tracer::LEVEL1, "Failed to connect to indication listener: %s", (const char*)e.getMessage().getCString())); PEG_METHOD_EXIT(); throw; } catch (...) { PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL1, "Failed to connect to indication listener."); PEG_METHOD_EXIT(); throw; } } 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.release()); 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 // AutoPtr<Message> response(dequeue()); if (response.get() != 0) { // Shouldn't be any more messages in our queue PEGASUS_ASSERT(getCount() == 0); // // Close the connection if response contained a "Connection: Close" // header (e.g. at authentication challenge) // if (response->getCloseConnect() == true) { _disconnect(); _doReconnect = true; response->setCloseConnect(false); } // // Future: If M-POST is used and HTTP response is 501 Not // Implemented or 510 Not Extended, retry with POST method // if (response->getType() == CLIENT_EXCEPTION_MESSAGE) { Exception* clientException = ((ClientExceptionMessage*)response.get())->clientException; PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL2, "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_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4, "Received expected indication response message."); CIMResponseMessage* cimResponse = (CIMResponseMessage*)response.get(); if (cimResponse->messageId != 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); PEG_METHOD_EXIT(); throw responseException; } if (cimResponse->cimException.getCode() != CIM_ERR_SUCCESS) { PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL1, "Received indication failure message."); CIMException cimException( cimResponse->cimException.getCode(), cimResponse->cimException.getMessage()); PEG_METHOD_EXIT(); throw cimException; } PEG_METHOD_EXIT(); return response.release(); } else if (dynamic_cast<CIMRequestMessage*>(response.get()) != 0) { // // Respond to an authentication challenge. // Reconnect if the connection was closed. // if (_doReconnect) { _connect(); } _requestEncoder->enqueue(response.release()); nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); stopMilliseconds = nowMilliseconds + _timeoutMilliseconds; continue; } else { MessageLoaderParms mlParms( "ExportClient.CIMExportClient.MISMATCHED_RESPONSE", "Mismatched response message type."); String mlString(MessageLoader::getMessage(mlParms)); CIMClientResponseException responseException(mlString); PEG_TRACE((TRC_EXPORT_CLIENT, Tracer::LEVEL1, (const char*)mlString.getCString())); PEG_METHOD_EXIT(); throw responseException; } } nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); } // // Reconnect to reset the connection (disregard late response) // PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL2, "Connection to the listener timed out."); _disconnect(); _authenticator.resetChallengeStatus(); _doReconnect = true; // // Throw timed out exception: // PEG_METHOD_EXIT(); throw ConnectionTimeoutException(); }