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(); }
Buffer WbemExecClient::issueRequest(const Buffer& request) { if (!_connected) { throw NotConnectedException(); } HTTPMessage* httpRequest = new HTTPMessage(request); // Note: A historical defect in the calculation of the Content-Length // header makes it possible that wbemexec input files exist with a // Content-Length value one larger than the actual content size. Adding // and extra newline character to the end of the message keeps those old // scripts working. httpRequest->message << "\n"; _authenticator.setRequestMessage(httpRequest); Boolean haveBeenChallenged = false; HTTPMessage* httpResponse; while (1) { HTTPMessage* httpRequestCopy = new HTTPMessage(*(HTTPMessage*)_authenticator.getRequestMessage()); _addAuthHeader(httpRequestCopy); Message* response = _doRequest(httpRequestCopy); PEGASUS_ASSERT(response->getType() == HTTP_MESSAGE); httpResponse = (HTTPMessage*)response; // If we've already been challenged or if the response does not // contain a challenge, there is nothing more to do. String startLine; Array<HTTPHeader> headers; Uint32 contentLength; httpResponse->parse(startLine, headers, contentLength); if (haveBeenChallenged || !_checkNeedToResend(headers)) { break; } // If the challenge contains a Connection: Close header, reestablish // the connection. String connectionHeader; if (HTTPMessage::lookupHeader( headers, "Connection", connectionHeader, false)) { if (String::equalNoCase(connectionHeader, "Close")) { _reconnect(); } } // Prompt for a password, if necessary if ((_password == String::EMPTY) && _isRemote) { _password = _promptForPassword(); _authenticator.setPassword(_password); } haveBeenChallenged = true; delete httpResponse; } AutoPtr<HTTPMessage> origRequest( (HTTPMessage*)_authenticator.releaseRequestMessage()); AutoPtr<HTTPMessage> destroyer(httpResponse); return httpResponse->message; }
void /*PORT_NAME*/_read() { if (!/*PORT_NAME*/_client.connected()) { /*PORT_NAME*/_reconnect(); } /*PORT_NAME*/_client.loop(); }