version 1.38, 2003/04/02 20:10:59
|
version 1.38.6.3, 2003/08/14 11:55:41
|
|
|
#include <Pegasus/Common/Exception.h> | #include <Pegasus/Common/Exception.h> |
#include "CIMOperationResponseDecoder.h" | #include "CIMOperationResponseDecoder.h" |
| |
|
// l10n |
|
#include <Pegasus/Common/MessageLoader.h> |
|
|
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
|
|
CIMOperationResponseDecoder::CIMOperationResponseDecoder( | CIMOperationResponseDecoder::CIMOperationResponseDecoder( |
MessageQueue* outputQueue, | MessageQueue* outputQueue, |
MessageQueue* encoderQueue, | MessageQueue* encoderQueue, |
ClientAuthenticator* authenticator) |
ClientAuthenticator* authenticator, |
|
Uint32 showInput) |
: | : |
MessageQueue(PEGASUS_QUEUENAME_OPRESPDECODER), | MessageQueue(PEGASUS_QUEUENAME_OPRESPDECODER), |
_outputQueue(outputQueue), | _outputQueue(outputQueue), |
_encoderQueue(encoderQueue), | _encoderQueue(encoderQueue), |
_authenticator(authenticator) |
_authenticator(authenticator), |
|
_showInput(showInput) |
{ | { |
|
|
} | } |
| |
CIMOperationResponseDecoder::~CIMOperationResponseDecoder() | CIMOperationResponseDecoder::~CIMOperationResponseDecoder() |
|
|
| |
if (httpMessage->message.size() == 0) | if (httpMessage->message.size() == 0) |
{ | { |
|
|
|
// l10n |
|
|
|
// CIMClientMalformedHTTPException* malformedHTTPException = |
|
// new CIMClientMalformedHTTPException("Empty HTTP response message."); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EMPTY_RESPONSE", "Empty HTTP response message."); |
|
String mlString(MessageLoader::getMessage(mlParms)); |
|
|
CIMClientMalformedHTTPException* malformedHTTPException = | CIMClientMalformedHTTPException* malformedHTTPException = |
new CIMClientMalformedHTTPException("Empty HTTP response message."); |
new CIMClientMalformedHTTPException(mlString); |
|
|
ClientExceptionMessage * response = | ClientExceptionMessage * response = |
new ClientExceptionMessage(malformedHTTPException); | new ClientExceptionMessage(malformedHTTPException); |
| |
|
|
// | // |
// Get the status line info | // Get the status line info |
// | // |
|
|
String httpVersion; | String httpVersion; |
Uint32 statusCode; | Uint32 statusCode; |
String reasonPhrase; | String reasonPhrase; |
|
|
startLine, httpVersion, statusCode, reasonPhrase); | startLine, httpVersion, statusCode, reasonPhrase); |
if (!parsableMessage) | if (!parsableMessage) |
{ | { |
CIMClientMalformedHTTPException* malformedHTTPException = new |
|
CIMClientMalformedHTTPException("Malformed HTTP response message."); |
// l10n |
|
|
|
// CIMClientMalformedHTTPException* malformedHTTPException = new |
|
// CIMClientMalformedHTTPException("Malformed HTTP response message."); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.MALFORMED_RESPONSE", "Malformed HTTP response message."); |
|
String mlString(MessageLoader::getMessage(mlParms)); |
|
|
|
CIMClientMalformedHTTPException* malformedHTTPException = |
|
new CIMClientMalformedHTTPException(mlString); |
|
|
ClientExceptionMessage * response = | ClientExceptionMessage * response = |
new ClientExceptionMessage(malformedHTTPException); | new ClientExceptionMessage(malformedHTTPException); |
| |
|
|
return; | return; |
} | } |
| |
|
#ifdef PEGASUS_CLIENT_TRACE_ENABLE |
|
if (_showInput & 1) |
|
{ |
|
cout << "CIMOperatonResponseDecoder"; |
|
httpMessage->printAll(cout); |
|
} |
|
if (_showInput & 2) |
|
{ |
|
Uint32 size = httpMessage->message.size(); |
|
char* tmpBuf = new char[size+1]; |
|
|
|
strncpy( tmpBuf, httpMessage->message.getData(), size ); |
|
tmpBuf[size] = '\0'; |
|
Logger::put(Logger::STANDARD_LOG, |
|
"CIMCLIENT", |
|
Logger::TRACE, |
|
"CIMOperationRequestDecoder::Response, XML content: $1", |
|
tmpBuf); |
|
delete []tmpBuf; |
|
} |
|
#endif |
|
|
|
#ifdef PEGASUS_CLIENT_TRACE_ENABLE |
|
if (_showInput & 1) |
|
{ |
|
cout << "CIMOperatonResponseDecoder"; |
|
httpMessage->printAll(cout); |
|
} |
|
if (_showInput & 2) |
|
{ |
|
Uint32 size = httpMessage->message.size(); |
|
char* tmpBuf = new char[size+1]; |
|
|
|
strncpy( tmpBuf, httpMessage->message.getData(), size ); |
|
tmpBuf[size] = '\0'; |
|
Logger::put(Logger::STANDARD_LOG, |
|
"CIMCLIENT", |
|
Logger::TRACE, |
|
"CIMOperationRequestDecoder::Response, XML content: $1", |
|
tmpBuf); |
|
delete []tmpBuf; |
|
} |
|
#endif |
|
|
try | try |
{ | { |
if (_authenticator->checkResponseHeaderForChallenge(headers)) | if (_authenticator->checkResponseHeaderForChallenge(headers)) |
|
|
// ATTN-SF-P3-20030115: Need to create a specific exception | // ATTN-SF-P3-20030115: Need to create a specific exception |
// to indicate Authentication failure. See JAGae53944. | // to indicate Authentication failure. See JAGae53944. |
| |
const String ERROR_MESSAGE = "Authentication failed."; |
// l10n |
|
// const String ERROR_MESSAGE = "Authentication failed."; |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.AUTHENTICATION_FAILED", "Authentication failed."); |
|
String ERROR_MESSAGE(MessageLoader::getMessage(mlParms)); |
|
|
CannotConnectException* cannotConnectException = | CannotConnectException* cannotConnectException = |
new CannotConnectException(ERROR_MESSAGE); | new CannotConnectException(ERROR_MESSAGE); |
ClientExceptionMessage * response = | ClientExceptionMessage * response = |
|
|
// | // |
// Check for a success (200 OK) response | // Check for a success (200 OK) response |
// | // |
|
|
if (statusCode != HTTP_STATUSCODE_OK) | if (statusCode != HTTP_STATUSCODE_OK) |
{ | { |
String cimError; | String cimError; |
|
|
// | // |
// Search for "CIMOperation" header: | // Search for "CIMOperation" header: |
// | // |
|
|
String cimOperation; | String cimOperation; |
| |
if (!HTTPMessage::lookupHeader( | if (!HTTPMessage::lookupHeader( |
headers, "CIMOperation", cimOperation, true)) | headers, "CIMOperation", cimOperation, true)) |
{ | { |
|
// l10n |
|
|
|
// CIMClientMalformedHTTPException* malformedHTTPException = new |
|
// CIMClientMalformedHTTPException("Missing CIMOperation HTTP header"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.MISSING_CIMOP_HEADER", "Missing $0 HTTP header", "CIMOperation"); |
|
String mlString(MessageLoader::getMessage(mlParms)); |
|
|
CIMClientMalformedHTTPException* malformedHTTPException = new | CIMClientMalformedHTTPException* malformedHTTPException = new |
CIMClientMalformedHTTPException("Missing CIMOperation HTTP header"); |
CIMClientMalformedHTTPException(mlString); |
|
|
ClientExceptionMessage * response = | ClientExceptionMessage * response = |
new ClientExceptionMessage(malformedHTTPException); | new ClientExceptionMessage(malformedHTTPException); |
| |
|
|
return; | return; |
} | } |
| |
|
// l10n start |
|
ContentLanguages contentLanguages = ContentLanguages::EMPTY; |
|
try |
|
{ |
|
// Get and validate the Content-Language header, if set |
|
String contentLanguageHeader; |
|
if (HTTPMessage::lookupHeader( |
|
headers, |
|
"Content-Language", |
|
contentLanguageHeader, |
|
false) == true) |
|
{ |
|
contentLanguages = ContentLanguages(contentLanguageHeader); |
|
} |
|
} |
|
catch (Exception &e) |
|
{ |
|
|
|
// l10n |
|
|
|
// CIMClientMalformedHTTPException* malformedHTTPException = new |
|
// CIMClientMalformedHTTPException("Malformed Content-Language header."); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.MALFORMED_CONTENT", "Malformed Content-Language header."); |
|
String mlString(MessageLoader::getMessage(mlParms)); |
|
|
|
CIMClientMalformedHTTPException* malformedHTTPException = |
|
new CIMClientMalformedHTTPException(mlString); |
|
|
|
ClientExceptionMessage * response = |
|
new ClientExceptionMessage(malformedHTTPException); |
|
|
|
_outputQueue->enqueue(response); |
|
return; |
|
} |
|
// l10n end |
// | // |
// Zero-terminate the message: |
// Search for "Content-Type" header: |
// | // |
| |
|
String cimContentType; |
|
|
|
if (!HTTPMessage::lookupHeader( |
|
headers, "Content-Type", cimContentType, true)) |
|
{ |
|
CIMClientMalformedHTTPException* malformedHTTPException = new |
|
CIMClientMalformedHTTPException("Missing CIMContentType HTTP header"); |
|
ClientExceptionMessage * response = |
|
new ClientExceptionMessage(malformedHTTPException); |
|
|
|
_outputQueue->enqueue(response); |
|
return; |
|
} |
|
|
|
// |
|
// Zero-terminate the message: |
|
// |
httpMessage->message.append('\0'); | httpMessage->message.append('\0'); |
| |
// Calculate the beginning of the content from the message size and | // Calculate the beginning of the content from the message size and |
|
|
| |
if (!String::equalNoCase(cimOperation, "MethodResponse")) | if (!String::equalNoCase(cimOperation, "MethodResponse")) |
{ | { |
|
|
|
// l10n |
|
|
|
// CIMClientMalformedHTTPException* malformedHTTPException = |
|
// new CIMClientMalformedHTTPException( |
|
// String("Received CIMOperation HTTP header value \"") + |
|
// cimOperation + "\", expected \"MethodResponse\""); |
|
|
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_METHODRESPONSE", "Received $0 HTTP header value \"$1\", expected \"$2\"", "CIMOperation", cimOperation, "MethodResponse"); |
|
String mlString(MessageLoader::getMessage(mlParms)); |
|
|
CIMClientMalformedHTTPException* malformedHTTPException = | CIMClientMalformedHTTPException* malformedHTTPException = |
new CIMClientMalformedHTTPException( |
new CIMClientMalformedHTTPException(mlString); |
String("Received CIMOperation HTTP header value \"") + |
|
cimOperation + "\", expected \"MethodResponse\""); |
|
ClientExceptionMessage * response = | ClientExceptionMessage * response = |
new ClientExceptionMessage(malformedHTTPException); | new ClientExceptionMessage(malformedHTTPException); |
| |
|
|
return; | return; |
} | } |
| |
_handleMethodResponse(content); |
_handleMethodResponse(content, |
|
contentLanguages); // l10n |
} | } |
| |
void CIMOperationResponseDecoder::_handleMethodResponse(char* content) |
void CIMOperationResponseDecoder::_handleMethodResponse(char* content, |
|
const ContentLanguages& contentLanguages) //l10n |
{ | { |
Message* response = 0; | Message* response = 0; |
| |
|
|
String messageId; | String messageId; |
String protocolVersion; | String protocolVersion; |
| |
if (!XmlReader::getMessageStartTag(parser, messageId, protocolVersion)) |
if (!XmlReader::getMessageStartTag(parser, messageId, protocolVersion)) { |
throw XmlValidationError( |
|
parser.getLine(), "expected MESSAGE element"); |
// l10n |
|
|
|
// throw XmlValidationError( |
|
// parser.getLine(), "expected MESSAGE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_ELEMENT", |
|
"expected $0 element", "MESSAGE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
|
} |
|
|
| |
if (!String::equalNoCase(protocolVersion, "1.0")) | if (!String::equalNoCase(protocolVersion, "1.0")) |
{ | { |
|
|
|
// l10n |
|
|
|
// CIMClientResponseException* responseException = |
|
// new CIMClientResponseException( |
|
// String("Received unsupported protocol version \"") + |
|
// protocolVersion + "\", expected \"1.0\""); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.UNSUPPORTED_PROTOCOL", "Received unsupported protocol version \"$0\", expected \"1.0\"", protocolVersion); |
|
String mlString(MessageLoader::getMessage(mlParms)); |
|
|
CIMClientResponseException* responseException = | CIMClientResponseException* responseException = |
new CIMClientResponseException( |
new CIMClientResponseException(mlString); |
String("Received unsupported protocol version \"") + |
|
protocolVersion + "\", expected \"1.0\""); |
|
ClientExceptionMessage * response = | ClientExceptionMessage * response = |
new ClientExceptionMessage(responseException); | new ClientExceptionMessage(responseException); |
| |
|
|
response = _decodeExecQueryResponse(parser, messageId); | response = _decodeExecQueryResponse(parser, messageId); |
else | else |
{ | { |
|
|
|
// l10n |
|
|
// Unrecognized IMethodResponse name attribute | // Unrecognized IMethodResponse name attribute |
throw XmlValidationError(parser.getLine(), |
// throw XmlValidationError(parser.getLine(), |
String("Unrecognized IMethodResponse name \"") + |
// String("Unrecognized IMethodResponse name \"") + |
iMethodResponseName + "\""); |
// iMethodResponseName + "\""); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.UNRECOGNIZED_NAME", |
|
"Unrecognized $0 name \"$1\"", "IMethodResponse", |
|
iMethodResponseName); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
| |
// | // |
|
|
} | } |
else | else |
{ | { |
throw XmlValidationError(parser.getLine(), |
// l10n |
"expected METHODRESPONSE or IMETHODRESPONSE element"); |
|
|
// throw XmlValidationError(parser.getLine(), |
|
// "expected METHODRESPONSE or IMETHODRESPONSE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_OR_ELEMENT", |
|
"expected $0 or $1 element", "METHODRESPONSE", "METHODRESPONSE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
| |
// | // |
|
|
| |
if (response) | if (response) |
{ | { |
|
//#ifdef PEGASUS_SNIA_INTEROP_TEST |
|
// httpMessage->printAll(cout); |
|
//#endif |
|
|
delete response; | delete response; |
} | } |
| |
|
|
new Exception(x.getMessage())); | new Exception(x.getMessage())); |
} | } |
| |
|
//l10n start |
|
// l10n TODO - might want to move A-L and C-L to Message |
|
// to make this more maintainable |
|
// Add the language header to the request |
|
CIMMessage * cimmsg = dynamic_cast<CIMMessage *>(response); |
|
if (cimmsg != NULL) |
|
{ |
|
cimmsg->contentLanguages = contentLanguages; |
|
} |
|
else |
|
{ |
|
; // l10n TODO - error back to client here |
|
} |
|
// l10n end |
|
|
|
|
_outputQueue->enqueue(response); | _outputQueue->enqueue(response); |
} | } |
| |
|
|
if ((entry.type == XmlEntry::EMPTY_TAG) || | if ((entry.type == XmlEntry::EMPTY_TAG) || |
!XmlReader::getClassElement(parser, cimClass)) | !XmlReader::getClassElement(parser, cimClass)) |
{ | { |
throw XmlValidationError(parser.getLine(),"expected CLASS element"); |
|
|
// l10n |
|
|
|
// throw XmlValidationError(parser.getLine(),"expected CLASS element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_ELEMENT", |
|
"expected $0 element", "CLASS"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
| |
XmlReader::expectEndTag(parser, "IRETURNVALUE"); | XmlReader::expectEndTag(parser, "IRETURNVALUE"); |
|
|
} | } |
else | else |
{ | { |
throw XmlValidationError(parser.getLine(), |
|
"expected ERROR or IRETURNVALUE element"); |
// l10n |
|
|
|
// throw XmlValidationError(parser.getLine(), |
|
// "expected ERROR or IRETURNVALUE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_OR_ELEMENT", |
|
"expected $0 or $1 element", "ERROR", "IRETURNVALUE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
} | } |
| |
|
|
} | } |
else | else |
{ | { |
throw XmlValidationError(parser.getLine(), |
|
"expected ERROR or IRETURNVALUE element"); |
// l10n |
|
|
|
// throw XmlValidationError(parser.getLine(), |
|
// "expected ERROR or IRETURNVALUE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_OR_ELEMENT", |
|
"expected $0 or $1 element", "ERROR", "IRETURNVALUE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
} | } |
| |
|
|
if ((entry.type == XmlEntry::EMPTY_TAG) || | if ((entry.type == XmlEntry::EMPTY_TAG) || |
!XmlReader::getInstanceElement(parser, cimInstance)) | !XmlReader::getInstanceElement(parser, cimInstance)) |
{ | { |
throw XmlValidationError( |
|
parser.getLine(), "expected INSTANCE element"); |
// l10n |
|
|
|
// throw XmlValidationError( |
|
// parser.getLine(), "expected INSTANCE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_ELEMENT", |
|
"expected $0 element", "INSTANCE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
| |
XmlReader::expectEndTag(parser, "IRETURNVALUE"); | XmlReader::expectEndTag(parser, "IRETURNVALUE"); |
|
|
} | } |
else | else |
{ | { |
throw XmlValidationError(parser.getLine(), |
|
"expected ERROR or IRETURNVALUE element"); |
// l10n |
|
|
|
// throw XmlValidationError(parser.getLine(), |
|
// "expected ERROR or IRETURNVALUE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_OR_ELEMENT", |
|
"expected $0 or $1 element", "ERROR", "IRETURNVALUE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
} | } |
| |
|
|
} | } |
else | else |
{ | { |
throw XmlValidationError(parser.getLine(), |
|
"expected ERROR or IRETURNVALUE element"); |
// l10n |
|
|
|
// throw XmlValidationError(parser.getLine(), |
|
// "expected ERROR or IRETURNVALUE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_OR_ELEMENT", |
|
"expected $0 or $1 element", "ERROR", "IRETURNVALUE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
} | } |
| |
|
|
{ | { |
if (gotReturnValue) | if (gotReturnValue) |
{ | { |
throw XmlValidationError(parser.getLine(), |
|
"unexpected RETURNVALUE element"); |
// l10n |
|
|
|
// throw XmlValidationError(parser.getLine(), |
|
// "unexpected RETURNVALUE element"); |
|
|
|
MessageLoaderParms mlParms("Client.CIMOperationResponseDecoder.EXPECTED_ELEMENT", |
|
"expected $0 element", "RETURNVALUE"); |
|
|
|
throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
gotReturnValue = true; | gotReturnValue = true; |
} | } |