/** Process HTTP response message from cimserver @param httpResponse Buffer reply from cimserver @param ostream the ostream to which output should be written @param estream the ostream to which errors should be written @return true = wait for data from challenge response @return false = client response has been received */ void WbemExecCommand::_handleResponse( Buffer responseMessage, ostream& oStream, ostream& eStream ) { String startLine; Array<HTTPHeader> headers; Uint32 contentLength; Uint32 contentOffset = 0; HTTPMessage httpMessage(responseMessage, 0); httpMessage.parse(startLine, headers, contentLength); if( contentLength > 0 ) { contentOffset = responseMessage.size() - contentLength; } else { contentOffset = responseMessage.size(); } String httpVersion; Uint32 statusCode; String reasonPhrase; Boolean parsableMessage = HTTPMessage::parseStatusLine( startLine, httpVersion, statusCode, reasonPhrase); if (!parsableMessage || (statusCode != HTTP_STATUSCODE_OK)) { // Received an HTTP error response // Output the HTTP error message and exit for (Uint32 i = 0; i < contentOffset; i++) { oStream << responseMessage[i]; } oStream.flush(); if( contentLength > 0 ) { _printContent( oStream, responseMessage, contentOffset ); } exit( 1 ); } // // Received a valid HTTP response from the server. // if (_debugOutput2) { for (Uint32 i = 0; i < contentOffset; i++) { oStream << responseMessage[i]; } oStream.flush(); } _printContent( oStream, responseMessage, contentOffset ); }
void CIMOperationRequestAuthorizer::sendResponse( Uint32 queueId, Array<char>& message) { PEG_METHOD_ENTER(TRC_SERVER, "CIMOperationRequestAuthorizer::sendResponse"); MessageQueue* queue = MessageQueue::lookup(queueId); if (queue) { AutoPtr<HTTPMessage> httpMessage(new HTTPMessage(message)); queue->enqueue(httpMessage.release()); } PEG_METHOD_EXIT(); }
void WsmResponseEncoder::sendResponse(const SoapResponse* response) { PEG_METHOD_ENTER(TRC_WSMSERVER, "WsmResponseEncoder::sendResponse"); PEG_TRACE((TRC_WSMSERVER, Tracer::LEVEL3, "WsmResponseEncoder::sendResponse()")); if (!response) { PEG_METHOD_EXIT(); return; } Uint32 queueId = response->getQueueId(); Boolean httpCloseConnect = response->getHttpCloseConnect(); PEG_TRACE((TRC_WSMSERVER, Tracer::LEVEL4, "WsmResponseEncoder::sendResponse()- " "response->getHttpCloseConnect() returned %d", httpCloseConnect)); MessageQueue* queue = MessageQueue::lookup(queueId); if (!queue) { PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1, "ERROR: non-existent queueId = %u, response not sent.", queueId)); PEG_METHOD_EXIT(); return; } PEGASUS_ASSERT(dynamic_cast<HTTPConnection*>(queue) != 0); Buffer message = response->getResponseContent(); // Note: WS-Management responses are never sent in chunks, so there is no // need to check dynamic_cast<HTTPConnection*>(queue)->isChunkRequested(). // HTTPMessage::isComplete() defaults to true, and we leave it that way. AutoPtr<HTTPMessage> httpMessage(new HTTPMessage(message)); httpMessage->setCloseConnect(httpCloseConnect); queue->enqueue(httpMessage.release()); PEG_METHOD_EXIT(); }
void HTTPAuthenticatorDelegator::_sendResponse( Uint32 queueId, Buffer& message, Boolean closeConnect) { PEG_METHOD_ENTER(TRC_HTTP, "HTTPAuthenticatorDelegator::_sendResponse"); MessageQueue* queue = MessageQueue::lookup(queueId); if (queue) { AutoPtr<HTTPMessage> httpMessage(new HTTPMessage(message)); httpMessage->dest = queue->getQueueId(); queue->enqueue(httpMessage.release()); } PEG_METHOD_EXIT(); }
/* Pull operation version of SendResponse. This adds one additional parameter (bodyParamsIn) that contains the parameters. This is because the parameters are added only on the the final segment of a chunk */ void CIMOperationResponseEncoder::sendResponsePull( CIMResponseMessage* response, const String& name, Boolean isImplicit, Buffer* bodyParams, Buffer* bodygiven) { PEG_METHOD_ENTER(TRC_DISPATCHER, "CIMOperationResponseEncoder::sendResponse"); PEG_TRACE((TRC_HTTP, Tracer::LEVEL4, "name = %s", (const char*)name.getCString())); if (! response) { PEG_METHOD_EXIT(); return; } Uint32 queueId = response->queueIds.top(); Boolean closeConnect = response->getCloseConnect(); PEG_TRACE(( TRC_HTTP, Tracer::LEVEL4, "CIMOperationResponseEncoder::sendResponse()- " "response->getCloseConnect() returned %d", closeConnect)); MessageQueue* queue = MessageQueue::lookup(queueId); if (!queue) { PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1, "ERROR: non-existent queueId = %u, response not sent.", queueId)); PEG_METHOD_EXIT(); return; } HttpMethod httpMethod = response->getHttpMethod(); String& messageId = response->messageId; CIMException& cimException = response->cimException; Buffer message; // Note: the language is ALWAYS passed empty to the xml formatters because // it is HTTPConnection that needs to make the decision of whether to add // the languages to the HTTP message. ContentLanguageList contentLanguage; CIMName cimName(name); Uint32 messageIndex = response->getIndex(); Boolean isFirst = messageIndex == 0 ? true : false; Boolean isLast = response->isComplete(); Buffer bodylocal; Buffer& body = bodygiven ? *bodygiven : bodylocal; Buffer& bodyParamsBuf = bodyParams ? *bodyParams : bodylocal; // STAT_SERVEREND sets the getTotalServerTime() value in the message class STAT_SERVEREND #ifndef PEGASUS_DISABLE_PERFINST Uint64 serverTime = response->getTotalServerTime(); #else Uint64 serverTime = 0; #endif Buffer (*formatResponse)( const CIMName& iMethodName, const String& messageId, HttpMethod httpMethod, const ContentLanguageList& httpContentLanguages, const Buffer& bodyParams, const Buffer& body, Uint64 serverResponseTime, Boolean isFirst, Boolean isLast); Buffer (*formatError)( const CIMName& methodName, const String& messageId, HttpMethod httpMethod, const CIMException& cimException); if (isImplicit == false) { formatResponse = XmlWriter::formatSimpleMethodRspMessage; formatError = XmlWriter::formatSimpleMethodErrorRspMessage; } else { formatError = XmlWriter::formatSimpleIMethodErrorRspMessage; if (response->binaryResponse) { formatResponse = BinaryCodec::formatSimpleIMethodRspMessage; } else { formatResponse = XmlWriter::formatSimpleIMethodRspMessage; } } if (cimException.getCode() != CIM_ERR_SUCCESS) { HTTPConnection* httpQueue = dynamic_cast<HTTPConnection*>(queue); Boolean isChunkRequest = false; Boolean isFirstError = true; // Note: The WMI Mapper may use a non-HTTPConnection queue here. if (httpQueue) { isChunkRequest = httpQueue->isChunkRequested(); isFirstError = (httpQueue->cimException.getCode() == CIM_ERR_SUCCESS); } // only process the FIRST error if (isFirstError) { // NOTE: even if this error occurs in the middle, HTTPConnection // will flush the entire queued message and reformat. if (isChunkRequest == false) { message = formatError(name, messageId, httpMethod, cimException); } // uri encode the error (for the http header) only when it is // non-chunking or the first error with chunking if (isChunkRequest == false || (isChunkRequest == true && isFirst == true)) { String msg = TraceableCIMException(cimException).getDescription(); String uriEncodedMsg = XmlWriter::encodeURICharacters(msg); CIMException cimExceptionUri( cimException.getCode(), uriEncodedMsg); cimExceptionUri.setContentLanguages( cimException.getContentLanguages()); cimException = cimExceptionUri; } } // if first error in response stream // never put the error in chunked response (because it will end up in // the trailer), so just use the non-error response formatter to send // more data if (isChunkRequest == true) { message = formatResponse( cimName, messageId, httpMethod, contentLanguage, bodyParamsBuf, body, serverTime, isFirst, isLast); } } else { // else non-error condition try { message = formatResponse( cimName, messageId, httpMethod, contentLanguage, bodyParamsBuf, body, serverTime, isFirst, isLast); } catch (PEGASUS_STD(bad_alloc)&) { MessageLoaderParms parms( "Server.CIMOperationResponseEncoder.OUT_OF_MEMORY", "A System error has occurred. Please retry the CIM Operation " "at a later time."); Logger::put_l( Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING, parms); cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms); // try again with new error and no body body.clear(); sendResponse(response, name, isImplicit); PEG_METHOD_EXIT(); return; } STAT_BYTESSENT } AutoPtr<HTTPMessage> httpMessage( new HTTPMessage(message, 0, &cimException)); httpMessage->setComplete(isLast); httpMessage->setIndex(messageIndex); httpMessage->binaryResponse = response->binaryResponse; if (cimException.getCode() != CIM_ERR_SUCCESS) { httpMessage->contentLanguages = cimException.getContentLanguages(); } else { const OperationContext::Container& container = response->operationContext.get(ContentLanguageListContainer::NAME); const ContentLanguageListContainer& listContainer = *dynamic_cast<const ContentLanguageListContainer*>(&container); contentLanguage = listContainer.getLanguages(); httpMessage->contentLanguages = contentLanguage; } httpMessage->setCloseConnect(closeConnect); queue->enqueue(httpMessage.release()); PEG_METHOD_EXIT(); }
HttpReturn::HttpReturn(unsigned returncode_) : returncode(returncode_), msg(httpMessage(returncode_)) { }