1 karl 1.41 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.35 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.25 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.35 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.37 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.41 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.2 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 kumpf 1.15 //
|
21 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/Config.h>
35 #include <iostream>
|
36 kumpf 1.9 #include <Pegasus/Common/Constants.h>
|
37 mike 1.2 #include <Pegasus/Common/XmlParser.h>
38 #include <Pegasus/Common/XmlReader.h>
39 #include <Pegasus/Common/System.h>
40 #include <Pegasus/Common/XmlWriter.h>
41 #include <Pegasus/Common/HTTPMessage.h>
42 #include <Pegasus/Common/CIMMessage.h>
|
43 kumpf 1.19 #include <Pegasus/Common/Exception.h>
|
44 mike 1.2 #include "CIMExportResponseDecoder.h"
45
|
46 humberto 1.22 // l10n
47 #include <Pegasus/Common/MessageLoader.h>
48
|
49 mike 1.2 PEGASUS_USING_STD;
50
51 PEGASUS_NAMESPACE_BEGIN
52
53 CIMExportResponseDecoder::CIMExportResponseDecoder(
|
54 kumpf 1.19 MessageQueue* outputQueue,
55 MessageQueue* encoderQueue,
|
56 mday 1.4 ClientAuthenticator* authenticator)
57 :
|
58 kumpf 1.19 MessageQueue(PEGASUS_QUEUENAME_EXPORTRESPDECODER),
|
59 mday 1.4 _outputQueue(outputQueue),
60 _encoderQueue(encoderQueue),
61 _authenticator(authenticator)
|
62 mike 1.2 {
|
63 kumpf 1.32 PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportResponseDecoder::CIMExportResponseDecoder()");
64 PEG_METHOD_EXIT();
|
65 mike 1.2 }
66
67 CIMExportResponseDecoder::~CIMExportResponseDecoder()
68 {
|
69 kumpf 1.32 PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportResponseDecoder::~CIMExportResponseDecoder()");
|
70 a.arora 1.31 _outputQueue.release();
71 _encoderQueue.release();
72 _authenticator.release();
|
73 kumpf 1.32 PEG_METHOD_EXIT();
|
74 mike 1.2 }
75
|
76 kumpf 1.19 void CIMExportResponseDecoder::setEncoderQueue(MessageQueue* encoderQueue)
|
77 mike 1.2 {
|
78 kumpf 1.32 PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportResponseDecoder::setEncoderQueue()");
|
79 a.arora 1.31 _encoderQueue.release();
80 _encoderQueue.reset(encoderQueue);
|
81 kumpf 1.32 PEG_METHOD_EXIT();
|
82 mike 1.2 }
83
|
84 mday 1.4
|
85 kumpf 1.19 void CIMExportResponseDecoder::handleEnqueue()
|
86 mike 1.2 {
|
87 kumpf 1.32 PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportResponseDecoder::handleEnqueue()");
|
88 kumpf 1.19 Message* message = dequeue();
89
|
90 carolann.graves 1.43 PEGASUS_ASSERT(message != 0);
|
91 mday 1.4
92 switch (message->getType())
93 {
94 case HTTP_MESSAGE:
95 {
|
96 carolann.graves 1.48 HTTPMessage* httpMessage = (HTTPMessage*)message;
97 _handleHTTPMessage(httpMessage);
98 break;
|
99 mday 1.4 }
100
101 default:
|
102 carolann.graves 1.48 PEGASUS_ASSERT(0);
103 break;
|
104 mday 1.4 }
|
105 mike 1.2
|
106 mday 1.4 delete message;
|
107 kumpf 1.32 PEG_METHOD_EXIT();
|
108 mday 1.4 }
|
109 mike 1.2
110 void CIMExportResponseDecoder::_handleHTTPMessage(HTTPMessage* httpMessage)
111 {
|
112 carolann.graves 1.48 PEG_METHOD_ENTER (TRC_EXPORT_CLIENT,
113 "CIMExportResponseDecoder::_handleHTTPMessage()");
|
114 mday 1.4
|
115 j.alex 1.38 //
|
116 carolann.graves 1.48 // Parse the HTTP CIM Export response message
|
117 j.alex 1.38 //
|
118 carolann.graves 1.48 ClientExceptionMessage* exceptionMessage;
119 char* content;
120 Array<HTTPHeader> headers;
121 Uint32 contentLength;
122 Uint32 statusCode;
123 String reasonPhrase;
124 Boolean cimReconnect;
125 Boolean valid;
126 HTTPExportResponseDecoder::parseHTTPHeaders(httpMessage, exceptionMessage,
127 headers, contentLength, statusCode, reasonPhrase, cimReconnect, valid);
|
128 mday 1.4
|
129 kumpf 1.19 //
|
130 carolann.graves 1.48 // Return exception on any parse errors from the HTTP export response
131 // message
|
132 kumpf 1.19 //
|
133 carolann.graves 1.48 if (!valid)
|
134 kumpf 1.19 {
|
135 carolann.graves 1.48 _outputQueue->enqueue(exceptionMessage);
136 PEG_METHOD_EXIT();
137 return;
|
138 kumpf 1.19 }
|
139 mday 1.4
|
140 kumpf 1.19 try
|
141 mday 1.4 {
|
142 kumpf 1.19 if (_authenticator->checkResponseHeaderForChallenge(headers))
143 {
144 //
145 // Get the original request, put that in the encoder's queue for
146 // re-sending with authentication challenge response.
147 //
148
|
149 kumpf 1.40 Message* reqMessage = _authenticator->releaseRequestMessage();
|
150 j.alex 1.38
|
151 j.alex 1.39 if (cimReconnect == true)
152 {
153 reqMessage->setCloseConnect(cimReconnect);
154 _outputQueue->enqueue(reqMessage);
155 }
156 else
157 {
158 _encoderQueue->enqueue(reqMessage);
159 }
160
|
161 kumpf 1.19
|
162 kumpf 1.32 PEG_METHOD_EXIT();
|
163 kumpf 1.19 return;
164 }
165 else
166 {
167 //
168 // Received a valid/error response from the server.
169 // We do not need the original request message anymore, hence delete
170 // the request message by getting the handle from the ClientAuthenticator.
171 //
|
172 kumpf 1.40 Message* reqMessage = _authenticator->releaseRequestMessage();
173 delete reqMessage;
|
174 kumpf 1.19 }
175 }
176 catch(InvalidAuthHeader& e)
177 {
|
178 a.arora 1.31 AutoPtr<CIMClientMalformedHTTPException> malformedHTTPException(
179 new CIMClientMalformedHTTPException(e.getMessage()));
180 AutoPtr<ClientExceptionMessage> response(
181 new ClientExceptionMessage(malformedHTTPException.get()));
182
183 malformedHTTPException.release();
|
184 kumpf 1.19
|
185 j.alex 1.38 response->setCloseConnect(cimReconnect);
|
186 a.arora 1.31 _outputQueue->enqueue(response.release());
|
187 kumpf 1.32 PEG_METHOD_EXIT();
|
188 kumpf 1.19 return;
189 }
190
|
191 carolann.graves 1.48 //
192 // Validate the HTTP headers in the export response message
193 //
194 HTTPExportResponseDecoder::validateHTTPHeaders(httpMessage, headers,
195 contentLength, statusCode, cimReconnect, reasonPhrase, content,
196 exceptionMessage, valid);
|
197 kumpf 1.19
198 //
|
199 carolann.graves 1.48 // Return exception on any errors in the HTTP headers in the export
200 // response message
|
201 kumpf 1.19 //
|
202 carolann.graves 1.48 if (!valid)
|
203 kumpf 1.19 {
|
204 carolann.graves 1.48 _outputQueue->enqueue(exceptionMessage);
|
205 kumpf 1.32 PEG_METHOD_EXIT();
|
206 kumpf 1.19 return;
207 }
|
208 mday 1.4
|
209 carolann.graves 1.48 //
210 // Decode the export response message
211 //
212 Message* responseMessage;
213 HTTPExportResponseDecoder::decodeExportResponse(content, cimReconnect,
214 responseMessage);
215 _outputQueue->enqueue(responseMessage);
|
216 mike 1.2
|
217 kumpf 1.32 PEG_METHOD_EXIT();
|
218 mike 1.2 }
219
220 PEGASUS_NAMESPACE_END
|